Module: JiraHelper::Issue

Included in:
Lita::Handlers::Jira, Lita::Handlers::JiraUtility
Defined in:
lib/jirahelper/issue.rb

Overview

Issues

Instance Method Summary collapse

Instance Method Details

#create_issue(project, subject, summary) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/jirahelper/issue.rb', line 60

def create_issue(project, subject, summary)
  project = fetch_project(project)
  return nil unless project
  issue = client.Issue.build
  issue.save(fields: { subject: subject,
                       summary: summary,
                       project: { id: project.id } })
  issue.fetch
  issue
end

#fetch_issue(key, expected = true) ⇒ Object

NOTE: Prefer this syntax here as it’s cleaner rubocop:disable Style/RescueEnsureAlignment



7
8
9
10
11
12
# File 'lib/jirahelper/issue.rb', line 7

def fetch_issue(key, expected = true)
  client.Issue.find(key)
  rescue
    log.error('JIRA HTTPError') if expected
    nil
end

#fetch_issues(jql) ⇒ Type Array

Leverage the jira-ruby Issue.jql search feature

Parameters:

  • jql (Type String)

    Valid JQL query

Returns:

  • (Type Array)

    0-m JIRA Issues returned from query



19
20
21
# File 'lib/jirahelper/issue.rb', line 19

def fetch_issues(jql)
  client.Issue.jql(jql)
end

#fetch_project(key) ⇒ Object

NOTE: Prefer this syntax here as it’s cleaner rubocop:disable Style/RescueEnsureAlignment



25
26
27
28
29
30
# File 'lib/jirahelper/issue.rb', line 25

def fetch_project(key)
  client.Project.find(key)
  rescue
    log.error('JIRA HTTPError')
    nil
end

#format_issue(issue) ⇒ Object

NOTE: Not breaking this function out just yet. rubocop:disable Metrics/AbcSize



35
36
37
38
39
40
41
42
43
44
# File 'lib/jirahelper/issue.rb', line 35

def format_issue(issue)
  t(config.format == 'one-line' ? 'issue.oneline' : 'issue.details',
    key: issue.key,
    summary: issue.summary,
    status: issue.status.name,
    assigned: optional_issue_property('unassigned') { issue.assignee.displayName },
    fixVersion: optional_issue_property('none') { issue.fixVersions.first['name'] },
    priority: optional_issue_property('none') { issue.priority.name },
    url: format_issue_link(issue.key))
end


56
57
58
# File 'lib/jirahelper/issue.rb', line 56

def format_issue_link(key)
  "#{config.site}#{config.context}/browse/#{key}"
end

#format_issues(issues) ⇒ Type Array<String>

Enumerate issues returned from JQL query and format for response

Parameters:

  • issues (Type Array)

    1-m issues returned from JQL query

Returns:

  • (Type Array<String>)

    formatted issues for display to user



51
52
53
54
# File 'lib/jirahelper/issue.rb', line 51

def format_issues(issues)
  results = [t('myissues.info')]
  results.concat(issues.map { |issue| format_issue(issue) })
end

#optional_issue_property(fallback = '') ⇒ Type String

Attempt to retrieve optional JIRA issue property value via a provided block. JIRA properties such as assignee and priority may not exist. In that case, the fallback will be used.

Parameters:

  • fallback (Type String) (defaults to: '')

    A String value to use if the JIRA property value doesn’t exist

Returns:

  • (Type String)

    fallback or returned value from yield block



77
78
79
80
81
# File 'lib/jirahelper/issue.rb', line 77

def optional_issue_property(fallback = '')
  yield
rescue
  fallback
end