Class: Groundskeeper::Jira
- Inherits:
-
Object
- Object
- Groundskeeper::Jira
- Defined in:
- lib/groundskeeper/jira.rb
Overview
Wraps an interface to Jira.
Defined Under Namespace
Classes: JiraClient
Constant Summary collapse
- JIRA_USERNAME_KEY =
"JIRA_USERNAME"
- JIRA_API_TOKEN_KEY =
"JIRA_API_TOKEN"
- JIRA_SITE_KEY =
"JIRA_SITE"
- DEPLOY_TO_STAGING =
"Deploy to Staging"
- DEPLOY_TO_PRODUCTION =
"Deploy to Production"
- TRANSITION_IDS =
{ DEPLOY_TO_STAGING => 201, DEPLOY_TO_PRODUCTION => 221 }.freeze
- ISSUE_PATTERN =
"%s-\\d+"
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Class Method Summary collapse
Instance Method Summary collapse
- #add_version_to_remote_issues(name, issue_ids) ⇒ Object
- #create_remote_version(name) ⇒ Object
- #credentials? ⇒ Boolean
-
#fetch_issues_by_fix_version(project:, version:) ⇒ Object
:nocov:.
-
#included_issues(changes) ⇒ Object
Returns the list of Jira issues found in a set of commit messages.
-
#initialize(client: nil, prefix: nil) ⇒ Jira
constructor
A new instance of Jira.
-
#release_version(project, version) ⇒ Object
:nocov:.
- #transition_remote_issues(transition_type, issue_ids) ⇒ Object
Constructor Details
#initialize(client: nil, prefix: nil) ⇒ Jira
Returns a new instance of Jira.
102 103 104 105 |
# File 'lib/groundskeeper/jira.rb', line 102 def initialize(client: nil, prefix: nil) @prefix = prefix @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
23 24 25 |
# File 'lib/groundskeeper/jira.rb', line 23 def client @client end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
23 24 25 |
# File 'lib/groundskeeper/jira.rb', line 23 def prefix @prefix end |
Class Method Details
.build(prefix) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/groundskeeper/jira.rb', line 95 def self.build(prefix) new( prefix: prefix, client: JiraClient.new ) end |
Instance Method Details
#add_version_to_remote_issues(name, issue_ids) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/groundskeeper/jira.rb', line 128 def add_version_to_remote_issues(name, issue_ids) failed_issues = [] issue_ids.each do |issue_id| client.add_version_to_issue(issue_id: issue_id, version_name: name) rescue IssueNotFoundError failed_issues << issue_id next end return "" unless failed_issues.count.positive? "Jira issue(s) not found, is #{failed_issues.join(', ')} correct?" end |
#create_remote_version(name) ⇒ Object
124 125 126 |
# File 'lib/groundskeeper/jira.rb', line 124 def create_remote_version(name) client.create_version(name: name, prefix: prefix) end |
#credentials? ⇒ Boolean
107 108 109 110 111 |
# File 'lib/groundskeeper/jira.rb', line 107 def credentials? !ENV.fetch(JIRA_USERNAME_KEY, "").empty? && !ENV.fetch(JIRA_API_TOKEN_KEY, "").empty? && !ENV.fetch(JIRA_SITE_KEY, "").empty? end |
#fetch_issues_by_fix_version(project:, version:) ⇒ Object
:nocov:
151 152 153 |
# File 'lib/groundskeeper/jira.rb', line 151 def fetch_issues_by_fix_version(project:, version:) client.fetch_issues_by_fix_version(project: project, version: version) end |
#included_issues(changes) ⇒ Object
Returns the list of Jira issues found in a set of commit messages.
114 115 116 117 118 119 120 121 122 |
# File 'lib/groundskeeper/jira.rb', line 114 def included_issues(changes) issue_expression = /#{format(ISSUE_PATTERN, prefix)}/ changes .map { |change| change.scan(issue_expression) } .flatten .compact .sort end |
#release_version(project, version) ⇒ Object
:nocov:
156 157 158 |
# File 'lib/groundskeeper/jira.rb', line 156 def release_version(project, version) client.release_version(project: project, version: version) end |
#transition_remote_issues(transition_type, issue_ids) ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/groundskeeper/jira.rb', line 141 def transition_remote_issues(transition_type, issue_ids) issue_ids.each do |issue_id| client.transition_issue( issue_id: issue_id[0], transition_id: TRANSITION_IDS[transition_type] ) end end |