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(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.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/groundskeeper/jira.rb', line 30 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.
28 29 30 |
# File 'lib/groundskeeper/jira.rb', line 28 def client @client end |
Instance Method Details
#add_version_to_issue(issue_id:, version_name:) ⇒ Object
:nocov:
50 51 52 53 54 55 56 |
# File 'lib/groundskeeper/jira.rb', line 50 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:
42 43 44 45 46 |
# File 'lib/groundskeeper/jira.rb', line 42 def create_version(name:, prefix:) client.Version .build .save(name: name, project: prefix) end |
#fetch_issues_by_fix_version(version:) ⇒ Object
:nocov:
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/groundskeeper/jira.rb', line 70 def fetch_issues_by_fix_version(version:) search_path = "/rest/api/2/search" query = "fixVersion=\"#{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:
83 84 85 86 87 88 89 90 |
# File 'lib/groundskeeper/jira.rb', line 83 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:
60 61 62 63 64 65 66 |
# File 'lib/groundskeeper/jira.rb', line 60 def transition_issue(issue_id:, transition_id:) client.Issue .find(issue_id) .transitions .build .save(transition: { id: transition_id }) end |