diff --git a/README.md b/README.md index 5cd09bd..dfd7719 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,11 @@ gem 'danger-jira' jira.check( key: ["KEY", "PM"], url: "https://myjira.atlassian.net/browse", - search_title: true, - search_commits: false, - fail_on_warning: false, - report_missing: true + search_title: true, + search_commits: false, + fail_on_warning: false, + report_missing: true, + skipabble: true ) ``` @@ -48,6 +49,10 @@ With "KEY-123" in the PR title or PR body, Danger will comment with: Generated by :no_entry_sign: Danger

+## Skipping + +You can skip danger checking for a JIRA issue by having `[no-jira]` in your title or PR body. + ## License MIT diff --git a/lib/jira/gem_version.rb b/lib/jira/gem_version.rb index 8150d96..d216604 100644 --- a/lib/jira/gem_version.rb +++ b/lib/jira/gem_version.rb @@ -1,3 +1,3 @@ module Jira - VERSION = "0.4.2".freeze + VERSION = "0.5.0".freeze end diff --git a/lib/jira/plugin.rb b/lib/jira/plugin.rb index 0116e3c..47904b6 100644 --- a/lib/jira/plugin.rb +++ b/lib/jira/plugin.rb @@ -41,7 +41,7 @@ def check(key: nil, url: nil, emoji: ":link:", search_title: true, search_commit throw Error("'key' missing - must supply JIRA issue key") if key.nil? throw Error("'url' missing - must supply JIRA installation URL") if url.nil? - return if skippable && should_skip_jira? + return if skippable && should_skip_jira? jira_issues = find_jira_issues( key: key, @@ -94,32 +94,31 @@ def find_jira_issues(key: nil, search_title: true, search_commits: false) return jira_issues.uniq end - def should_skip_jira(search_title: true, search_commits: false) + def should_skip_jira?(search_title: true, search_commits: false) # Consider first occurrence of 'no-jira' - regexp = Regexp.new('no-jira', true) + regexp = Regexp.new("no-jira", true) if search_title github.pr_title.gsub(regexp) do |match| - if match.nil? return true + return true unless match.empty? end end if search_commits git.commits.map do |commit| commit.message.gsub(regexp) do |match| - if match.nil? return true + return true unless match.empty? end end end github.pr_body.gsub(regexp) do |match| - if match.nil? return true - end + return true unless match.empty? + end return false end - def ensure_url_ends_with_slash(url) return "#{url}/" unless url.end_with?("/") return url diff --git a/spec/jira_spec.rb b/spec/jira_spec.rb index 3e57ccb..ba5558e 100644 --- a/spec/jira_spec.rb +++ b/spec/jira_spec.rb @@ -19,7 +19,7 @@ module Danger it "can find jira issues via title" do allow(@jira).to receive_message_chain("github.pr_title").and_return("Ticket [WEB-123] and WEB-124") issues = @jira.find_jira_issues(key: "WEB") - expect((issues <=> ["WEB-123", "WEB-124"]) == 0) + expect(issues).to eq(["WEB-123", "WEB-124"]) end it "can find jira issues in commits" do @@ -34,7 +34,7 @@ def single_commit.message search_title: false, search_commits: true ) - expect((issues <=> ["WEB-125"]) == 0) + expect(issues).to eq(["WEB-125"]) end it "can find jira issues in pr body" do @@ -44,22 +44,42 @@ def single_commit.message search_title: false, search_commits: false ) - expect((issues <=> ["WEB-126"]) == 0) + expect(issues).to eq(["WEB-126"]) end it "can find no-jira in pr body" do allow(@jira).to receive_message_chain("github.pr_body").and_return("[no-jira] Ticket doesn't need a jira but [WEB-123] WEB-123") - result = @jira.should_skip_jira( + result = @jira.should_skip_jira?( search_title: false, search_commits: false ) - expect((result <=> true) == 0) + expect(result).to be(true) + end + + it "can find no-jira in commits" do + single_commit = Object.new + def single_commit.message + "Small text change [no-jira]" + end + commits = [single_commit] + allow(@jira).to receive_message_chain("git.commits").and_return(commits) + result = @jira.should_skip_jira?( + search_title: false, + search_commits: true + ) + expect(result).to be(true) + end + + it "can find no-jira in title" do + allow(@jira).to receive_message_chain("github.pr_title").and_return("[no-jira] Ticket doesn't need jira but [WEB-123] and WEB-123") + result = @jira.should_skip_jira? + expect(result).to be(true) end it "can remove duplicates" do allow(@jira).to receive_message_chain("github.pr_title").and_return("Ticket [WEB-123] and WEB-123") issues = @jira.find_jira_issues(key: "WEB") - expect((issues <=> ["WEB-123"]) == 0) + expect(issues).to eq(["WEB-123"]) end end end