Parent

Class/Module Index [+]

Quicksearch

Pkg::Util::Jira

Public Class Methods

jira_client_options(username, password, site) click to toggle source

This class is a very thin wrapper around the jira library. For testability, the small bit of logic that does some prep for the library or processing of its output are extracted into a handful of class methods.

# File ext/packaging/lib/packaging/util/jira.rb, line 8
def self.jira_client_options(username, password, site)
  {
    :username           => username,
    :password           => password,
    :site               => site,
    :context_path       => '',
    :auth_type          => :basic,
    :use_ssl            => true,
  }
end
jira_issue_fields(summary, description, project, parent, assignee) click to toggle source
# File ext/packaging/lib/packaging/util/jira.rb, line 24
def self.jira_issue_fields(summary, description, project, parent, assignee)
  # build the fields hash describing the ticket
  fields = {
      'summary'     => summary,
      'description' => description,
      'project'     => { 'key' => project},
      'issuetype'   => { 'name' => parent ? "Sub-task" : "Task" },
      'assignee'    => { 'name' => assignee },
  }
  if parent
    fields['parent'] = { 'id' => parent }
  end

  fields
end
jira_project_name(projects, project) click to toggle source
# File ext/packaging/lib/packaging/util/jira.rb, line 19
def self.jira_project_name(projects, project)
  # projects is an array of objects with key and name methods
  projects.find { |p| p.key == project }.name
end
new(username, password, site) click to toggle source

Future improvement, exception handling and more helpful error messages

# File ext/packaging/lib/packaging/util/jira.rb, line 42
def initialize(username, password, site)
  # This library uses the gem called 'jira-ruby' which provides the library 'jira'.
  # Not to be confused with the gem called 'jira'. Be careful out there.
  Pkg::Util.require_library_or_fail('jira', 'jira-ruby')

  # Construct a jira client
  options = self.class.jira_client_options(username, password, site)
  options[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_PEER
      # only get OpenSSL through the jira library so leave it out of the class method
  @client = JIRA::Client.new(options)
end

Public Instance Methods

create_issue(summary, description, project, parent, assignee) click to toggle source
# File ext/packaging/lib/packaging/util/jira.rb, line 70
def create_issue(summary, description, project, parent, assignee)
  fields = self.class.jira_issue_fields(summary, description, project,
                                        parent, assignee)

  issue = @client.Issue.build
  issue.save!( {'fields' => fields } )

  # fetch the issue back so we can report the key and id
  issue.fetch

  return issue.key, issue.id
end
project?(project) click to toggle source
# File ext/packaging/lib/packaging/util/jira.rb, line 54
def project?(project)
  @client.Project.find(project)
rescue
  fail "Could not find project: #{project}"
end
project_name(project) click to toggle source
# File ext/packaging/lib/packaging/util/jira.rb, line 66
def project_name(project)
  self.class.jira_project_name(@client.Project.all, project)
end
user?(user) click to toggle source
# File ext/packaging/lib/packaging/util/jira.rb, line 60
def user?(user)
  @client.User.find(user)
rescue
  fail "Could not find user: #{user}"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.