Class: PredictabilityEngine::JiraWorkflow
- Inherits:
-
Object
- Object
- PredictabilityEngine::JiraWorkflow
- 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
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#statuses ⇒ Object
readonly
Returns the value of attribute statuses.
Class Method Summary collapse
- .default_path(profile_name) ⇒ Object
- .extract(profile_name, client: nil) ⇒ Object
- .load(path) ⇒ Object
- .merge(configs) ⇒ Object
- .normalize_status(hash) ⇒ Object
Instance Method Summary collapse
- #arrival_names ⇒ Object
- #departure_names ⇒ Object
-
#initialize(profile: nil, project: nil, statuses: []) ⇒ JiraWorkflow
constructor
A new instance of JiraWorkflow.
-
#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.
- #to_hash ⇒ Object
- #write(path) ⇒ Object
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
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
15 16 17 |
# File 'lib/predictability_engine/jira_workflow.rb', line 15 def profile @profile end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
15 16 17 |
# File 'lib/predictability_engine/jira_workflow.rb', line 15 def project @project end |
#statuses ⇒ Object (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.(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_names ⇒ Object
84 85 86 |
# File 'lib/predictability_engine/jira_workflow.rb', line 84 def arrival_names names_for('arrival') end |
#departure_names ⇒ Object
88 89 90 |
# File 'lib/predictability_engine/jira_workflow.rb', line 88 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_hash ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/predictability_engine/jira_workflow.rb', line 76 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 73 74 |
# File 'lib/predictability_engine/jira_workflow.rb', line 69 def write(path) dir = File.dirname(path) FileUtils.mkdir_p(dir) File.write(path, to_hash.to_yaml) path end |