danger-jira 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b60d918d9064f2dcba7770ed3af01a9d004c56a
4
- data.tar.gz: 2e68f7e4d194deea128895418831730ff58fd3e6
3
+ metadata.gz: daacac410e05a9b467387aebfd37ab246879df80
4
+ data.tar.gz: 2f8b2e3e28fe2b7fac647328296292e044faa768
5
5
  SHA512:
6
- metadata.gz: 3a86f35dc9e1dc148f542814fda32b4e169d6f7b4fe3cb707a6e8dd4be1fddf54f95b44d6434f34929f700e986492e3a1d0cd9f56e2c7ec9845a612f675c327b
7
- data.tar.gz: 6f09aacd48613a8a454bf6336e0d08373a1cdbdf627f81c7717eebbf3d2019c7a0de8f38dc846a2aeb6676424b83e74726cd84f5e02d7c672ab3dfefb196e962
6
+ metadata.gz: d2f031933e816a15720b421665f7f0c0f626e9da2270d6de76ad0780150142c3c323f11816bb8a602ef061930c6a53b25d45a1a70360012fc19885c5f177e9f6
7
+ data.tar.gz: 9d1f8d7c9910ff55c8bbd30d7bd5906e79e0c29ad6c2733dbd901acb2bb59f041adef5c2a4b05cd7b9d6046d82aa7092a75968f314edfa528321632a0aa76b12
data/README.md CHANGED
@@ -20,10 +20,11 @@ gem 'danger-jira'
20
20
  jira.check(
21
21
  key: ["KEY", "PM"],
22
22
  url: "https://myjira.atlassian.net/browse",
23
- search_title: true,
24
- search_commits: false,
25
- fail_on_warning: false,
26
- report_missing: true
23
+ search_title: true,
24
+ search_commits: false,
25
+ fail_on_warning: false,
26
+ report_missing: true,
27
+ skipabble: true
27
28
  )
28
29
  ```
29
30
 
@@ -48,6 +49,10 @@ With "KEY-123" in the PR title or PR body, Danger will comment with:
48
49
  Generated by :no_entry_sign: <a href="http://github.com/danger/danger/">Danger</a>
49
50
  </p>
50
51
 
52
+ ## Skipping
53
+
54
+ You can skip danger checking for a JIRA issue by having `[no-jira]` in your title or PR body.
55
+
51
56
  ## License
52
57
 
53
58
  MIT
@@ -1,3 +1,3 @@
1
1
  module Jira
2
- VERSION = "0.4.2".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
data/lib/jira/plugin.rb CHANGED
@@ -32,12 +32,17 @@ module Danger
32
32
  # @param [Boolean] report_missing
33
33
  # Option to report if no JIRA issue was found
34
34
  #
35
+ # @param [Boolean] skippable
36
+ # Option to skip the report if 'no-jira' is provided on the PR title, description or commits
37
+ #
35
38
  # @return [void]
36
39
  #
37
- def check(key: nil, url: nil, emoji: ":link:", search_title: true, search_commits: false, fail_on_warning: false, report_missing: true)
40
+ def check(key: nil, url: nil, emoji: ":link:", search_title: true, search_commits: false, fail_on_warning: false, report_missing: true, skippable: true)
38
41
  throw Error("'key' missing - must supply JIRA issue key") if key.nil?
39
42
  throw Error("'url' missing - must supply JIRA installation URL") if url.nil?
40
43
 
44
+ return if skippable && should_skip_jira?
45
+
41
46
  jira_issues = find_jira_issues(
42
47
  key: key,
43
48
  search_title: search_title,
@@ -89,6 +94,31 @@ module Danger
89
94
  return jira_issues.uniq
90
95
  end
91
96
 
97
+ def should_skip_jira?(search_title: true, search_commits: false)
98
+ # Consider first occurrence of 'no-jira'
99
+ regexp = Regexp.new("no-jira", true)
100
+
101
+ if search_title
102
+ github.pr_title.gsub(regexp) do |match|
103
+ return true unless match.empty?
104
+ end
105
+ end
106
+
107
+ if search_commits
108
+ git.commits.map do |commit|
109
+ commit.message.gsub(regexp) do |match|
110
+ return true unless match.empty?
111
+ end
112
+ end
113
+ end
114
+
115
+ github.pr_body.gsub(regexp) do |match|
116
+ return true unless match.empty?
117
+ end
118
+
119
+ return false
120
+ end
121
+
92
122
  def ensure_url_ends_with_slash(url)
93
123
  return "#{url}/" unless url.end_with?("/")
94
124
  return url
data/spec/jira_spec.rb CHANGED
@@ -19,7 +19,7 @@ module Danger
19
19
  it "can find jira issues via title" do
20
20
  allow(@jira).to receive_message_chain("github.pr_title").and_return("Ticket [WEB-123] and WEB-124")
21
21
  issues = @jira.find_jira_issues(key: "WEB")
22
- expect((issues <=> ["WEB-123", "WEB-124"]) == 0)
22
+ expect(issues).to eq(["WEB-123", "WEB-124"])
23
23
  end
24
24
 
25
25
  it "can find jira issues in commits" do
@@ -34,7 +34,7 @@ module Danger
34
34
  search_title: false,
35
35
  search_commits: true
36
36
  )
37
- expect((issues <=> ["WEB-125"]) == 0)
37
+ expect(issues).to eq(["WEB-125"])
38
38
  end
39
39
 
40
40
  it "can find jira issues in pr body" do
@@ -44,13 +44,42 @@ module Danger
44
44
  search_title: false,
45
45
  search_commits: false
46
46
  )
47
- expect((issues <=> ["WEB-126"]) == 0)
47
+ expect(issues).to eq(["WEB-126"])
48
+ end
49
+
50
+ it "can find no-jira in pr body" do
51
+ allow(@jira).to receive_message_chain("github.pr_body").and_return("[no-jira] Ticket doesn't need a jira but [WEB-123] WEB-123")
52
+ result = @jira.should_skip_jira?(
53
+ search_title: false,
54
+ search_commits: false
55
+ )
56
+ expect(result).to be(true)
57
+ end
58
+
59
+ it "can find no-jira in commits" do
60
+ single_commit = Object.new
61
+ def single_commit.message
62
+ "Small text change [no-jira]"
63
+ end
64
+ commits = [single_commit]
65
+ allow(@jira).to receive_message_chain("git.commits").and_return(commits)
66
+ result = @jira.should_skip_jira?(
67
+ search_title: false,
68
+ search_commits: true
69
+ )
70
+ expect(result).to be(true)
71
+ end
72
+
73
+ it "can find no-jira in title" do
74
+ allow(@jira).to receive_message_chain("github.pr_title").and_return("[no-jira] Ticket doesn't need jira but [WEB-123] and WEB-123")
75
+ result = @jira.should_skip_jira?
76
+ expect(result).to be(true)
48
77
  end
49
78
 
50
79
  it "can remove duplicates" do
51
80
  allow(@jira).to receive_message_chain("github.pr_title").and_return("Ticket [WEB-123] and WEB-123")
52
81
  issues = @jira.find_jira_issues(key: "WEB")
53
- expect((issues <=> ["WEB-123"]) == 0)
82
+ expect(issues).to eq(["WEB-123"])
54
83
  end
55
84
  end
56
85
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-jira
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RestlessThinker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-06 00:00:00.000000000 Z
11
+ date: 2018-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api