Class: PredictabilityEngine::JiraWorkflow

Inherits:
Object
  • Object
show all
Defined in:
lib/predictability_engine/jira_workflow.rb

Overview

Editable mapping of Jira workflow statuses → arrival/departure roles. Extracted from Jira’s status catalogue, persisted to YAML, and consumed by DataSources::Jira to drive start_date / end_date selection.

Constant Summary collapse

DEFAULT_PATH_TEMPLATE =
'~/.config/jira/%s.workflow.yml'
CATEGORY_ROLE_DEFAULTS =
{ 'in progress' => 'arrival', 'done' => 'departure' }.freeze
ROLES =
%w[arrival departure].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile: nil, project: nil, statuses: []) ⇒ JiraWorkflow

Returns a new instance of JiraWorkflow.



17
18
19
20
21
# File 'lib/predictability_engine/jira_workflow.rb', line 17

def initialize(profile: nil, project: nil, statuses: [])
  @profile = profile
  @project = project
  @statuses = statuses.map { |s| self.class.normalize_status(s) }
end

Instance Attribute Details

#profileObject (readonly)

Returns the value of attribute profile.



15
16
17
# File 'lib/predictability_engine/jira_workflow.rb', line 15

def profile
  @profile
end

#projectObject (readonly)

Returns the value of attribute project.



15
16
17
# File 'lib/predictability_engine/jira_workflow.rb', line 15

def project
  @project
end

#statusesObject (readonly)

Returns the value of attribute statuses.



15
16
17
# File 'lib/predictability_engine/jira_workflow.rb', line 15

def statuses
  @statuses
end

Class Method Details

.default_path(profile_name) ⇒ Object



23
24
25
# File 'lib/predictability_engine/jira_workflow.rb', line 23

def self.default_path(profile_name)
  File.expand_path(format(DEFAULT_PATH_TEMPLATE, profile_name))
end

.extract(profile_name, client: nil) ⇒ Object



34
35
36
37
38
39
# File 'lib/predictability_engine/jira_workflow.rb', line 34

def self.extract(profile_name, client: nil)
  client ||= Config.jira_client(profile_name)
  project = Config.jira(profile_name)[:project]
  statuses = fetch_statuses(client).map { |s| seed_role(s) }
  new(profile: profile_name, project: project, statuses: statuses)
end

.load(path) ⇒ Object



27
28
29
30
31
32
# File 'lib/predictability_engine/jira_workflow.rb', line 27

def self.load(path)
  return nil unless path && File.exist?(path)

  raw = Config.load_yaml_file(path) || {}
  new(profile: raw['profile'], project: raw['project'], statuses: raw['statuses'] || [])
end

.merge(configs) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/predictability_engine/jira_workflow.rb', line 55

def self.merge(configs)
  merged = {}
  configs.each do |cfg|
    cfg.statuses.each { |s| merge_status(merged, s) }
  end
  new(statuses: merged.values)
end

.normalize_status(hash) ⇒ Object



63
64
65
66
67
# File 'lib/predictability_engine/jira_workflow.rb', line 63

def self.normalize_status(hash)
  h = hash.transform_keys(&:to_s)
  role = h['role'].to_s.empty? ? nil : h['role'].to_s
  { name: h['name'], category: h['category'], role: role }
end

Instance Method Details

#arrival_namesObject



82
83
84
# File 'lib/predictability_engine/jira_workflow.rb', line 82

def arrival_names
  names_for('arrival')
end

#departure_namesObject



86
87
88
# File 'lib/predictability_engine/jira_workflow.rb', line 86

def departure_names
  names_for('departure')
end

#refresh(fresh) ⇒ Object

Refresh an existing config against a fresh Jira fetch:

  • statuses the user already annotated keep their role

  • brand-new statuses are added with the seeded default role

  • statuses that disappeared from Jira are dropped



45
46
47
48
49
50
51
52
53
# File 'lib/predictability_engine/jira_workflow.rb', line 45

def refresh(fresh)
  existing_roles = @statuses.to_h { |s| [s[:name], s[:role]] }
  @statuses = fresh.statuses.map do |s|
    s.merge(role: existing_roles.key?(s[:name]) ? existing_roles[s[:name]] : s[:role])
  end
  @profile ||= fresh.profile
  @project ||= fresh.project
  self
end

#to_hashObject



74
75
76
77
78
79
80
# File 'lib/predictability_engine/jira_workflow.rb', line 74

def to_hash
  {
    'profile' => @profile,
    'project' => @project,
    'statuses' => @statuses.map { |s| s.transform_keys(&:to_s) }
  }.compact
end

#write(path) ⇒ Object



69
70
71
72
# File 'lib/predictability_engine/jira_workflow.rb', line 69

def write(path)
  PredictabilityEngine.write_file(path, to_hash.to_yaml)
  path
end