Class: Rubyists::Linear::Team

Inherits:
Object
  • Object
show all
Includes:
SemanticLogger::Loggable
Defined in:
lib/linear/models/team.rb

Overview

The Issue class represents a Linear issue.

Constant Summary collapse

BaseFilter =

TODO: Make this configurable

{ # rubocop:disable Naming/ConstantName
  and: [
    { name: { notEndsWith: ' Releases' } },
    { name: { notEndsWith: '-ios' } },
    { name: { notEndsWith: '-android' } }
  ]
}.freeze
Base =
fragment('BaseTeam', 'Team') do
  description
  id
  key
  name
  createdAt
  updatedAt
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.full_fragmentObject



33
34
35
36
37
38
# File 'lib/linear/models/team.rb', line 33

def self.full_fragment
  @full_fragment ||= fragment('WholeTeam', 'Team') do
    ___ Base
    projects { nodes { ___ Project.base_fragment } }
  end
end

.mineObject



40
41
42
# File 'lib/linear/models/team.rb', line 40

def self.mine
  User.me.teams
end

Instance Method Details

#display(_options) ⇒ Object



92
93
94
# File 'lib/linear/models/team.rb', line 92

def display(_options)
  printf "%s\n", full
end

#fullObject



48
49
50
# File 'lib/linear/models/team.rb', line 48

def full
  format('%<key>-6s %<to_s>s', key:, to_s:)
end

#label_groupsObject



63
64
65
# File 'lib/linear/models/team.rb', line 63

def label_groups
  @label_groups ||= []
end

#label_queryObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/linear/models/team.rb', line 52

def label_query
  team_id = id
  query do
    team(id: team_id) do
      labels(first: 100, filter: BaseFilter) do
        nodes { ___ Label.base_fragment }
      end
    end
  end
end

#labelsObject

rubocop:disable Metrics/CyclomaticComplexity



67
68
69
70
71
72
73
74
75
76
# File 'lib/linear/models/team.rb', line 67

def labels # rubocop:disable Metrics/CyclomaticComplexity
  return @labels if @labels

  @labels = Api.query(label_query).dig(:team, :labels, :nodes)&.map do |label|
    label_groups << Label.new(label) if label[:isGroup]
    next if label[:isGroup] || label[:parent]

    Label.new label
  end&.compact
end

#membersObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/linear/models/team.rb', line 78

def members
  return @members if @members && !@members.empty?

  q = query do
    team(id:) do
      members do
        nodes { ___ User::Base }
      end
    end
  end
  data = Api.query(q)
  @members = data.dig(:team, :members, :nodes)&.map { |member| User.new member } || []
end

#to_sObject



44
45
46
# File 'lib/linear/models/team.rb', line 44

def to_s
  format('%<name>s', name:)
end

#workflow_statesObject



107
108
109
110
111
112
113
114
# File 'lib/linear/models/team.rb', line 107

def workflow_states
  return @workflow_states if @workflow_states

  data = Api.query(workflow_states_query)
  @workflow_states = data.dig(:team, :states, :nodes)&.map do |state|
    WorkflowState.new state
  end
end

#workflow_states_queryObject



96
97
98
99
100
101
102
103
104
105
# File 'lib/linear/models/team.rb', line 96

def workflow_states_query
  team_id = id
  query do
    team(id: team_id) do
      states do
        nodes { ___ WorkflowState.base_fragment }
      end
    end
  end
end