Class: Danger::DangerJiraIssueLinks
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerJiraIssueLinks
- Defined in:
- lib/jira_issue_links/plugin.rb
Overview
Collect issue mentions from git commit messages. Results are passed out as a table in markdown.
Defined Under Namespace
Classes: JiraIssue
Instance Attribute Summary collapse
-
#include_resolves_keyword ⇒ Bool
If ‘true` then in report will be added “Resolves” keyword for automatic resolve issue in jira.
-
#jira_context_path ⇒ String
Jira context path Default - empty string.
-
#jira_password ⇒ String
Jira password.
-
#jira_site ⇒ String
Jira site url.
-
#jira_username ⇒ String
Jira username.
Instance Method Summary collapse
-
#collect_issues_from_commits ⇒ Array<String>
Find all issue references in commit messages.
-
#print_links_only ⇒ void
Generates a ‘markdown` list of issues with links No required access to Jira, needs only base url - `jira_site`.
-
#print_links_with_titles ⇒ void
Generates a ‘markdown` table of issues with type, title and link.
Instance Attribute Details
#include_resolves_keyword ⇒ Bool
If ‘true` then in report will be added “Resolves” keyword for automatic resolve issue in jira. Default - false
50 51 52 |
# File 'lib/jira_issue_links/plugin.rb', line 50 def include_resolves_keyword @include_resolves_keyword end |
#jira_context_path ⇒ String
Jira context path Default - empty string
43 44 45 |
# File 'lib/jira_issue_links/plugin.rb', line 43 def jira_context_path @jira_context_path end |
#jira_password ⇒ String
Jira password
32 33 34 |
# File 'lib/jira_issue_links/plugin.rb', line 32 def jira_password @jira_password end |
#jira_site ⇒ String
Jira site url
37 38 39 |
# File 'lib/jira_issue_links/plugin.rb', line 37 def jira_site @jira_site end |
#jira_username ⇒ String
Jira username
27 28 29 |
# File 'lib/jira_issue_links/plugin.rb', line 27 def jira_username @jira_username end |
Instance Method Details
#collect_issues_from_commits ⇒ Array<String>
Find all issue references in commit messages. Message should starts with pattern: ‘[TASK-123]`
55 56 57 58 59 60 |
# File 'lib/jira_issue_links/plugin.rb', line 55 def collect_issues_from_commits git.commits .flat_map { |c| c..match(/^\[(\w+-\d+)\]/)&.captures } .compact .uniq end |
#print_links_only ⇒ void
This method returns an undefined value.
Generates a ‘markdown` list of issues with links No required access to Jira, needs only base url - `jira_site`.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/jira_issue_links/plugin.rb', line 103 def print_links_only found_issues = collect_issues_from_commits return if found_issues.empty? = "## Jira issues\n\n" found_issues.each do |issue_id| if include_resolves_keyword << "Resolves " end << "[#{issue_id}](#{jira_site}/browse/#{issue_id})\n\n" end markdown end |
#print_links_with_titles ⇒ void
This method returns an undefined value.
Generates a ‘markdown` table of issues with type, title and link. Required access to Jira site.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/jira_issue_links/plugin.rb', line 66 def print_links_with_titles found_issues = collect_issues_from_commits return if found_issues.empty? = "## Jira issues\n\n" if include_resolves_keyword << "| | | |\n" << "| --- | --- | ----- |\n" else << "| | |\n" << "| --- | ----- |\n" end begin found_issues.each do |issue_id| issue = obtain_issue(issue_id) return if issue.nil? description = issue.summary description = description.gsub(/[<|>\[\]]/) { |bracket| "\\#{bracket}" } << "![#{issue.issuetype}](#{issue.iconUrl}) | " if include_resolves_keyword << "Resolves #{issue_id} | " end << "[#{description}](#{jira_site}/browse/#{issue_id})\n" end rescue JIRA::HTTPError => e print e. end markdown end |