danger-jira_issue_links 0.1.1 → 0.2.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 +4 -4
- data/.rspec +3 -0
- data/Gemfile.lock +11 -11
- data/README.md +6 -0
- data/lib/jira_issue_links/gem_version.rb +1 -1
- data/lib/jira_issue_links/plugin.rb +53 -25
- data/spec/jira_issue_links_spec.rb +72 -4
- data/spec/spec_helper.rb +5 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7e7df6fd19328c5200bca36fec3455702a803160
|
|
4
|
+
data.tar.gz: 7bf77af3efcb8d63e3660b397a0b208644df16d7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ddf477f291da157017bc91cd00d216bce118e79af1b004c7b49e3f6daa7dcd0bffab9f356d3f13fc778b9061c4e7aec0113f8ec538632c383103a2f5505c8890
|
|
7
|
+
data.tar.gz: 17372b48036608c53097dcd0cb7217f7e2c073f2c70dcd532e6d8f14bebf1d510eb94238cd653347b27171050a65fe31565cf73d7e01e9e13855d8f7fb853a97
|
data/.rspec
ADDED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
danger-jira_issue_links (0.1.
|
|
4
|
+
danger-jira_issue_links (0.1.1)
|
|
5
5
|
danger-plugin-api (~> 1.0)
|
|
6
6
|
jira-ruby (~> 1.1)
|
|
7
7
|
|
|
@@ -13,7 +13,7 @@ GEM
|
|
|
13
13
|
i18n (>= 0.7, < 2)
|
|
14
14
|
minitest (~> 5.1)
|
|
15
15
|
tzinfo (~> 1.1)
|
|
16
|
-
addressable (2.
|
|
16
|
+
addressable (2.6.0)
|
|
17
17
|
public_suffix (>= 2.0.2, < 4.0)
|
|
18
18
|
ast (2.4.0)
|
|
19
19
|
claide (1.0.2)
|
|
@@ -26,13 +26,13 @@ GEM
|
|
|
26
26
|
concurrent-ruby (1.1.5)
|
|
27
27
|
cork (0.3.0)
|
|
28
28
|
colored2 (~> 3.1)
|
|
29
|
-
danger (6.0.
|
|
29
|
+
danger (6.0.9)
|
|
30
30
|
claide (~> 1.0)
|
|
31
31
|
claide-plugins (>= 0.9.2)
|
|
32
32
|
colored2 (~> 3.1)
|
|
33
33
|
cork (~> 0.1)
|
|
34
34
|
faraday (~> 0.9)
|
|
35
|
-
faraday-http-cache (~>
|
|
35
|
+
faraday-http-cache (~> 2.0)
|
|
36
36
|
git (~> 1.5)
|
|
37
37
|
kramdown (~> 2.0)
|
|
38
38
|
kramdown-parser-gfm (~> 1.0)
|
|
@@ -44,7 +44,7 @@ GEM
|
|
|
44
44
|
diff-lcs (1.3)
|
|
45
45
|
faraday (0.15.4)
|
|
46
46
|
multipart-post (>= 1.2, < 3)
|
|
47
|
-
faraday-http-cache (
|
|
47
|
+
faraday-http-cache (2.0.0)
|
|
48
48
|
faraday (~> 0.8)
|
|
49
49
|
ffi (1.10.0)
|
|
50
50
|
formatador (0.2.5)
|
|
@@ -71,7 +71,7 @@ GEM
|
|
|
71
71
|
multipart-post
|
|
72
72
|
oauth (~> 0.5, >= 0.5.0)
|
|
73
73
|
kramdown (2.1.0)
|
|
74
|
-
kramdown-parser-gfm (1.0
|
|
74
|
+
kramdown-parser-gfm (1.1.0)
|
|
75
75
|
kramdown (~> 2.0)
|
|
76
76
|
listen (3.0.7)
|
|
77
77
|
rb-fsevent (>= 0.9.3)
|
|
@@ -79,7 +79,7 @@ GEM
|
|
|
79
79
|
lumberjack (1.0.13)
|
|
80
80
|
method_source (0.9.2)
|
|
81
81
|
minitest (5.11.3)
|
|
82
|
-
multipart-post (2.
|
|
82
|
+
multipart-post (2.1.1)
|
|
83
83
|
nap (1.1.0)
|
|
84
84
|
nenv (0.3.0)
|
|
85
85
|
no_proxy_fix (0.1.2)
|
|
@@ -97,7 +97,7 @@ GEM
|
|
|
97
97
|
coderay (~> 1.1.0)
|
|
98
98
|
method_source (~> 0.9.0)
|
|
99
99
|
psych (3.1.0)
|
|
100
|
-
public_suffix (3.0
|
|
100
|
+
public_suffix (3.1.0)
|
|
101
101
|
rainbow (3.0.0)
|
|
102
102
|
rake (10.5.0)
|
|
103
103
|
rb-fsevent (0.10.3)
|
|
@@ -125,9 +125,9 @@ GEM
|
|
|
125
125
|
ruby-progressbar (~> 1.7)
|
|
126
126
|
unicode-display_width (>= 1.4.0, < 1.6)
|
|
127
127
|
ruby-progressbar (1.10.0)
|
|
128
|
-
sawyer (0.8.
|
|
129
|
-
addressable (>= 2.3.5
|
|
130
|
-
faraday (
|
|
128
|
+
sawyer (0.8.2)
|
|
129
|
+
addressable (>= 2.3.5)
|
|
130
|
+
faraday (> 0.8, < 2.0)
|
|
131
131
|
shellany (0.0.1)
|
|
132
132
|
terminal-table (1.8.0)
|
|
133
133
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
data/README.md
CHANGED
|
@@ -33,6 +33,12 @@ jira_issue_links.jira_password = "password"
|
|
|
33
33
|
jira_issue_links.jira_site = "https://your-company.atlassian.net"
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
Option to include in output report phrase `Resolves TASK-123`, it help GitLab Jira plugin automatically close issues (see: [GitLab Jira integration](https://docs.gitlab.com/ee/user/project/integrations/jira.html#closing-jira-issues)).
|
|
37
|
+
```
|
|
38
|
+
jira_issue_links.include_resolves_keyword = true
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
|
|
36
42
|
Find all issue mentions in commit messages, obtain info from Jira and make table of links
|
|
37
43
|
```
|
|
38
44
|
jira_issue_links.print_links_with_titles
|
|
@@ -18,6 +18,9 @@ module Danger
|
|
|
18
18
|
#
|
|
19
19
|
class DangerJiraIssueLinks < Plugin
|
|
20
20
|
|
|
21
|
+
# Private struct
|
|
22
|
+
JiraIssue = Struct.new("JiraIssue", :id, :summary, :issuetype, :iconUrl)
|
|
23
|
+
|
|
21
24
|
# Jira username
|
|
22
25
|
#
|
|
23
26
|
# @return [String]
|
|
@@ -39,19 +42,21 @@ module Danger
|
|
|
39
42
|
# @return [String]
|
|
40
43
|
attr_accessor :jira_context_path
|
|
41
44
|
|
|
45
|
+
# If `true` then in report will be added "Resolves" keyword for automatic resolve issue in jira.
|
|
46
|
+
# @see https://docs.gitlab.com/ee/user/project/integrations/jira.html
|
|
47
|
+
# Default - false
|
|
48
|
+
#
|
|
49
|
+
# @return [Bool]
|
|
50
|
+
attr_accessor :include_resolves_keyword
|
|
42
51
|
|
|
43
52
|
# Find all issue references in commit messages.
|
|
44
53
|
# Message should starts with pattern: `[TASK-123]`
|
|
45
54
|
# @return [Array<String>]
|
|
46
55
|
def collect_issues_from_commits
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
all_issues.push(captures[0])
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
all_issues.uniq
|
|
56
|
+
git.commits
|
|
57
|
+
.flat_map { |c| c.message.match(/^\[(\w+-\d+)\]/)&.captures }
|
|
58
|
+
.compact
|
|
59
|
+
.uniq
|
|
55
60
|
end
|
|
56
61
|
|
|
57
62
|
# Generates a `markdown` table of issues with type, title and link.
|
|
@@ -62,27 +67,26 @@ module Danger
|
|
|
62
67
|
found_issues = collect_issues_from_commits
|
|
63
68
|
return if found_issues.empty?
|
|
64
69
|
|
|
65
|
-
jira_context_path = '' if jira_context_path.nil?
|
|
66
|
-
client = JIRA::Client.new(
|
|
67
|
-
username: jira_username,
|
|
68
|
-
password: jira_password,
|
|
69
|
-
site: jira_site,
|
|
70
|
-
context_path: jira_context_path,
|
|
71
|
-
auth_type: :basic
|
|
72
|
-
)
|
|
73
|
-
|
|
74
70
|
message = "## Jira issues\n\n"
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
if include_resolves_keyword
|
|
72
|
+
message << "| | | |\n"
|
|
73
|
+
message << "| --- | --- | ----- |\n"
|
|
74
|
+
else
|
|
75
|
+
message << "| | |\n"
|
|
76
|
+
message << "| --- | ----- |\n"
|
|
77
|
+
end
|
|
77
78
|
|
|
78
79
|
begin
|
|
79
80
|
found_issues.each do |issue_id|
|
|
80
|
-
issue =
|
|
81
|
+
issue = obtain_issue(issue_id)
|
|
81
82
|
return if issue.nil?
|
|
82
83
|
description = issue.summary
|
|
83
84
|
description = description.gsub(/[<|>\[\]]/) { |bracket| "\\#{bracket}" }
|
|
84
|
-
message << " | "
|
|
86
|
+
if include_resolves_keyword
|
|
87
|
+
message << "Resolves #{issue_id} | "
|
|
88
|
+
end
|
|
89
|
+
message << "[#{description}](#{jira_site}/browse/#{issue_id})\n"
|
|
86
90
|
end
|
|
87
91
|
rescue JIRA::HTTPError => e
|
|
88
92
|
print e.message
|
|
@@ -100,13 +104,37 @@ module Danger
|
|
|
100
104
|
found_issues = collect_issues_from_commits
|
|
101
105
|
return if found_issues.empty?
|
|
102
106
|
|
|
103
|
-
message = "
|
|
104
|
-
found_issues.each do |issue_id|
|
|
105
|
-
|
|
107
|
+
message = "## Jira issues\n\n"
|
|
108
|
+
found_issues.each do |issue_id|
|
|
109
|
+
if include_resolves_keyword
|
|
110
|
+
message << "Resolves "
|
|
111
|
+
end
|
|
112
|
+
message << "[#{issue_id}](#{jira_site}/browse/#{issue_id})\n\n"
|
|
106
113
|
end
|
|
107
114
|
|
|
108
115
|
markdown message
|
|
109
116
|
end
|
|
110
117
|
|
|
118
|
+
|
|
119
|
+
private
|
|
120
|
+
|
|
121
|
+
def jira_client
|
|
122
|
+
jira_context_path = '' if jira_context_path.nil?
|
|
123
|
+
@jira_client = JIRA::Client.new(
|
|
124
|
+
username: jira_username,
|
|
125
|
+
password: jira_password,
|
|
126
|
+
site: jira_site,
|
|
127
|
+
context_path: jira_context_path,
|
|
128
|
+
auth_type: :basic
|
|
129
|
+
) if @jira_client.nil?
|
|
130
|
+
return @jira_client
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def obtain_issue(issue_id)
|
|
134
|
+
issue = jira_client.Issue.jql("ID = '#{issue_id}'").first
|
|
135
|
+
return if issue.nil?
|
|
136
|
+
return JiraIssue.new(issue_id, issue.summary, issue.issuetype.name, issue.issuetype.iconUrl)
|
|
137
|
+
end
|
|
138
|
+
|
|
111
139
|
end
|
|
112
140
|
end
|
|
@@ -2,6 +2,10 @@ require File.expand_path("../spec_helper", __FILE__)
|
|
|
2
2
|
|
|
3
3
|
module Danger
|
|
4
4
|
describe Danger::DangerJiraIssueLinks do
|
|
5
|
+
|
|
6
|
+
# alias
|
|
7
|
+
JiraIssue = Danger::DangerJiraIssueLinks::JiraIssue
|
|
8
|
+
|
|
5
9
|
it "should be a plugin" do
|
|
6
10
|
expect(Danger::DangerJiraIssueLinks.new(nil)).to be_a Danger::Plugin
|
|
7
11
|
end
|
|
@@ -9,16 +13,80 @@ module Danger
|
|
|
9
13
|
describe "with Dangerfile" do
|
|
10
14
|
before do
|
|
11
15
|
@dangerfile = testing_dangerfile
|
|
12
|
-
@
|
|
16
|
+
@plugin = @dangerfile.jira_issue_links
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "collect issues with regex" do
|
|
20
|
+
@plugin.include_resolves_keyword = true
|
|
21
|
+
|
|
22
|
+
commits = [
|
|
23
|
+
"[XX-123] fix it",
|
|
24
|
+
"xxx",
|
|
25
|
+
"[XX-123] fix it",
|
|
26
|
+
"[A-1] fix it, [B-2] df"
|
|
27
|
+
].map do |message|
|
|
28
|
+
instance_double('Commit', message: message)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
expect(@plugin.git).to receive(:commits).and_return(commits)
|
|
32
|
+
expect(@plugin.collect_issues_from_commits).to eql([
|
|
33
|
+
"XX-123", "A-1"
|
|
34
|
+
])
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "print simple links" do
|
|
39
|
+
@plugin.jira_site = "http://site"
|
|
40
|
+
|
|
41
|
+
commits = [
|
|
42
|
+
"[XX-123] fix it"
|
|
43
|
+
].map do |message|
|
|
44
|
+
instance_double('Commit', message: message)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
expect(@plugin.git).to receive(:commits).and_return(commits)
|
|
48
|
+
expect(@plugin.print_links_only)
|
|
49
|
+
output = @plugin.status_report[:markdowns].first
|
|
50
|
+
expect(output.message).to eq("## Jira issues\n\n[XX-123](http://site/browse/XX-123)\n\n")
|
|
13
51
|
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
it "print jira task without resolves" do
|
|
55
|
+
@plugin.jira_site = "http://site"
|
|
14
56
|
|
|
15
|
-
|
|
16
|
-
|
|
57
|
+
commits = [
|
|
58
|
+
"[XX-123] fix it"
|
|
59
|
+
].map do |message|
|
|
60
|
+
instance_double('Commit', message: message)
|
|
61
|
+
end
|
|
17
62
|
|
|
18
|
-
expect(@
|
|
63
|
+
expect(@plugin.git).to receive(:commits).and_return(commits)
|
|
64
|
+
expect(@plugin).to receive(:obtain_issue).and_return(JiraIssue.new("XX-123", "summary", "Task", "url"))
|
|
65
|
+
|
|
66
|
+
expect(@plugin.print_links_with_titles)
|
|
67
|
+
output = @plugin.status_report[:markdowns].first
|
|
68
|
+
expect(output.message).to eq("## Jira issues\n\n| | |\n| --- | ----- |\n | [summary](http://site/browse/XX-123)\n")
|
|
19
69
|
end
|
|
20
70
|
|
|
21
71
|
|
|
72
|
+
it "print jira task with resolves keyword" do
|
|
73
|
+
@plugin.include_resolves_keyword = true
|
|
74
|
+
@plugin.jira_site = "http://site"
|
|
75
|
+
|
|
76
|
+
commits = [
|
|
77
|
+
"[XX-123] fix it"
|
|
78
|
+
].map do |message|
|
|
79
|
+
instance_double('Commit', message: message)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
expect(@plugin.git).to receive(:commits).and_return(commits)
|
|
83
|
+
expect(@plugin).to receive(:obtain_issue).and_return(JiraIssue.new("XX-123", "summary", "Task", "url"))
|
|
84
|
+
|
|
85
|
+
expect(@plugin.print_links_with_titles)
|
|
86
|
+
output = @plugin.status_report[:markdowns].first
|
|
87
|
+
expect(output.message).to eq("## Jira issues\n\n| | | |\n| --- | --- | ----- |\n | Resolves XX-123 | [summary](http://site/browse/XX-123)\n")
|
|
88
|
+
end
|
|
89
|
+
|
|
22
90
|
end
|
|
23
91
|
end
|
|
24
92
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -51,7 +51,11 @@ def testing_env
|
|
|
51
51
|
{
|
|
52
52
|
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
|
|
53
53
|
"DANGER_LOCAL_ONLY" => "true",
|
|
54
|
-
"FL_JIRA_SITE" => "https://redmadrobot.atlassian.net"
|
|
54
|
+
"FL_JIRA_SITE" => "https://redmadrobot.atlassian.net",
|
|
55
|
+
'TRAVIS_PULL_REQUEST' => '800',
|
|
56
|
+
'TRAVIS_REPO_SLUG' => 'artsy/eigen',
|
|
57
|
+
'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
|
|
58
|
+
'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
|
|
55
59
|
}
|
|
56
60
|
end
|
|
57
61
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: danger-jira_issue_links
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Anton Glezman
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-05-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: danger-plugin-api
|
|
@@ -172,6 +172,7 @@ extensions: []
|
|
|
172
172
|
extra_rdoc_files: []
|
|
173
173
|
files:
|
|
174
174
|
- ".gitignore"
|
|
175
|
+
- ".rspec"
|
|
175
176
|
- ".rubocop.yml"
|
|
176
177
|
- ".travis.yml"
|
|
177
178
|
- Gemfile
|