Skip to content

Commit

Permalink
Merge pull request RestlessThinker#7 from mikian/master
Browse files Browse the repository at this point in the history
Find JIRA Tickets in Commits
  • Loading branch information
RestlessThinker authored Jun 26, 2018
2 parents 7a3bd97 + a1d9838 commit 91063d2
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 7 deletions.
Empty file modified .gitignore
100755 → 100644
Empty file.
Empty file modified .rubocop.yml
100755 → 100644
Empty file.
Empty file modified .travis.yml
100755 → 100644
Empty file.
Empty file modified Gemfile
100755 → 100644
Empty file.
Empty file modified Guardfile
100755 → 100644
Empty file.
Empty file modified LICENSE.txt
100755 → 100644
Empty file.
Empty file modified README.md
100755 → 100644
Empty file.
Empty file modified Rakefile
100755 → 100644
Empty file.
Empty file modified danger-jira.gemspec
100755 → 100644
Empty file.
Empty file modified lib/danger_jira.rb
100755 → 100644
Empty file.
Empty file modified lib/danger_plugin.rb
100755 → 100644
Empty file.
Empty file modified lib/jira/gem_version.rb
100755 → 100644
Empty file.
29 changes: 22 additions & 7 deletions lib/jira/plugin.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,40 @@ class DangerJira < Plugin
# @param [String] emoji
# The emoji you want to display in the message.
#
# @param [Boolean] search_title
# Option to search JIRA issues from PR title
#
# @param [Boolean] search_commits
# Option to search JIRA issues from commit messages
#
# @param [Boolean] fail_on_warning
# Option to fail danger if no JIRA issue found in PR title
# Option to fail danger if no JIRA issue found
#
# @param [Boolean] report_missing
# Option to report if no JIRA issue was found
#
# @return [void]
#
def check(key: nil, url: nil, emoji: ":link:", fail_on_warning: false)
def check(key: nil, url: nil, emoji: ":link:", search_title: true, search_commits: false, fail_on_warning: false, report_missing: true)
throw Error("'key' missing - must supply JIRA issue key") if key.nil?
throw Error("'url' missing - must supply JIRA installation URL") if url.nil?

# Support multiple JIRA projects
keys = key.kind_of?(Array) ? key.join("|") : key
jira_key_regex_string = "((#{keys})-[0-9]+)"
jira_key_regex_string = "((?:#{keys})-[0-9]+)"
regexp = Regexp.new(/#{jira_key_regex_string}/)

jira_issues = []
github.pr_title.gsub(regexp) do |match|
jira_issues << match

if search_title
jira_issues << github.pr_title.scan(regexp)
end
if search_commits
jira_issues << git.commits.map { |commit| commit.message.scan(regexp) }.compact
end

jira_issues.flatten.uniq

if jira_issues.empty?
github.pr_body.gsub(regexp) do |match|
jira_issues << match
Expand All @@ -48,8 +63,8 @@ def check(key: nil, url: nil, emoji: ":link:", fail_on_warning: false)
if !jira_issues.empty?
jira_urls = jira_issues.map { |issue| link(href: ensure_url_ends_with_slash(url), issue: issue) }.join(", ")
message("#{emoji} #{jira_urls}")
else
msg = "This PR does not contain a JIRA issue key in the PR title (e.g. KEY-123)"
elsif report_missing
msg = "This PR does not contain any JIRA issue keys in the PR title or commit messages (e.g. KEY-123)"
if fail_on_warning
fail(msg)
else
Expand Down
Empty file modified spec/jira_spec.rb
100755 → 100644
Empty file.
Empty file modified spec/spec_helper.rb
100755 → 100644
Empty file.

0 comments on commit 91063d2

Please sign in to comment.