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



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

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

.mineObject



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

def self.mine
  User.me.teams
end

Instance Method Details

#display(_options) ⇒ Object



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

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

#fullObject



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

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

#label_groupsObject



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

def label_groups
  @label_groups ||= []
end

#label_queryObject



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

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



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

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



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

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



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

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

#workflow_statesObject



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

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



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

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