danger-yajp 0.1.0 → 1.0.1
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/.github/workflows/create-tag.yml +39 -0
- data/Gemfile.lock +55 -54
- data/README.md +20 -14
- data/danger-yajp.gemspec +4 -4
- data/lib/yajp/gem_version.rb +1 -1
- data/lib/yajp/issue.rb +70 -0
- data/lib/yajp/plugin.rb +29 -43
- data/spec/yajp_spec.rb +17 -15
- metadata +14 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2868f707abb91adf4aac75dbc2c882083fdee0851e7abb37fc90b939ae7c944e
|
4
|
+
data.tar.gz: fce1af4f4cd6cfa8fb3b0be1f36d5d507f86b8d43a45c78203078a2120572c65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edc00b2e66a419e4408f36b3238dc57e59189a0ad63eabaf2d3a13be41f0da26041313ffc4b050118b19ab014324ef6b360f3ee4ee11f29fc5adb64870044df3
|
7
|
+
data.tar.gz: 2e5273d151a6b9ced079a5b2dabbbf5e370a04a7250232f76095aeb3c2942a8d49c97b46669079d5c9019aa6cb388dc8dc22139ce620011c83e153246071e7dd
|
@@ -0,0 +1,39 @@
|
|
1
|
+
name: Create release
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: main
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
name: Retrieve version + create release
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
with:
|
15
|
+
fetch-depth: 0
|
16
|
+
|
17
|
+
- name: Set up Ruby 2.6
|
18
|
+
uses: actions/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 2.6.x
|
21
|
+
|
22
|
+
- name: Retrieve version
|
23
|
+
id: version
|
24
|
+
run: |
|
25
|
+
version=$(ruby -e 'require "./lib/yajp/gem_version.rb"' -e 'puts Yajp::VERSION')
|
26
|
+
echo "TAG_NAME=$version" >> $GITHUB_ENV
|
27
|
+
latest_tag=$(git describe --tags --abbrev=0)
|
28
|
+
echo 'VERSION_DESCRIPTION<<EOF' >> $GITHUB_ENV
|
29
|
+
git log --pretty='format:%h %s' ${latest_tag}..HEAD >> $GITHUB_ENV
|
30
|
+
echo $'\nEOF' >> $GITHUB_ENV
|
31
|
+
|
32
|
+
- name: Create release
|
33
|
+
uses: actions/create-release@v1
|
34
|
+
env:
|
35
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
36
|
+
with:
|
37
|
+
tag_name: ${{ env.TAG_NAME }}
|
38
|
+
release_name: v${{ env.TAG_NAME }}
|
39
|
+
body: ${{ env.VERSION_DESCRIPTION }}
|
data/Gemfile.lock
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danger-yajp (
|
4
|
+
danger-yajp (1.0.0)
|
5
5
|
danger-plugin-api
|
6
6
|
jira-ruby
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (6.
|
11
|
+
activesupport (6.1.3.1)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
-
i18n (>=
|
14
|
-
minitest (
|
15
|
-
tzinfo (~>
|
16
|
-
zeitwerk (~> 2.
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
zeitwerk (~> 2.3)
|
17
17
|
addressable (2.7.0)
|
18
18
|
public_suffix (>= 2.0.2, < 5.0)
|
19
|
-
ast (2.4.
|
19
|
+
ast (2.4.2)
|
20
20
|
atlassian-jwt (0.2.0)
|
21
21
|
jwt (~> 2.1.0)
|
22
22
|
claide (1.0.3)
|
@@ -26,11 +26,12 @@ GEM
|
|
26
26
|
open4 (~> 1.3)
|
27
27
|
coderay (1.1.3)
|
28
28
|
colored2 (3.1.2)
|
29
|
-
concurrent-ruby (1.1.
|
29
|
+
concurrent-ruby (1.1.8)
|
30
30
|
cork (0.3.0)
|
31
31
|
colored2 (~> 3.1)
|
32
|
-
crack (0.4.
|
33
|
-
|
32
|
+
crack (0.4.5)
|
33
|
+
rexml
|
34
|
+
danger (8.2.3)
|
34
35
|
claide (~> 1.0)
|
35
36
|
claide-plugins (>= 0.9.2)
|
36
37
|
colored2 (~> 3.1)
|
@@ -42,18 +43,20 @@ GEM
|
|
42
43
|
kramdown-parser-gfm (~> 1.0)
|
43
44
|
no_proxy_fix
|
44
45
|
octokit (~> 4.7)
|
45
|
-
terminal-table (
|
46
|
+
terminal-table (>= 1, < 4)
|
46
47
|
danger-plugin-api (1.0.0)
|
47
48
|
danger (> 2.0)
|
48
49
|
diff-lcs (1.4.4)
|
49
|
-
faraday (1.
|
50
|
+
faraday (1.3.0)
|
51
|
+
faraday-net_http (~> 1.0)
|
50
52
|
multipart-post (>= 1.2, < 3)
|
51
53
|
ruby2_keywords
|
52
54
|
faraday-http-cache (2.2.0)
|
53
55
|
faraday (>= 0.8)
|
54
|
-
|
56
|
+
faraday-net_http (1.0.1)
|
57
|
+
ffi (1.15.0-x64-mingw32)
|
55
58
|
formatador (0.2.5)
|
56
|
-
git (1.
|
59
|
+
git (1.8.1)
|
57
60
|
rchardet (~> 1.8)
|
58
61
|
guard (2.16.2)
|
59
62
|
formatador (>= 0.2.4)
|
@@ -70,24 +73,24 @@ GEM
|
|
70
73
|
guard-compat (~> 1.1)
|
71
74
|
rspec (>= 2.99.0, < 4.0)
|
72
75
|
hashdiff (1.0.1)
|
73
|
-
i18n (1.8.
|
76
|
+
i18n (1.8.10)
|
74
77
|
concurrent-ruby (~> 1.0)
|
75
|
-
jira-ruby (2.1.
|
78
|
+
jira-ruby (2.1.5)
|
76
79
|
activesupport
|
77
80
|
atlassian-jwt
|
78
81
|
multipart-post
|
79
82
|
oauth (~> 0.5, >= 0.5.0)
|
80
83
|
jwt (2.1.0)
|
81
|
-
kramdown (2.3.
|
84
|
+
kramdown (2.3.1)
|
82
85
|
rexml
|
83
86
|
kramdown-parser-gfm (1.1.0)
|
84
87
|
kramdown (~> 2.0)
|
85
|
-
listen (3.
|
88
|
+
listen (3.5.1)
|
86
89
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
87
90
|
rb-inotify (~> 0.9, >= 0.9.10)
|
88
91
|
lumberjack (1.2.8)
|
89
92
|
method_source (1.0.0)
|
90
|
-
minitest (5.14.
|
93
|
+
minitest (5.14.4)
|
91
94
|
multipart-post (2.1.1)
|
92
95
|
nap (1.1.0)
|
93
96
|
nenv (0.3.0)
|
@@ -95,69 +98,67 @@ GEM
|
|
95
98
|
notiffany (0.1.3)
|
96
99
|
nenv (~> 0.1)
|
97
100
|
shellany (~> 0.0)
|
98
|
-
oauth (0.5.
|
99
|
-
octokit (4.
|
101
|
+
oauth (0.5.6)
|
102
|
+
octokit (4.20.0)
|
100
103
|
faraday (>= 0.9)
|
101
104
|
sawyer (~> 0.8.0, >= 0.5.3)
|
102
105
|
open4 (1.3.4)
|
103
|
-
parallel (1.
|
104
|
-
parser (
|
106
|
+
parallel (1.20.1)
|
107
|
+
parser (3.0.1.0)
|
105
108
|
ast (~> 2.4.1)
|
106
|
-
pry (0.
|
109
|
+
pry (0.14.0)
|
107
110
|
coderay (~> 1.1)
|
108
111
|
method_source (~> 1.0)
|
109
112
|
public_suffix (4.0.6)
|
110
113
|
rainbow (3.0.0)
|
111
|
-
rake (13.0.
|
114
|
+
rake (13.0.3)
|
112
115
|
rb-fsevent (0.10.4)
|
113
116
|
rb-inotify (0.10.1)
|
114
117
|
ffi (~> 1.0)
|
115
118
|
rchardet (1.8.0)
|
116
|
-
regexp_parser (1.
|
117
|
-
rexml (3.2.
|
119
|
+
regexp_parser (2.1.1)
|
120
|
+
rexml (3.2.5)
|
118
121
|
rspec (3.10.0)
|
119
122
|
rspec-core (~> 3.10.0)
|
120
123
|
rspec-expectations (~> 3.10.0)
|
121
124
|
rspec-mocks (~> 3.10.0)
|
122
|
-
rspec-core (3.10.
|
125
|
+
rspec-core (3.10.1)
|
123
126
|
rspec-support (~> 3.10.0)
|
124
|
-
rspec-expectations (3.10.
|
127
|
+
rspec-expectations (3.10.1)
|
125
128
|
diff-lcs (>= 1.2.0, < 2.0)
|
126
129
|
rspec-support (~> 3.10.0)
|
127
|
-
rspec-mocks (3.10.
|
130
|
+
rspec-mocks (3.10.2)
|
128
131
|
diff-lcs (>= 1.2.0, < 2.0)
|
129
132
|
rspec-support (~> 3.10.0)
|
130
|
-
rspec-support (3.10.
|
131
|
-
rubocop (1.
|
133
|
+
rspec-support (3.10.2)
|
134
|
+
rubocop (1.12.1)
|
132
135
|
parallel (~> 1.10)
|
133
|
-
parser (>=
|
136
|
+
parser (>= 3.0.0.0)
|
134
137
|
rainbow (>= 2.2.2, < 4.0)
|
135
|
-
regexp_parser (>= 1.8)
|
138
|
+
regexp_parser (>= 1.8, < 3.0)
|
136
139
|
rexml
|
137
|
-
rubocop-ast (>= 1.0.
|
140
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
138
141
|
ruby-progressbar (~> 1.7)
|
139
|
-
unicode-display_width (>= 1.4.0, <
|
140
|
-
rubocop-ast (1.
|
142
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
143
|
+
rubocop-ast (1.4.1)
|
141
144
|
parser (>= 2.7.1.5)
|
142
|
-
ruby-progressbar (1.
|
143
|
-
ruby2_keywords (0.0.
|
145
|
+
ruby-progressbar (1.11.0)
|
146
|
+
ruby2_keywords (0.0.4)
|
144
147
|
sawyer (0.8.2)
|
145
148
|
addressable (>= 2.3.5)
|
146
149
|
faraday (> 0.8, < 2.0)
|
147
150
|
shellany (0.0.1)
|
148
|
-
terminal-table (1.
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
unicode-display_width (1.7.0)
|
155
|
-
webmock (3.9.4)
|
151
|
+
terminal-table (1.6.0)
|
152
|
+
thor (1.1.0)
|
153
|
+
tzinfo (2.0.4)
|
154
|
+
concurrent-ruby (~> 1.0)
|
155
|
+
unicode-display_width (2.0.0)
|
156
|
+
webmock (3.12.2)
|
156
157
|
addressable (>= 2.3.6)
|
157
158
|
crack (>= 0.3.2)
|
158
159
|
hashdiff (>= 0.4.0, < 2.0.0)
|
159
|
-
yard (0.9.
|
160
|
-
zeitwerk (2.4.
|
160
|
+
yard (0.9.26)
|
161
|
+
zeitwerk (2.4.2)
|
161
162
|
|
162
163
|
PLATFORMS
|
163
164
|
x64-mingw32
|
@@ -169,10 +170,10 @@ DEPENDENCIES
|
|
169
170
|
guard-rspec (~> 4.7)
|
170
171
|
pry
|
171
172
|
rake (~> 13.0)
|
172
|
-
rspec (~> 3
|
173
|
-
rubocop (
|
174
|
-
webmock (~> 3
|
175
|
-
yard (~> 0.9
|
173
|
+
rspec (~> 3)
|
174
|
+
rubocop (~> 1)
|
175
|
+
webmock (~> 3)
|
176
|
+
yard (~> 0.9)
|
176
177
|
|
177
178
|
BUNDLED WITH
|
178
|
-
2.
|
179
|
+
2.2.3
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[](https://rubygems.org/gems/danger-yajp)
|
5
5
|
[](https://libraries.io/rubygems/danger-yajp)
|
6
6
|
|
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.
|
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. It also does that by expanding the Issue class from `jira-ruby`.
|
8
8
|
|
9
9
|
Inspired by [danger-jira](https://github.com/RestlessThinker/danger-jira), from which I borrowed the issue search, and by [danger-jira_sync](https://github.com/roverdotcom/danger-jira_sync) for their usage of the awesome [jira-ruby](https://github.com/sumoheavy/jira-ruby) gem.
|
10
10
|
|
@@ -18,12 +18,12 @@ gem 'danger-yajp'
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
You first need to define the environment variables `DANGER_JIRA_URL`, `DANGER_JIRA_USER` and `
|
21
|
+
You first need to define the environment variables `DANGER_JIRA_URL`, `DANGER_JIRA_USER` and `DANGER_JIRA_API_TOKEN` in your CI environment, for example:
|
22
22
|
|
23
23
|
```
|
24
24
|
DANGER_JIRA_URL: https://jira.company.com/jira
|
25
25
|
DANGER_JIRA_USER: username
|
26
|
-
|
26
|
+
DANGER_JIRA_API_TOKEN: abcd12345
|
27
27
|
```
|
28
28
|
|
29
29
|
### Find issues
|
@@ -45,17 +45,23 @@ end
|
|
45
45
|
|
46
46
|
### Transition / update issues
|
47
47
|
|
48
|
-
yajp allows to easily transition and update issues without the hassle of building custom json in the Dangerfile. The inputs are:
|
48
|
+
yajp allows to easily transition and update issues without the hassle of building custom json in the Dangerfile. The methods are available in the issue object, or to handle multiple issues in the plugin object. The inputs are:
|
49
49
|
|
50
|
-
*
|
51
|
-
*
|
52
|
-
* Any number of fields to be updated in
|
50
|
+
* For the transition action, the ID or name of the transition (which is not the name of the status)
|
51
|
+
* When using the methods from the plugin object, the issues to handled, which is by default the issues found when the command `find_issues` was last run.
|
52
|
+
* Any number of fields to be updated in a hash: `key: value`
|
53
53
|
|
54
|
+
Example 1: transition all the issues found after running `find_issues`:
|
54
55
|
```rb
|
55
|
-
jira.
|
56
|
+
jira.transition_all('done', assignee: { name: 'username' }, customfield_11005: 'example')
|
56
57
|
```
|
57
58
|
|
58
|
-
|
59
|
+
Example 2: update a single issue:
|
60
|
+
```rb
|
61
|
+
issue.update(assignee: { name: 'username' }, customfield_11005: 'example')
|
62
|
+
```
|
63
|
+
|
64
|
+
The `transition` and `transition_all` methods only take fields available in the transition screen. Use the `split_transition_fields` method to separate the fields available in the transition screen, or use the `transition_and_update_all` method to transition and update issues (and automatically dispatch the fields to the correct action).
|
59
65
|
|
60
66
|
> Transition IDs can be found in Jira under Project Workflow > Edit Workflow in Text Mode.
|
61
67
|
|
@@ -69,10 +75,10 @@ jira.pr_as_remotelink(issue, false)
|
|
69
75
|
|
70
76
|
### Issue URL
|
71
77
|
|
72
|
-
Use `
|
78
|
+
Use `link` to retrieve the browse URL of the Jira issue.
|
73
79
|
|
74
80
|
```rb
|
75
|
-
message "<a href='#{
|
81
|
+
message "<a href='#{issue.link}'>#{issue.key} - #{issue.summary}</a>"
|
76
82
|
```
|
77
83
|
|
78
84
|
### API
|
@@ -92,13 +98,13 @@ if issues.empty?
|
|
92
98
|
warn 'This PR does not contain any Jira issue.'
|
93
99
|
else
|
94
100
|
issues.each do |issue|
|
95
|
-
message "<a href='#{
|
101
|
+
message "<a href='#{issue.link}'>#{issue.key} - #{issue.summary}</a>"
|
96
102
|
|
97
103
|
case issue.status.name
|
98
104
|
when 'In Progress'
|
99
|
-
jira.
|
105
|
+
jira.transition_and_update_all(10, issue: issue, assignee: { name: 'username' }, customfield_11005: 'example')
|
100
106
|
when 'To Do', 'Blocked'
|
101
|
-
warn "Issue <a href='#{
|
107
|
+
warn "Issue <a href='#{issue.link}'>#{issue.key}</a> is not in Dev status, please make sure the issue you're working on is in the correct status"
|
102
108
|
end
|
103
109
|
end
|
104
110
|
end
|
data/danger-yajp.gemspec
CHANGED
@@ -29,12 +29,12 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency 'rake', '~> 13.0'
|
30
30
|
|
31
31
|
# Testing support
|
32
|
-
spec.add_development_dependency 'rspec', '~> 3
|
33
|
-
spec.add_development_dependency 'webmock', '~> 3
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3'
|
33
|
+
spec.add_development_dependency 'webmock', '~> 3'
|
34
34
|
|
35
35
|
# Linting code and docs
|
36
|
-
spec.add_development_dependency 'rubocop', '
|
37
|
-
spec.add_development_dependency 'yard', '~> 0.9
|
36
|
+
spec.add_development_dependency 'rubocop', '~> 1'
|
37
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
38
38
|
|
39
39
|
# Makes testing easy via `bundle exec guard`
|
40
40
|
spec.add_development_dependency 'guard', '~> 2.16'
|
data/lib/yajp/gem_version.rb
CHANGED
data/lib/yajp/issue.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'jira-ruby'
|
4
|
+
|
5
|
+
module Danger
|
6
|
+
# This class extends (aka monkey patch) the `JIRA::Resource::Issue` class with straightforward methods to easily transition and update issues.
|
7
|
+
#
|
8
|
+
class JIRA::Resource::Issue
|
9
|
+
# Get the browse URL of the issue.
|
10
|
+
#
|
11
|
+
# @return [String] the URL of the issue
|
12
|
+
#
|
13
|
+
def link
|
14
|
+
"#{ENV['DANGER_JIRA_URL']}/browse/#{key}"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Update the issue.
|
18
|
+
#
|
19
|
+
# @example Update the fields `assignee` and `customfield_11005`
|
20
|
+
# issue.update(assignee: { name: 'username' }, customfield_11005: 'example')
|
21
|
+
#
|
22
|
+
# @param [Hash] fields Fields to update
|
23
|
+
#
|
24
|
+
# @return [Boolean] `true` if the issue was updated successfully, `false` otherwise.
|
25
|
+
#
|
26
|
+
def update(**fields)
|
27
|
+
return if fields.empty?
|
28
|
+
|
29
|
+
save({ fields: fields })
|
30
|
+
end
|
31
|
+
|
32
|
+
# Transition the issue using the ID or name of the transition. Transition IDs can be found in Jira under Project Workflow > Edit Workflow in Text Mode.
|
33
|
+
# The transition name is the text that appears on the issue screen to transition it.
|
34
|
+
# The fields that can be updated with this method are only the fields available in the transition screen of the transition. Otherwise use `transition_and_update`.
|
35
|
+
#
|
36
|
+
# @example Transition the issue and set the fields `assignee` and `customfield_11005` available on the transition screens
|
37
|
+
# jira.transition(my_issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
|
38
|
+
#
|
39
|
+
# @param [Integer, String] transition_id ID or name of the transition
|
40
|
+
# @param [Hash] fields Fields that can be updated on the transition screen
|
41
|
+
#
|
42
|
+
# @return [Boolean] `true` if the issue was transitioned successfully, `false` otherwise.
|
43
|
+
#
|
44
|
+
def transition(transition_id, **fields)
|
45
|
+
if transition_id.kind_of?(String)
|
46
|
+
transition_id = get_transition_id(transition_id)
|
47
|
+
|
48
|
+
return false if transition_id == -1
|
49
|
+
end
|
50
|
+
data = { transition: { id: transition_id.to_s } }
|
51
|
+
data[:fields] = fields unless fields.empty?
|
52
|
+
|
53
|
+
transitions.build.save(data)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Retrieve the ID of the transition matching the given name.
|
57
|
+
#
|
58
|
+
# @param [String] name
|
59
|
+
#
|
60
|
+
# @return [Integer] the ID of the transition, or -1 if no match was found
|
61
|
+
#
|
62
|
+
def get_transition_id(name)
|
63
|
+
transitions.all.each do |transition|
|
64
|
+
return transition.id if transition.name.casecmp?(name)
|
65
|
+
end
|
66
|
+
|
67
|
+
return -1
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/yajp/plugin.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require 'json'
|
3
|
+
require_relative 'issue'
|
5
4
|
|
6
5
|
module Danger
|
7
6
|
# Yet Another Jira Plugin (in short: yajp) provides methods to easily find and manipulate issues from within the Dangerfile.
|
@@ -19,13 +18,13 @@ module Danger
|
|
19
18
|
# warn 'This PR does not contain any Jira issue.'
|
20
19
|
# else
|
21
20
|
# issues.each do |issue|
|
22
|
-
# message "<a href='#{
|
21
|
+
# message "<a href='#{issue.link}'>#{issue.key} - #{issue.summary}</a>"
|
23
22
|
#
|
24
23
|
# case issue.status.name
|
25
24
|
# when 'In Progress'
|
26
|
-
#
|
25
|
+
# issue.transition(10, assignee: { name: 'username' }, customfield_11005: 'example')
|
27
26
|
# when 'To Do', 'Blocked'
|
28
|
-
# warn "Issue <a href='#{
|
27
|
+
# warn "Issue <a href='#{issue.link}'>#{issue.key}</a> is not in Dev status, please make sure the issue you're working on is in the correct status"
|
29
28
|
# end
|
30
29
|
# end
|
31
30
|
# end
|
@@ -74,7 +73,7 @@ module Danger
|
|
74
73
|
# @param [Boolean] search_commits Option to search Jira issues from from commit messages
|
75
74
|
# @param [Boolean] search_branch Option to search Jira issues from the name of the PR branch
|
76
75
|
#
|
77
|
-
# @return [Array<JIRA::Issue>] An array containing all the unique issues found in the PR.
|
76
|
+
# @return [Array<JIRA::Resource::Issue>] An array containing all the unique issues found in the PR.
|
78
77
|
#
|
79
78
|
def find_issues(key, search_title: true, search_commits: false, search_branch: false)
|
80
79
|
regexp = build_regexp_from_key(key)
|
@@ -85,29 +84,28 @@ module Danger
|
|
85
84
|
jira_issues.concat(search_branch(regexp)) if search_branch
|
86
85
|
jira_issues.concat(search_pr_body(regexp)) if jira_issues.empty?
|
87
86
|
|
88
|
-
jira_issues.uniq.map { |issue_key| @api.Issue.find(issue_key) }
|
87
|
+
@issues = jira_issues.uniq(&:downcase).map { |issue_key| @api.Issue.find(issue_key) }
|
89
88
|
end
|
90
89
|
|
91
|
-
# Transition the given Jira issue(s) using the ID of the transition. Transition IDs can be found in Jira under Project Workflow > Edit Workflow in Text Mode.
|
90
|
+
# Transition the given Jira issue(s) using the ID or name of the transition. Transition IDs can be found in Jira under Project Workflow > Edit Workflow in Text Mode.
|
91
|
+
# The transition name is the text that appears on the issue screen to transition it.
|
92
92
|
# The fields that can be updated with this method are only the fields available in the transition screen of the transition. Otherwise use `transition_and_update`.
|
93
93
|
#
|
94
|
-
# @example Transition the issue `my_issue` and set the fields `assignee` and `customfield_11005` available on the transition screens
|
95
|
-
# jira.
|
94
|
+
# @example Transition the issue `my_issue` using the transition 'done' and set the fields `assignee` and `customfield_11005` available on the transition screens
|
95
|
+
# jira.transition_all(my_issue, 'done', assignee: { name: 'username' }, customfield_11005: 'example')
|
96
96
|
#
|
97
|
-
# @param [
|
98
|
-
# @param [
|
97
|
+
# @param [Integer, String] transition_id ID or name of the transition
|
98
|
+
# @param [Array<JIRA::Resource::Issue>, JIRA::Resource::Issue] issue An array of issues, or a single issue
|
99
99
|
# @param [Hash] fields Fields that can be updated on the transition screen
|
100
100
|
#
|
101
101
|
# @return [Boolean] `true` if all the issues were transitioned successfully, `false` otherwise.
|
102
102
|
#
|
103
|
-
def
|
103
|
+
def transition_all(transition_id, issue: @issues, **fields)
|
104
104
|
issues = issue.kind_of?(Array) ? issue : [] << issue
|
105
|
-
data = { transition: { id: transition_id.to_s } }
|
106
|
-
data[:fields] = fields unless fields.empty?
|
107
105
|
result = true
|
108
106
|
|
109
107
|
issues.each do |key|
|
110
|
-
result &= key.
|
108
|
+
result &= key.transition(transition_id, **fields)
|
111
109
|
end
|
112
110
|
|
113
111
|
return result
|
@@ -116,21 +114,21 @@ module Danger
|
|
116
114
|
# Update the given Jira issue(s).
|
117
115
|
#
|
118
116
|
# @example Update the issue `my_issue` and set the fields `assignee` and `customfield_11005`
|
119
|
-
# jira.
|
117
|
+
# jira.update_all(my_issue, assignee: { name: 'username' }, customfield_11005: 'example')
|
120
118
|
#
|
121
|
-
# @param [Array<JIRA::Issue
|
119
|
+
# @param [Array<JIRA::Resource::Issue>, JIRA::Resource::Issue] issue An array of issue, or a single issue
|
122
120
|
# @param [Hash] fields Fields to update
|
123
121
|
#
|
124
122
|
# @return [Boolean] `true` if all the issues were updated successfully, `false` otherwise.
|
125
123
|
#
|
126
|
-
def
|
124
|
+
def update_all(issue: @issues, **fields)
|
127
125
|
return if fields.empty?
|
128
126
|
|
129
127
|
issues = issue.kind_of?(Array) ? issue : [] << issue
|
130
128
|
result = true
|
131
129
|
|
132
130
|
issues.each do |key|
|
133
|
-
result &= key.
|
131
|
+
result &= key.update(**fields)
|
134
132
|
end
|
135
133
|
|
136
134
|
return result
|
@@ -138,7 +136,7 @@ module Danger
|
|
138
136
|
|
139
137
|
# Utility to split the given fields into fields that can be updated on the transition screen corresponding to the `transition_id` of the given `issue`.
|
140
138
|
#
|
141
|
-
# @param [JIRA::Issue] issue
|
139
|
+
# @param [JIRA::Resource::Issue] issue
|
142
140
|
# @param [Integer] transition_id
|
143
141
|
# @param [Hash] fields Fields to split
|
144
142
|
#
|
@@ -162,39 +160,29 @@ module Danger
|
|
162
160
|
# and use the other fields with the update action.
|
163
161
|
#
|
164
162
|
# @example Transition the issue `my_issue` and set the fields `assignee` and `customfield_11005`
|
165
|
-
# jira.
|
163
|
+
# jira.transition_and_update_all(my_issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
|
166
164
|
#
|
167
|
-
# @param [Array<JIRA::Issue>] issue An array of issues, or a single `JIRA::Issue`
|
168
165
|
# @param [Integer] transition_id
|
166
|
+
# @param [Array<JIRA::Resource::Issue>, JIRA::Resource::Issue] issue An array of issues, or a single issue
|
169
167
|
# @param [Hash] fields Fields to update
|
170
168
|
#
|
171
169
|
# @return [Boolean] `true` if all the issues were transitioned and updated successfully, `false` otherwise.
|
172
170
|
#
|
173
|
-
def
|
171
|
+
def transition_and_update_all(transition_id, issue: @issues, **fields)
|
174
172
|
issues = issue.kind_of?(Array) ? issue : [] << issue
|
175
173
|
result = issues.first.split_transition_fields(transition_id, fields)
|
176
174
|
transition_fields = result[:transition_fields]
|
177
175
|
fields = result[:other_fields]
|
178
176
|
|
179
|
-
result = transition(
|
180
|
-
result & update(issues, **fields)
|
181
|
-
end
|
182
|
-
|
183
|
-
# Get the browse URL of a Jira issue.
|
184
|
-
#
|
185
|
-
# @param [JIRA::Issue] issue
|
186
|
-
#
|
187
|
-
# @return [String] the URL of the issue
|
188
|
-
#
|
189
|
-
def issue_link(issue)
|
190
|
-
"#{ENV['DANGER_JIRA_URL']}/browse/#{issue.key}"
|
177
|
+
result = transition(transition_id, issue: issues, **transition_fields)
|
178
|
+
result & update(issue: issues, **fields)
|
191
179
|
end
|
192
180
|
|
193
181
|
# 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
182
|
#
|
195
|
-
# @param [Array<JIRA::Issue
|
183
|
+
# @param [Array<JIRA::Resource::Issue>, JIRA::Resource::Issue] issue An array of issues, or a single issue
|
196
184
|
# @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`
|
185
|
+
# @param [<Hash>, <Boolean>] 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
186
|
#
|
199
187
|
# @return [Boolean] `true` if all the remote links were added successfully, `false` otherwise.
|
200
188
|
#
|
@@ -230,12 +218,10 @@ module Danger
|
|
230
218
|
def pr_link
|
231
219
|
return @pr_link unless @pr_link.nil?
|
232
220
|
|
233
|
-
pr_hash = JSON.parse(vcs_host.pr_json, symbolize_names: true)
|
234
|
-
|
235
221
|
if defined? @dangerfile.gitlab
|
236
|
-
@pr_link =
|
222
|
+
@pr_link = vcs_host.pr_json['web_url']
|
237
223
|
else
|
238
|
-
@pr_link =
|
224
|
+
@pr_link = vcs_host.pr_json['html_url']
|
239
225
|
end
|
240
226
|
|
241
227
|
return @pr_link
|
@@ -249,7 +235,7 @@ module Danger
|
|
249
235
|
|
250
236
|
def build_regexp_from_key(key)
|
251
237
|
keys = key.kind_of?(Array) ? key.join('|') : key
|
252
|
-
return /((?:#{keys})-[0-9]+)/
|
238
|
+
return /((?:#{keys})-[0-9]+)/i
|
253
239
|
end
|
254
240
|
|
255
241
|
def search_title(regexp)
|
data/spec/yajp_spec.rb
CHANGED
@@ -47,9 +47,9 @@ module Danger
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'can find jira issues via branch name' do
|
50
|
-
allow(plugin).to receive_message_chain('github.branch_for_head').and_return('bugfix/
|
50
|
+
allow(plugin).to receive_message_chain('github.branch_for_head').and_return('bugfix/web-126')
|
51
51
|
issues = plugin.search_branch(plugin.build_regexp_from_key('WEB'))
|
52
|
-
expect(issues).to eq(['
|
52
|
+
expect(issues).to eq(['web-126'])
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'can find jira issues in pr body' do
|
@@ -62,13 +62,14 @@ module Danger
|
|
62
62
|
issue = Object.new
|
63
63
|
|
64
64
|
def issue.find(key)
|
65
|
-
|
65
|
+
# The find method in jira-ruby plugin is not case sensitive, hence the upcase.
|
66
|
+
return key.upcase
|
66
67
|
end
|
67
68
|
|
68
69
|
allow_any_instance_of(JIRA::Client).to receive(:Issue).and_return(issue)
|
69
70
|
|
70
71
|
allow(plugin).to receive_message_chain('github.pr_title').and_return('Fix for WEB-128 and WEB-129')
|
71
|
-
allow(plugin).to receive_message_chain('github.branch_for_head').and_return('bugfix/
|
72
|
+
allow(plugin).to receive_message_chain('github.branch_for_head').and_return('bugfix/web-128')
|
72
73
|
issues = plugin.find_issues('WEB', search_branch: true)
|
73
74
|
expect(issues).to eq(['WEB-128', 'WEB-129'])
|
74
75
|
end
|
@@ -83,7 +84,7 @@ module Danger
|
|
83
84
|
allow_any_instance_of(JIRA::Base).to receive(:self).and_return(url)
|
84
85
|
stub = stub_request(:get, "#{url}/transitions?expand=transitions.fields").
|
85
86
|
to_return(body: json)
|
86
|
-
result = plugin.split_transition_fields(plugin.api.Issue.build, 2, transition_data.merge(fields))
|
87
|
+
result = plugin.split_transition_fields(plugin.api.Issue.build, 2, **transition_data.merge(fields))
|
87
88
|
|
88
89
|
expect(stub).to have_been_requested.once
|
89
90
|
expect(result).to eq({ transition_fields: transition_data, other_fields: fields })
|
@@ -91,13 +92,16 @@ module Danger
|
|
91
92
|
|
92
93
|
it 'can transition an issue' do
|
93
94
|
expected_json = '{"transition":{"id":"2"},"fields":{"assignee":{"name":"username"},"customfield_11005":"example"}}'
|
94
|
-
|
95
|
-
|
95
|
+
issue_id = Random.rand(1000)
|
96
|
+
url = "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/#{issue_id}/transitions"
|
97
|
+
issue = plugin.api.Issue.build({ 'id' => issue_id, 'key' => 'WEB-131' })
|
98
|
+
transition_1 = issue.transitions.build({ 'id' => '2', 'name' => 'TEST' })
|
99
|
+
transition_2 = issue.transitions.build({ 'id' => '3', 'name' => 'FAKE' })
|
96
100
|
|
97
|
-
|
101
|
+
allow_any_instance_of(JIRA::HasManyProxy).to receive(:all).and_return([transition_1, transition_2])
|
98
102
|
stub = stub_request(:post, url).
|
99
103
|
with(body: expected_json)
|
100
|
-
result = plugin.
|
104
|
+
result = plugin.transition_all('test', issue: issue, assignee: { name: 'username' }, customfield_11005: 'example')
|
101
105
|
|
102
106
|
expect(stub).to have_been_requested.once
|
103
107
|
expect(result).to be true
|
@@ -106,14 +110,12 @@ module Danger
|
|
106
110
|
it 'can update issues' do
|
107
111
|
expected_json = '{"fields":{"assignee":{"name":"username"},"customfield_11005":"example"}}'
|
108
112
|
uri_template = Addressable::Template.new "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/{issue}"
|
109
|
-
issue1 = plugin.api.Issue.build
|
110
|
-
issue2 = plugin.api.Issue.build
|
113
|
+
issue1 = plugin.api.Issue.build({ 'id' => Random.rand(1000), 'self' => "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/WEB-132", 'key' => 'WEB-132' })
|
114
|
+
issue2 = plugin.api.Issue.build({ 'id' => Random.rand(1000), 'self' => "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/WEB-133", 'key' => 'WEB-133' })
|
111
115
|
|
112
|
-
allow(issue1).to receive(:key_value).and_return('WEB-132')
|
113
|
-
allow(issue2).to receive(:key_value).and_return('WEB-133')
|
114
116
|
stub = stub_request(:put, uri_template).
|
115
117
|
with(body: expected_json)
|
116
|
-
result = plugin.
|
118
|
+
result = plugin.update_all(issue: [issue1, issue2], assignee: { name: 'username' }, customfield_11005: 'example')
|
117
119
|
|
118
120
|
expect(stub).to have_been_requested.twice
|
119
121
|
expect(result).to be true
|
@@ -122,7 +124,7 @@ module Danger
|
|
122
124
|
|
123
125
|
it 'can add remote link' do
|
124
126
|
pr_title = 'PR Title'
|
125
|
-
pr_json = '
|
127
|
+
pr_json = { 'html_url' => 'https://github.com/test/pull/1234' }
|
126
128
|
url = "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/WEB-134/remotelink"
|
127
129
|
json = File.read("#{File.dirname(__FILE__)}/support/remotelink.json")
|
128
130
|
issue = plugin.api.Issue.build
|
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.1
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- juliendms
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|
@@ -72,56 +72,56 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3
|
75
|
+
version: '3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3
|
82
|
+
version: '3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: webmock
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '3
|
89
|
+
version: '3'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '3
|
96
|
+
version: '3'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rubocop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1
|
103
|
+
version: '1'
|
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
|
-
version: 1
|
110
|
+
version: '1'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: yard
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.9
|
117
|
+
version: '0.9'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.9
|
124
|
+
version: '0.9'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: guard
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,6 +171,7 @@ executables: []
|
|
171
171
|
extensions: []
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
174
|
+
- ".github/workflows/create-tag.yml"
|
174
175
|
- ".github/workflows/gem-push.yml"
|
175
176
|
- ".gitignore"
|
176
177
|
- ".rubocop.yml"
|
@@ -185,6 +186,7 @@ files:
|
|
185
186
|
- lib/danger_plugin.rb
|
186
187
|
- lib/danger_yajp.rb
|
187
188
|
- lib/yajp/gem_version.rb
|
189
|
+
- lib/yajp/issue.rb
|
188
190
|
- lib/yajp/plugin.rb
|
189
191
|
- spec/spec_helper.rb
|
190
192
|
- spec/support/remotelink.json
|