class Speedflow::Plugin::Jira::Client
Attributes
@return [JIRA::Client] JIRA Client
.
@return [Prompt] Prompt
.
Public Class Methods
Initialize.
config - Speedflow::Plugin::Jira::Configuration instance. prompt - Speedflow::Plugin::Jira::Prompt
instance.
Examples
Client.new({}, Speedflow::Plugin::Jira::Prompt.new) # => <Speedflow::Plugin::Jira::Client>
Returns nothing.
# File lib/speedflow/plugin/jira/client.rb, line 28 def initialize(config, prompt) @config = config @prompt = prompt end
Public Instance Methods
Public: Auth hash for JIRA.
Returns hash of auth.
# File lib/speedflow/plugin/jira/client.rb, line 174 def auth { username: @config.by_config('username'), password: @config.by_config('password'), site: @config.by_config('site'), context_path: @config.by_config('context_path', ''), auth_type: @config.by_config('auth_type', :basic).to_sym, read_timeout: @config.by_config('read_timeout', 120).to_i } end
Public: Create issue.
project_key - Project key. title - Title (summary). issue_type_id - Issue type (Fixnum).
Returns Hash of issue.
# File lib/speedflow/plugin/jira/client.rb, line 53 def create_issue(project_key, title, issue_type_id) safe do issue = jira_client.Issue.build data = IssueFormatter.to_create(project_key, title, issue_type_id) issue.save!(data) issue.fetch issue end end
Public: Issue link.
issue_key - Issue key.
Returns issue link.
# File lib/speedflow/plugin/jira/client.rb, line 130 def issue_link(issue_key) issue_link = @config.by_config('site') issue_link << @config.by_config('context_path') issue_link << 'browse/' issue_link << issue_key issue_link end
Public: Issue output formatter.
issue - ::JIRA::Resource::Issue
Returns Hash.
# File lib/speedflow/plugin/jira/client.rb, line 143 def issue_output_format(issue) { 'issue' => { 'key' => issue.key, 'summary' => issue.fields['summary'], 'url' => issue_link(issue.key) } } end
Public: Jira
issue transitions.
issue_key - Issue key.
Returns Hash of transitions.
# File lib/speedflow/plugin/jira/client.rb, line 111 def issue_trans(issue_key) safe do issue = jira_client.Issue.find(issue_key, expand: 'transitions') issue.transitions end end
Public: Jira
issue types.
Returns Hash of issue types.
# File lib/speedflow/plugin/jira/client.rb, line 121 def issue_types safe { jira_client.Issuetype.all } end
Public: Jira
client.
Returns <::JIRA::Client> instance.
# File lib/speedflow/plugin/jira/client.rb, line 167 def jira_client @jira_client ||= ::JIRA::Client.new(auth) end
Public: Jira
project.
project_key - Project key.
Returns JIRA::Resource.Project.
# File lib/speedflow/plugin/jira/client.rb, line 95 def project(project_key) safe { jira_client.Project.find(project_key) } end
Public: Jira
projects.
Returns Hash of projects.
# File lib/speedflow/plugin/jira/client.rb, line 102 def projects safe { jira_client.Project.all } end
Public: Prompt
.
Returns <::Speedflow::Plugin::Prompt> instance.
# File lib/speedflow/plugin/jira/client.rb, line 188 def prompt @prompt ||= ::Speedflow::Plugin::Prompt.new end
Public: Safe process JIRA action.
Returns nothing.
# File lib/speedflow/plugin/jira/client.rb, line 153 def safe yield rescue ::JIRA::HTTPError => exception prompt.error 'Jira errors' prompt.errors exception abort rescue ::URI::InvalidURIError prompt.error 'Invalid URL' abort end
Public: Search issue.
project - Project name. title - Issue title.
Returns Hash of issue.
# File lib/speedflow/plugin/jira/client.rb, line 39 def search_issue(project, title) safe do jira_client .Issue.jql("PROJECT = \"#{project}\" AND text ~ \"#{title}\"") end end
Public: Update issue.
issue_key - Key of issue. assignee_name - Assignee name.
Returns Hash of issue.
# File lib/speedflow/plugin/jira/client.rb, line 69 def update_issue_assignee(issue_key, assignee_name) safe do issue = jira_client.Issue.find(issue_key) data = IssueFormatter.to_assignee(assignee_name) issue.save!(data) end end
Public: Update issue transition.
issue_key - Key of issue. transition_id - Transition ID.
Returns Hash of issue.
# File lib/speedflow/plugin/jira/client.rb, line 83 def update_issue_transition(issue_key, transition_id) safe do issue = jira_client.Issue.find(issue_key) issue.transitions.build.save!(transition: transition_id) end end