Class: LinearApi::CachedMetadata

Inherits:
ApplicationRecord show all
Defined in:
app/models/linear_api/cached_metadata.rb

Constant Summary collapse

TYPES =
%w[label project state user].freeze

Class Method Summary collapse

Class Method Details

.backlog_state_idObject

State lookups



53
54
55
# File 'app/models/linear_api/cached_metadata.rb', line 53

def backlog_state_id
  states.find_by(key: 'backlog')&.linear_id
end

.bug_label_idObject

Common label lookups



28
29
30
# File 'app/models/linear_api/cached_metadata.rb', line 28

def bug_label_id
  labels.find_by(key: 'type:bug')&.linear_id
end

.critical_priority_idObject



44
45
46
# File 'app/models/linear_api/cached_metadata.rb', line 44

def critical_priority_id
  labels.find_by(key: 'priority:critical')&.linear_id
end

.daily_operations_project_idObject

Project lookups



78
79
80
# File 'app/models/linear_api/cached_metadata.rb', line 78

def daily_operations_project_id
  projects.find_by(key: 'daily_operations')&.linear_id
end

.done_state_idObject



73
74
75
# File 'app/models/linear_api/cached_metadata.rb', line 73

def done_state_id
  states.find_by(key: 'done')&.linear_id
end

.feature_label_idObject



32
33
34
# File 'app/models/linear_api/cached_metadata.rb', line 32

def feature_label_id
  labels.find_by(key: 'type:feature')&.linear_id
end

.high_priority_idObject



48
49
50
# File 'app/models/linear_api/cached_metadata.rb', line 48

def high_priority_id
  labels.find_by(key: 'priority:high')&.linear_id
end

.in_progress_state_idObject



61
62
63
# File 'app/models/linear_api/cached_metadata.rb', line 61

def in_progress_state_id
  states.find_by(key: 'in_progress')&.linear_id
end

.in_review_state_idObject



65
66
67
# File 'app/models/linear_api/cached_metadata.rb', line 65

def in_review_state_id
  states.find_by(key: 'in_review')&.linear_id
end

.infrastructure_label_idObject



40
41
42
# File 'app/models/linear_api/cached_metadata.rb', line 40

def infrastructure_label_id
  labels.find_by(key: 'area:infrastructure')&.linear_id
end

.qa_state_idObject



69
70
71
# File 'app/models/linear_api/cached_metadata.rb', line 69

def qa_state_id
  states.find_by(key: 'qa')&.linear_id
end

.resolve_label_id(label) ⇒ Object

Resolve symbolic label to ID



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/models/linear_api/cached_metadata.rb', line 87

def resolve_label_id(label)
  case label
  when :bug then bug_label_id
  when :feature then feature_label_id
  when :sync then sync_label_id
  when :infrastructure then infrastructure_label_id
  when :critical then critical_priority_id
  when :high then high_priority_id
  when String then label # Already an ID
  else
    labels.find_by(key: label.to_s)&.linear_id
  end
end

.sync_label_idObject



36
37
38
# File 'app/models/linear_api/cached_metadata.rb', line 36

def sync_label_id
  labels.find_by(key: 'area:sync')&.linear_id
end

.tech_debt_project_idObject



82
83
84
# File 'app/models/linear_api/cached_metadata.rb', line 82

def tech_debt_project_id
  projects.find_by(key: 'tech_debt')&.linear_id
end

.todo_state_idObject



57
58
59
# File 'app/models/linear_api/cached_metadata.rb', line 57

def todo_state_id
  states.find_by(key: 'todo')&.linear_id
end

.upsert_from_api(type:, linear_id:, name:, **attrs) ⇒ Object

Upsert from API data



102
103
104
105
106
107
# File 'app/models/linear_api/cached_metadata.rb', line 102

def upsert_from_api(type:, linear_id:, name:, **attrs)
  find_or_initialize_by(metadata_type: type, linear_id: linear_id).tap do |record|
    record.assign_attributes(name: name, **attrs)
    record.save!
  end
end