class NG1BuildHelpers::JIRA::Jira
This class will be used to create a Fix Version for a given release and build number and then assign any tickets to those fix versions.
Attributes
client[R]
fixed_in_build_field_id[R]
jira_transition_id[R]
Public Class Methods
new(options)
click to toggle source
# File lib/jira/jira.rb, line 29 def initialize(options) site = options.site username = options.username password = options.password auth_token = Base64.strict_encode64("#{username}:#{password}") base_url = File.join(site, '/rest/api/2') headers = { "Authorization" => "Basic #{auth_token}", "Content-Type" => "application/json", } @client = RestClient::Resource.new(base_url, :headers => headers) @@build = options.build @@version = options.version @@project = options.project @@version_name = options.version_name end
Public Instance Methods
create_release_version()
click to toggle source
Create a release version in JIRA
and return it's ID
# File lib/jira/jira.rb, line 49 def create_release_version() begin params = { "name" => "#{@@version_name} #{@@version}-#{@@build}", "released" => true, "project" => "#{@@project}", "releaseDate" => DateTime.now } puts "Creating release #{JSON.generate(params)}" version_response = client["version"].post(JSON.generate(params)) fields = JSON.parse(version_response.body) version_id = fields["id"] rescue RestClient::Exception => e puts "Error updating version : Error code #{e.response}" end version_id end
jira_update(issues, options)
click to toggle source
# File lib/jira/jira.rb, line 144 def jira_update(issues, options) puts "Updating JIRA" version_id = create_release_version() if (version_id) #Set the fix version of all the issues that were built. issues.each do |issue_key| puts "Updating issue #{issue_key} to release version #{version_id}" update_fix_version(issue_key, version_id) update_transition(issue_key) end end end
update_fix_version(issue_key, version_id)
click to toggle source
# File lib/jira/jira.rb, line 91 def update_fix_version(issue_key, version_id) params = { update: { # Set the fix version "fixVersions" => [ { "add" => {"id" => version_id} } ], # Peer Review Field "customfield_19007" => [ { "set" => [ {"value" => "Complete"} ] } ] } } puts "Setting #{issue_key} fix version to #{version_id}" begin issue_response = client["issue/#{issue_key}"].put(JSON.generate(params)) rescue RestClient::Exception => e puts "Error updating issue #{issue_key}: Error: #{e.response}" end end
update_testing_transition(issue_key)
click to toggle source
# File lib/jira/jira.rb, line 70 def update_testing_transition(issue_key) begin fields_resource = "issue/#{issue_key}/transitions" response = client[fields_resource].get response_json = JSON.parse(response.body) transitions = response_json["transitions"] testing_transition = transitions.find do |transition| transition["name"] == "Testing" end if testing_transition @jira_transition_id = testing_transition["id"] end rescue RestClient::Exception => e puts "Error code #{e.response} attempting to find Build Complete transition" end end
update_transition(issue_key)
click to toggle source
# File lib/jira/jira.rb, line 120 def update_transition(issue_key) #try to perform the transition if !jira_transition_id update_testing_transition(issue_key) end if jira_transition_id begin params = { transition: { id: jira_transition_id } } puts "Transitioning #{issue_key} to Testing" issue_response = client["issue/#{issue_key}/transitions"].post(JSON.generate(params)) rescue RestClient::Exception => e puts "Error updating issue #{issue_key}: Error #{e.response}" end end end