Class: Groundskeeper::Jira::JiraClient
- Inherits:
-
Object
- Object
- Groundskeeper::Jira::JiraClient
- Defined in:
- lib/groundskeeper/jira.rb
Overview
Wraps the jira-ruby Client class.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#add_version_to_issue(issue_id:, version_name:) ⇒ Object
:nocov:.
-
#create_version(name:, prefix:) ⇒ Object
:nocov:.
-
#fetch_issues_by_fix_version(project:, version:) ⇒ Object
:nocov:.
-
#initialize ⇒ JiraClient
constructor
A new instance of JiraClient.
-
#release_version(project:, version:) ⇒ Object
:nocov:.
-
#transition_issue(issue_id:, transition_id:) ⇒ Object
:nocov:.
Constructor Details
#initialize ⇒ JiraClient
Returns a new instance of JiraClient.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/groundskeeper/jira.rb', line 31 def initialize @client = JIRA::Client.new( username: ENV.fetch(JIRA_USERNAME_KEY, nil), password: ENV.fetch(JIRA_API_TOKEN_KEY, nil), site: ENV.fetch(JIRA_SITE_KEY, nil), context_path: "", auth_type: :basic, read_timeout: 120 ) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
29 30 31 |
# File 'lib/groundskeeper/jira.rb', line 29 def client @client end |
Instance Method Details
#add_version_to_issue(issue_id:, version_name:) ⇒ Object
:nocov:
51 52 53 54 55 56 57 |
# File 'lib/groundskeeper/jira.rb', line 51 def add_version_to_issue(issue_id:, version_name:) raise IssueNotFoundError if client.Issue.find(issue_id).nil? client.Issue .find(issue_id) .save(update: { fixVersions: [{ add: { name: version_name } }] }) end |
#create_version(name:, prefix:) ⇒ Object
:nocov:
43 44 45 46 47 |
# File 'lib/groundskeeper/jira.rb', line 43 def create_version(name:, prefix:) client.Version .build .save(name: name, project: prefix) end |
#fetch_issues_by_fix_version(project:, version:) ⇒ Object
:nocov:
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/groundskeeper/jira.rb', line 71 def fetch_issues_by_fix_version(project:, version:) search_path = "/rest/api/2/search" query = "fixVersion=\"#{project.repo_name} #{version}\"" request_url = "#{search_path}?fields=key&jql=#{CGI.escape(query)}" response = client.get(request_url).body JSON.parse(response)["issues"].map { |issue| issue["key"] } rescue JIRA::HTTPError puts "Jira request failed - #{request_url}" end |
#release_version(project:, version:) ⇒ Object
:nocov:
84 85 86 87 88 89 90 91 |
# File 'lib/groundskeeper/jira.rb', line 84 def release_version(project:, version:) version_name = "#{project.repo_name} #{version}" client.Project .find(project.jira_prefix) .versions .find { |element| element.name == version_name } .save(released: true) end |
#transition_issue(issue_id:, transition_id:) ⇒ Object
:nocov:
61 62 63 64 65 66 67 |
# File 'lib/groundskeeper/jira.rb', line 61 def transition_issue(issue_id:, transition_id:) client.Issue .find(issue_id) .transitions .build .save(transition: { id: transition_id }) end |