Skip to content

Commit

Permalink
Merge pull request #11 from RestlessThinker/no-jira-tweaks
Browse files Browse the repository at this point in the history
Tweaks to the no-jira PR
  • Loading branch information
RestlessThinker authored Aug 22, 2018
2 parents bc11245 + 4bb6381 commit db35e7a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
```

Expand All @@ -48,6 +49,10 @@ With "KEY-123" in the PR title or PR body, Danger will comment with:
Generated by :no_entry_sign: <a href="http://github.com/danger/danger/">Danger</a>
</p>

## Skipping

You can skip danger checking for a JIRA issue by having `[no-jira]` in your title or PR body.

## License

MIT
2 changes: 1 addition & 1 deletion lib/jira/gem_version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Jira
VERSION = "0.4.2".freeze
VERSION = "0.5.0".freeze
end
15 changes: 7 additions & 8 deletions lib/jira/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
32 changes: 26 additions & 6 deletions spec/jira_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit db35e7a

Please sign in to comment.