danger-jira 0.6.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +4 -2
- data/danger-jira.gemspec +2 -2
- data/lib/jira/gem_version.rb +1 -1
- data/lib/jira/plugin.rb +37 -8
- data/spec/jira_spec.rb +65 -1
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7287a448b908b4d6879ac9b84f23eca2d36d5d9dd054a0825f29ea710a7de426
|
4
|
+
data.tar.gz: d15208bc1856e2aca33a38f507b1d49b1dca882d21a3f7d8571b57b93ab29b3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86772d0e7840a1c448e5d94d2e5df3c8b5a73190a3d17b961686b4e054008d3c2094e4364c8fc7c474818f305e685e0b108baf28673080129bfec24a05ad9686
|
7
|
+
data.tar.gz: ccb68490a542b183a1cfa62ea8dca9dd20dee815eeadfc6c7ff2711c13181c7ac9c460ea40a19b4e9e7fc80e9f185bd4c1b03ec65c9317da949a00ea2ceb3c57
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](LICENSE.txt)
|
4
4
|
[](https://rubygems.org/gems/danger-jira)
|
5
5
|
|
6
|
-
A [Danger](https://github.com/danger/danger) plugin for that links JIRA issues to pull requests. Inspired by [danger-plugin-jira-issue](https://github.com/macklinu/danger-plugin-jira-issue)
|
6
|
+
A [Danger](https://github.com/danger/danger) plugin for that links JIRA issues to pull requests for both GitHub and GitLab. Inspired by [danger-plugin-jira-issue](https://github.com/macklinu/danger-plugin-jira-issue)
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -22,6 +22,8 @@ jira.check(
|
|
22
22
|
url: "https://myjira.atlassian.net/browse",
|
23
23
|
search_title: true,
|
24
24
|
search_commits: false,
|
25
|
+
search_branch: false,
|
26
|
+
search_body: false,
|
25
27
|
fail_on_warning: false,
|
26
28
|
report_missing: true,
|
27
29
|
skippable: true
|
@@ -51,7 +53,7 @@ With "KEY-123" in the PR title or PR body, Danger will comment with:
|
|
51
53
|
|
52
54
|
## Skipping
|
53
55
|
|
54
|
-
You can skip danger checking for a JIRA issue by
|
56
|
+
You can skip danger checking for a JIRA issue by if `no-jira` is provided on the PR title, description or commits. `nojira` is also allowed on branch names.
|
55
57
|
|
56
58
|
## License
|
57
59
|
|
data/danger-jira.gemspec
CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
|
22
22
|
|
23
23
|
# General ruby development
|
24
|
-
spec.add_development_dependency 'bundler', '~>
|
25
|
-
spec.add_development_dependency 'rake', '~>
|
24
|
+
spec.add_development_dependency 'bundler', '~> 2.4'
|
25
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
26
26
|
|
27
27
|
# Testing support
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
data/lib/jira/gem_version.rb
CHANGED
data/lib/jira/plugin.rb
CHANGED
@@ -26,6 +26,9 @@ module Danger
|
|
26
26
|
# @param [Boolean] search_commits
|
27
27
|
# Option to search JIRA issues from commit messages
|
28
28
|
#
|
29
|
+
# @param [Boolean] search_branch
|
30
|
+
# Option to search JIRA issues from the name of the PR branch
|
31
|
+
#
|
29
32
|
# @param [Boolean] fail_on_warning
|
30
33
|
# Option to fail danger if no JIRA issue found
|
31
34
|
#
|
@@ -33,11 +36,11 @@ module Danger
|
|
33
36
|
# Option to report if no JIRA issue was found
|
34
37
|
#
|
35
38
|
# @param [Boolean] skippable
|
36
|
-
# Option to skip the report if 'no-jira' is provided on the PR title, description or commits
|
39
|
+
# Option to skip the report if 'no-jira' is provided on the PR title, description or commits. 'nojira' is also allowed on branch names.
|
37
40
|
#
|
38
41
|
# @return [void]
|
39
42
|
#
|
40
|
-
def check(key: nil, url: nil, emoji: ":link:", search_title: true, search_commits: false, fail_on_warning: false, report_missing: true, skippable: true)
|
43
|
+
def check(key: nil, url: nil, emoji: ":link:", search_title: true, search_commits: false, search_branch: false, search_body: false, fail_on_warning: false, report_missing: true, skippable: true)
|
41
44
|
throw Error("'key' missing - must supply JIRA issue key") if key.nil?
|
42
45
|
throw Error("'url' missing - must supply JIRA installation URL") if url.nil?
|
43
46
|
|
@@ -46,14 +49,21 @@ module Danger
|
|
46
49
|
jira_issues = find_jira_issues(
|
47
50
|
key: key,
|
48
51
|
search_title: search_title,
|
49
|
-
search_commits: search_commits
|
52
|
+
search_commits: search_commits,
|
53
|
+
search_branch: search_branch,
|
54
|
+
search_body: search_body
|
50
55
|
)
|
51
56
|
|
52
57
|
if !jira_issues.empty?
|
53
58
|
jira_urls = jira_issues.map { |issue| link(href: ensure_url_ends_with_slash(url), issue: issue) }.join(", ")
|
54
59
|
message("#{emoji} #{jira_urls}")
|
55
60
|
elsif report_missing
|
56
|
-
|
61
|
+
msg = error_message_for(
|
62
|
+
search_title,
|
63
|
+
search_commits,
|
64
|
+
search_branch,
|
65
|
+
search_body
|
66
|
+
)
|
57
67
|
if fail_on_warning
|
58
68
|
fail(msg)
|
59
69
|
else
|
@@ -69,7 +79,16 @@ module Danger
|
|
69
79
|
return github
|
70
80
|
end
|
71
81
|
|
72
|
-
def
|
82
|
+
def error_message_for(search_title, search_commits, search_branch, search_body)
|
83
|
+
error_string = ""
|
84
|
+
error_string += ", title" if search_title
|
85
|
+
error_string += ", commit messages" if search_commits
|
86
|
+
error_string += ", branch name" if search_branch
|
87
|
+
error_string += ", body" if search_body
|
88
|
+
return "This PR does not contain any JIRA issue keys in the PR" + error_string[1..-1] + " (e.g. KEY-123)"
|
89
|
+
end
|
90
|
+
|
91
|
+
def find_jira_issues(key: nil, search_title: true, search_commits: false, search_branch: false, search_body: false)
|
73
92
|
# Support multiple JIRA projects
|
74
93
|
keys = key.kind_of?(Array) ? key.join("|") : key
|
75
94
|
jira_key_regex_string = "((?:#{keys})-[0-9]+)"
|
@@ -91,7 +110,13 @@ module Danger
|
|
91
110
|
end
|
92
111
|
end
|
93
112
|
|
94
|
-
if
|
113
|
+
if search_branch
|
114
|
+
vcs_host.branch_for_head.gsub(regexp) do |match|
|
115
|
+
jira_issues << match
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
if search_body
|
95
120
|
vcs_host.pr_body.gsub(regexp) do |match|
|
96
121
|
jira_issues << match
|
97
122
|
end
|
@@ -100,8 +125,8 @@ module Danger
|
|
100
125
|
end
|
101
126
|
|
102
127
|
def should_skip_jira?(search_title: true)
|
103
|
-
# Consider first occurrence of 'no-jira'
|
104
|
-
regexp = Regexp.new("no-jira", true)
|
128
|
+
# Consider first occurrence of 'no-jira' or nojira
|
129
|
+
regexp = Regexp.new("(no-jira|nojira)", true)
|
105
130
|
|
106
131
|
if search_title
|
107
132
|
vcs_host.pr_title.gsub(regexp) do |match|
|
@@ -113,6 +138,10 @@ module Danger
|
|
113
138
|
return true unless match.empty?
|
114
139
|
end
|
115
140
|
|
141
|
+
vcs_host.branch_for_head.gsub(regexp) do |match|
|
142
|
+
return true unless match.empty?
|
143
|
+
end
|
144
|
+
|
116
145
|
return false
|
117
146
|
end
|
118
147
|
|
data/spec/jira_spec.rb
CHANGED
@@ -37,16 +37,54 @@ module Danger
|
|
37
37
|
expect(issues).to eq(["WEB-125"])
|
38
38
|
end
|
39
39
|
|
40
|
+
it "can find jira issues via branch name" do
|
41
|
+
allow(@jira).to receive_message_chain("github.branch_for_head").and_return("bugfix/WEB-126")
|
42
|
+
issues = @jira.find_jira_issues(
|
43
|
+
key: "WEB",
|
44
|
+
search_title: false,
|
45
|
+
search_commits: false,
|
46
|
+
search_branch: true
|
47
|
+
)
|
48
|
+
expect(issues).to eq(["WEB-126"])
|
49
|
+
end
|
50
|
+
|
40
51
|
it "can find jira issues in pr body" do
|
41
52
|
allow(@jira).to receive_message_chain("github.pr_body").and_return("[WEB-126]")
|
42
53
|
issues = @jira.find_jira_issues(
|
43
54
|
key: "WEB",
|
44
55
|
search_title: false,
|
45
|
-
search_commits: false
|
56
|
+
search_commits: false,
|
57
|
+
search_branch: false,
|
58
|
+
search_body: true
|
46
59
|
)
|
47
60
|
expect(issues).to eq(["WEB-126"])
|
48
61
|
end
|
49
62
|
|
63
|
+
it "outputs error message for title" do
|
64
|
+
error_string = @jira.error_message_for(true, false, false, false)
|
65
|
+
expect(error_string).to eq("This PR does not contain any JIRA issue keys in the PR title (e.g. KEY-123)")
|
66
|
+
end
|
67
|
+
|
68
|
+
it "outputs error message for title, commits" do
|
69
|
+
error_string = @jira.error_message_for(true, true, false, false)
|
70
|
+
expect(error_string).to eq("This PR does not contain any JIRA issue keys in the PR title, commit messages (e.g. KEY-123)")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "outputs error message for title, commits, branch" do
|
74
|
+
error_string = @jira.error_message_for(true, true, true, false)
|
75
|
+
expect(error_string).to eq("This PR does not contain any JIRA issue keys in the PR title, commit messages, branch name (e.g. KEY-123)")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "outputs error message for title, commits, branch, body" do
|
79
|
+
error_string = @jira.error_message_for(true, true, true, true)
|
80
|
+
expect(error_string).to eq("This PR does not contain any JIRA issue keys in the PR title, commit messages, branch name, body (e.g. KEY-123)")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "outputs error message for title, branch" do
|
84
|
+
error_string = @jira.error_message_for(true, false, true, false)
|
85
|
+
expect(error_string).to eq("This PR does not contain any JIRA issue keys in the PR title, branch name (e.g. KEY-123)")
|
86
|
+
end
|
87
|
+
|
50
88
|
it "can find no-jira in pr body" do
|
51
89
|
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
90
|
result = @jira.should_skip_jira?(search_title: false)
|
@@ -59,6 +97,32 @@ module Danger
|
|
59
97
|
expect(result).to be(true)
|
60
98
|
end
|
61
99
|
|
100
|
+
it "can find no-jira in branch name" do
|
101
|
+
allow(@jira).to receive_message_chain("github.pr_body").and_return("")
|
102
|
+
allow(@jira).to receive_message_chain("github.branch_for_head").and_return("feat/no-jira/somefeature")
|
103
|
+
result = @jira.should_skip_jira?(search_title: false)
|
104
|
+
expect(result).to be(true)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "can find nojira in pr body" do
|
108
|
+
allow(@jira).to receive_message_chain("github.pr_body").and_return("[nojira] Ticket doesn't need a jira but [WEB-123] WEB-123")
|
109
|
+
result = @jira.should_skip_jira?(search_title: false)
|
110
|
+
expect(result).to be(true)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "can find nojira in title" do
|
114
|
+
allow(@jira).to receive_message_chain("github.pr_title").and_return("[nojira] Ticket doesn't need jira but [WEB-123] and WEB-123")
|
115
|
+
result = @jira.should_skip_jira?
|
116
|
+
expect(result).to be(true)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "can find nojira in branch name" do
|
120
|
+
allow(@jira).to receive_message_chain("github.pr_body").and_return("")
|
121
|
+
allow(@jira).to receive_message_chain("github.branch_for_head").and_return("feat/nojira/somefeature")
|
122
|
+
result = @jira.should_skip_jira?(search_title: false)
|
123
|
+
expect(result).to be(true)
|
124
|
+
end
|
125
|
+
|
62
126
|
it "can remove duplicates" do
|
63
127
|
allow(@jira).to receive_message_chain("github.pr_title").and_return("Ticket [WEB-123] and WEB-123")
|
64
128
|
issues = @jira.find_jira_issues(key: "WEB")
|
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
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RestlessThinker
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.4'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,7 +176,7 @@ homepage: https://github.com/RestlessThinker/danger-jira
|
|
176
176
|
licenses:
|
177
177
|
- MIT
|
178
178
|
metadata: {}
|
179
|
-
post_install_message:
|
179
|
+
post_install_message:
|
180
180
|
rdoc_options: []
|
181
181
|
require_paths:
|
182
182
|
- lib
|
@@ -191,9 +191,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
191
|
- !ruby/object:Gem::Version
|
192
192
|
version: '0'
|
193
193
|
requirements: []
|
194
|
-
|
195
|
-
|
196
|
-
signing_key:
|
194
|
+
rubygems_version: 3.4.10
|
195
|
+
signing_key:
|
197
196
|
specification_version: 4
|
198
197
|
summary: A Danger plugin to link JIRA issues to a pull request.
|
199
198
|
test_files:
|