danger-yajp 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/Gemfile.lock +5 -5
- data/README.md +11 -1
- data/danger-yajp.gemspec +1 -1
- data/lib/yajp/gem_version.rb +1 -1
- data/lib/yajp/plugin.rb +54 -3
- data/spec/support/remotelink.json +1 -0
- data/spec/yajp_spec.rb +23 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31fe21c6c47db66193c9bb074710f559b03ea8b8df46abc478712d2d23d0d00d
|
4
|
+
data.tar.gz: 93cc2f58198a219c4a9e758c6e6ed2e36934dff6576b2d3d24ddca3e039e9698
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 278831d0fbef23988cd1fad62d056aab0bb21ce96b33215f6a0222c361c2d1860ecf6267da024a7b7cb7a0a68455e87df272ccc3768e1be8004f8c6b6887c88e
|
7
|
+
data.tar.gz: cc54f2f528a3a4c2a92f96330dad7116f30b667a6558262ffb4eedc07b10a9558490ba798229693fd8e8cc7d9c8331dbcbbd0e48f06cde3996bc2353a9c3418d
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danger-yajp (0.0
|
4
|
+
danger-yajp (0.1.0)
|
5
5
|
danger-plugin-api
|
6
6
|
jira-ruby
|
7
7
|
|
@@ -128,13 +128,13 @@ GEM
|
|
128
128
|
diff-lcs (>= 1.2.0, < 2.0)
|
129
129
|
rspec-support (~> 3.10.0)
|
130
130
|
rspec-support (3.10.0)
|
131
|
-
rubocop (1.
|
131
|
+
rubocop (1.2.0)
|
132
132
|
parallel (~> 1.10)
|
133
133
|
parser (>= 2.7.1.5)
|
134
134
|
rainbow (>= 2.2.2, < 4.0)
|
135
135
|
regexp_parser (>= 1.8)
|
136
136
|
rexml
|
137
|
-
rubocop-ast (>= 0.
|
137
|
+
rubocop-ast (>= 1.0.1)
|
138
138
|
ruby-progressbar (~> 1.7)
|
139
139
|
unicode-display_width (>= 1.4.0, < 2.0)
|
140
140
|
rubocop-ast (1.1.1)
|
@@ -152,7 +152,7 @@ GEM
|
|
152
152
|
tzinfo (1.2.7)
|
153
153
|
thread_safe (~> 0.1)
|
154
154
|
unicode-display_width (1.7.0)
|
155
|
-
webmock (3.9.
|
155
|
+
webmock (3.9.4)
|
156
156
|
addressable (>= 2.3.6)
|
157
157
|
crack (>= 0.3.2)
|
158
158
|
hashdiff (>= 0.4.0, < 2.0.0)
|
@@ -170,7 +170,7 @@ DEPENDENCIES
|
|
170
170
|
pry
|
171
171
|
rake (~> 13.0)
|
172
172
|
rspec (~> 3.9)
|
173
|
-
rubocop (
|
173
|
+
rubocop (>= 1.0.0)
|
174
174
|
webmock (~> 3.9)
|
175
175
|
yard (~> 0.9.11)
|
176
176
|
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Yet Another Jira Plugin
|
2
2
|
|
3
|
-
[![License](
|
3
|
+
[![License](https://img.shields.io/github/license/juliendms/danger-yajp)](LICENSE)
|
4
|
+
[![Gem](https://img.shields.io/gem/v/danger-yajp)](https://rubygems.org/gems/danger-yajp)
|
5
|
+
[![Dependencies](https://img.shields.io/librariesio/release/rubygems/danger-yajp)](https://libraries.io/rubygems/danger-yajp)
|
4
6
|
|
5
7
|
Yet Another Jira Plugin (in short: yajp) is a [Danger](https://danger.systems/ruby/) plugin that provides methods to easily find and manipulate issues from within the Dangerfile. The major difference with the existing Jira plugins is the ability to transition and update issues with the same feeling as manipulating PR data from Danger. This plugin was build in the same mind as Danger, meaning that you will find methods to easily manipulate Jira data, but no predefined warning and/or message.
|
6
8
|
|
@@ -57,6 +59,14 @@ The `transition` method only takes fields available in the transition screen. Us
|
|
57
59
|
|
58
60
|
> Transition IDs can be found in Jira under Project Workflow > Edit Workflow in Text Mode.
|
59
61
|
|
62
|
+
### Reference the PR as a remote link
|
63
|
+
|
64
|
+
yajp can reference the PR as a remote link on Jira. It will use the icon of GitLab or Github depending on what you use. The remote link will use the URL of the PR as a `globalId` to not create duplicates. Optionnaly, you can specify the relationship with the issue (default is `relates to`), and the status, either as an object (eg. `{ "resolved": true, "icon": {...} }`) or as a boolean that will set the value of the property `resolved`. By default, no status is sent.
|
65
|
+
|
66
|
+
```rb
|
67
|
+
jira.pr_as_remotelink(issue, false)
|
68
|
+
```
|
69
|
+
|
60
70
|
### Issue URL
|
61
71
|
|
62
72
|
Use `issue_link` to retrieve the browse URL of the Jira issue.
|
data/danger-yajp.gemspec
CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_development_dependency 'webmock', '~> 3.9'
|
34
34
|
|
35
35
|
# Linting code and docs
|
36
|
-
spec.add_development_dependency 'rubocop', '
|
36
|
+
spec.add_development_dependency 'rubocop', '>= 1.0.0'
|
37
37
|
spec.add_development_dependency 'yard', '~> 0.9.11'
|
38
38
|
|
39
39
|
# Makes testing easy via `bundle exec guard`
|
data/lib/yajp/gem_version.rb
CHANGED
data/lib/yajp/plugin.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'jira-ruby'
|
4
|
+
require 'json'
|
4
5
|
|
5
6
|
module Danger
|
6
7
|
# Yet Another Jira Plugin (in short: yajp) provides methods to easily find and manipulate issues from within the Dangerfile.
|
@@ -69,9 +70,9 @@ module Danger
|
|
69
70
|
# jira.find_issues('KEY', search_title: false, search_branch: true)
|
70
71
|
#
|
71
72
|
# @param [Array<String>] key An array of Jira project keys like `['KEY', 'JIRA']`, or a single `String` with a Jira project key
|
72
|
-
# @param [Boolean] search_title Option to search Jira issues from PR title
|
73
|
-
# @param [Boolean] search_commits Option to search Jira issues from from commit messages
|
74
|
-
# @param [Boolean] search_branch Option to search Jira issues from the name of the PR branch
|
73
|
+
# @param [Boolean] search_title Option to search Jira issues from PR title
|
74
|
+
# @param [Boolean] search_commits Option to search Jira issues from from commit messages
|
75
|
+
# @param [Boolean] search_branch Option to search Jira issues from the name of the PR branch
|
75
76
|
#
|
76
77
|
# @return [Array<JIRA::Issue>] An array containing all the unique issues found in the PR.
|
77
78
|
#
|
@@ -184,10 +185,40 @@ module Danger
|
|
184
185
|
# @param [JIRA::Issue] issue
|
185
186
|
#
|
186
187
|
# @return [String] the URL of the issue
|
188
|
+
#
|
187
189
|
def issue_link(issue)
|
188
190
|
"#{ENV['DANGER_JIRA_URL']}/browse/#{issue.key}"
|
189
191
|
end
|
190
192
|
|
193
|
+
# Add a remote link to the PR in the given Jira issues. It uses the link of the PR as the `globalId` of the remote link, thus avoiding to create duplicates each time the PR is updated.
|
194
|
+
#
|
195
|
+
# @param [Array<JIRA::Issue>] issue An array of issues, or a single `JIRA::Issue`
|
196
|
+
# @param [<String>] relation Option to set the relationship of the remote link
|
197
|
+
# @param [<Hash>] status Option to set the status property of the remote link, it can be <Hash> or a <Boolean> that will set the value of the property `resolved`
|
198
|
+
#
|
199
|
+
# @return [Boolean] `true` if all the remote links were added successfully, `false` otherwise.
|
200
|
+
#
|
201
|
+
def pr_as_remotelink(issue, relation: 'relates to', status: nil)
|
202
|
+
issues = issue.kind_of?(Array) ? issue : [] << issue
|
203
|
+
result = true
|
204
|
+
|
205
|
+
remote_link_prop = { object: { url: pr_link, title: vcs_host.pr_title, icon: link_icon } }
|
206
|
+
remote_link_prop[:globalId] = pr_link
|
207
|
+
remote_link_prop[:relationship] = relation
|
208
|
+
|
209
|
+
if status.kind_of?(Hash)
|
210
|
+
remote_link_prop[:object][:status] = status
|
211
|
+
elsif !status.nil?
|
212
|
+
remote_link_prop[:object][:status] = { resolved: status }
|
213
|
+
end
|
214
|
+
|
215
|
+
issues.each do |key|
|
216
|
+
result &= key.remotelink.build.save(remote_link_prop)
|
217
|
+
end
|
218
|
+
|
219
|
+
return result
|
220
|
+
end
|
221
|
+
|
191
222
|
private
|
192
223
|
|
193
224
|
def vcs_host
|
@@ -196,6 +227,26 @@ module Danger
|
|
196
227
|
github
|
197
228
|
end
|
198
229
|
|
230
|
+
def pr_link
|
231
|
+
return @pr_link unless @pr_link.nil?
|
232
|
+
|
233
|
+
pr_hash = JSON.parse(vcs_host.pr_json, symbolize_names: true)
|
234
|
+
|
235
|
+
if defined? @dangerfile.gitlab
|
236
|
+
@pr_link = pr_hash[:web_url]
|
237
|
+
else
|
238
|
+
@pr_link = pr_hash[:html_url]
|
239
|
+
end
|
240
|
+
|
241
|
+
return @pr_link
|
242
|
+
end
|
243
|
+
|
244
|
+
def link_icon
|
245
|
+
return { title: 'Gitlab', url16x16: 'https://gitlab.com/favicon.ico' } if defined? @dangerfile.gitlab
|
246
|
+
|
247
|
+
{ title: 'Github', url16x16: 'https://github.com/favicon.ico' }
|
248
|
+
end
|
249
|
+
|
199
250
|
def build_regexp_from_key(key)
|
200
251
|
keys = key.kind_of?(Array) ? key.join('|') : key
|
201
252
|
return /((?:#{keys})-[0-9]+)/
|
@@ -0,0 +1 @@
|
|
1
|
+
{"object":{"url":"https://github.com/test/pull/1234","title":"PR Title","icon":{"title":"Github","url16x16":"https://github.com/favicon.ico"},"status":{"resolved":true}},"globalId":"https://github.com/test/pull/1234","relationship":"relates to"}
|
data/spec/yajp_spec.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative 'spec_helper'
|
4
4
|
|
5
|
+
# rubocop:disable Metrics/ModuleLength
|
5
6
|
module Danger
|
6
7
|
describe Danger::DangerYajp do
|
7
8
|
before do
|
@@ -72,6 +73,7 @@ module Danger
|
|
72
73
|
expect(issues).to eq(['WEB-128', 'WEB-129'])
|
73
74
|
end
|
74
75
|
|
76
|
+
# rubocop:disable Naming/VariableNumber
|
75
77
|
it 'can split transition field from other fields' do
|
76
78
|
json = File.read("#{File.dirname(__FILE__)}/support/transitions.all.json")
|
77
79
|
url = "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/WEB-130/transitions"
|
@@ -116,6 +118,27 @@ module Danger
|
|
116
118
|
expect(stub).to have_been_requested.twice
|
117
119
|
expect(result).to be true
|
118
120
|
end
|
121
|
+
# rubocop:enable Naming/VariableNumber
|
122
|
+
|
123
|
+
it 'can add remote link' do
|
124
|
+
pr_title = 'PR Title'
|
125
|
+
pr_json = '{"html_url":"https://github.com/test/pull/1234"}'
|
126
|
+
url = "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/WEB-134/remotelink"
|
127
|
+
json = File.read("#{File.dirname(__FILE__)}/support/remotelink.json")
|
128
|
+
issue = plugin.api.Issue.build
|
129
|
+
|
130
|
+
allow(issue).to receive(:key_value).and_return('WEB-134')
|
131
|
+
allow(dangerfile.github).to receive(:pr_json).and_return(pr_json)
|
132
|
+
allow(dangerfile.github).to receive(:pr_title).and_return(pr_title)
|
133
|
+
|
134
|
+
stub = stub_request(:post, url).
|
135
|
+
with(body: json)
|
136
|
+
result = plugin.pr_as_remotelink(issue, status: true)
|
137
|
+
|
138
|
+
expect(stub).to have_been_requested.once
|
139
|
+
expect(result).to be true
|
140
|
+
end
|
119
141
|
end
|
120
142
|
end
|
121
143
|
end
|
144
|
+
# rubocop:enable Metrics/ModuleLength
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-yajp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- juliendms
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -98,14 +98,14 @@ dependencies:
|
|
98
98
|
name: rubocop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: 1.0.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 1.0.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- lib/yajp/gem_version.rb
|
188
188
|
- lib/yajp/plugin.rb
|
189
189
|
- spec/spec_helper.rb
|
190
|
+
- spec/support/remotelink.json
|
190
191
|
- spec/support/transitions.all.json
|
191
192
|
- spec/yajp_spec.rb
|
192
193
|
homepage: https://github.com/juliendms/danger-yajp
|
@@ -215,5 +216,6 @@ summary: Yet Another Jira Plugin is a danger plugin to find issues, access their
|
|
215
216
|
and perform operations on them.
|
216
217
|
test_files:
|
217
218
|
- spec/spec_helper.rb
|
219
|
+
- spec/support/remotelink.json
|
218
220
|
- spec/support/transitions.all.json
|
219
221
|
- spec/yajp_spec.rb
|