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(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.
101 102 103 104 |
# File 'lib/groundskeeper/jira.rb', line 101 def initialize(client: nil, prefix: nil) @prefix = prefix @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
22 23 24 |
# File 'lib/groundskeeper/jira.rb', line 22 def client @client end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
22 23 24 |
# File 'lib/groundskeeper/jira.rb', line 22 def prefix @prefix end |
Class Method Details
.build(prefix) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/groundskeeper/jira.rb', line 94 def self.build(prefix) new( prefix: prefix, client: JiraClient.new ) end |
Instance Method Details
#add_version_to_remote_issues(name, issue_ids) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/groundskeeper/jira.rb', line 127 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
123 124 125 |
# File 'lib/groundskeeper/jira.rb', line 123 def create_remote_version(name) client.create_version(name: name, prefix: prefix) end |
#credentials? ⇒ Boolean
106 107 108 109 110 |
# File 'lib/groundskeeper/jira.rb', line 106 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(version) ⇒ Object
:nocov:
150 151 152 |
# File 'lib/groundskeeper/jira.rb', line 150 def fetch_issues_by_fix_version(version) client.fetch_issues_by_fix_version(version: version) end |
#included_issues(changes) ⇒ Object
Returns the list of Jira issues found in a set of commit messages.
113 114 115 116 117 118 119 120 121 |
# File 'lib/groundskeeper/jira.rb', line 113 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:
155 156 157 |
# File 'lib/groundskeeper/jira.rb', line 155 def release_version(project, version) client.release_version(project: project, version: version) end |
#transition_remote_issues(transition_type, issue_ids) ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/groundskeeper/jira.rb', line 140 def transition_remote_issues(transition_type, issue_ids) issue_ids.each do |issue_id| client.transition_issue( issue_id: issue_id, transition_id: TRANSITION_IDS[transition_type] ) end end |