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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31fe21c6c47db66193c9bb074710f559b03ea8b8df46abc478712d2d23d0d00d
4
- data.tar.gz: 93cc2f58198a219c4a9e758c6e6ed2e36934dff6576b2d3d24ddca3e039e9698
3
+ metadata.gz: 2868f707abb91adf4aac75dbc2c882083fdee0851e7abb37fc90b939ae7c944e
4
+ data.tar.gz: fce1af4f4cd6cfa8fb3b0be1f36d5d507f86b8d43a45c78203078a2120572c65
5
5
  SHA512:
6
- metadata.gz: 278831d0fbef23988cd1fad62d056aab0bb21ce96b33215f6a0222c361c2d1860ecf6267da024a7b7cb7a0a68455e87df272ccc3768e1be8004f8c6b6887c88e
7
- data.tar.gz: cc54f2f528a3a4c2a92f96330dad7116f30b667a6558262ffb4eedc07b10a9558490ba798229693fd8e8cc7d9c8331dbcbbd0e48f06cde3996bc2353a9c3418d
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 (0.1.0)
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.0.3.4)
11
+ activesupport (6.1.3.1)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
16
- zeitwerk (~> 2.2, >= 2.2.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.1)
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.7)
29
+ concurrent-ruby (1.1.8)
30
30
  cork (0.3.0)
31
31
  colored2 (~> 3.1)
32
- crack (0.4.4)
33
- danger (8.2.0)
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 (~> 1)
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.1.0)
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
- ffi (1.13.1-x64-mingw32)
56
+ faraday-net_http (1.0.1)
57
+ ffi (1.15.0-x64-mingw32)
55
58
  formatador (0.2.5)
56
- git (1.7.0)
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.5)
76
+ i18n (1.8.10)
74
77
  concurrent-ruby (~> 1.0)
75
- jira-ruby (2.1.3)
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.0)
84
+ kramdown (2.3.1)
82
85
  rexml
83
86
  kramdown-parser-gfm (1.1.0)
84
87
  kramdown (~> 2.0)
85
- listen (3.2.1)
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.2)
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.4)
99
- octokit (4.19.0)
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.19.2)
104
- parser (2.7.2.0)
106
+ parallel (1.20.1)
107
+ parser (3.0.1.0)
105
108
  ast (~> 2.4.1)
106
- pry (0.13.1)
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.1)
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.8.2)
117
- rexml (3.2.4)
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.0)
125
+ rspec-core (3.10.1)
123
126
  rspec-support (~> 3.10.0)
124
- rspec-expectations (3.10.0)
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.0)
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.0)
131
- rubocop (1.2.0)
133
+ rspec-support (3.10.2)
134
+ rubocop (1.12.1)
132
135
  parallel (~> 1.10)
133
- parser (>= 2.7.1.5)
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.1)
140
+ rubocop-ast (>= 1.2.0, < 2.0)
138
141
  ruby-progressbar (~> 1.7)
139
- unicode-display_width (>= 1.4.0, < 2.0)
140
- rubocop-ast (1.1.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.10.1)
143
- ruby2_keywords (0.0.2)
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.8.0)
149
- unicode-display_width (~> 1.1, >= 1.1.1)
150
- thor (1.0.1)
151
- thread_safe (0.3.6)
152
- tzinfo (1.2.7)
153
- thread_safe (~> 0.1)
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.25)
160
- zeitwerk (2.4.1)
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.9)
173
- rubocop (>= 1.0.0)
174
- webmock (~> 3.9)
175
- yard (~> 0.9.11)
173
+ rspec (~> 3)
174
+ rubocop (~> 1)
175
+ webmock (~> 3)
176
+ yard (~> 0.9)
176
177
 
177
178
  BUNDLED WITH
178
- 2.1.4
179
+ 2.2.3
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Gem](https://img.shields.io/gem/v/danger-yajp)](https://rubygems.org/gems/danger-yajp)
5
5
  [![Dependencies](https://img.shields.io/librariesio/release/rubygems/danger-yajp)](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 `DANGER_JIRA_PASSWORD` in your CI environment, for example:
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
- DANGER_JIRA_PASSWORD: abcd12345
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
- * An issue (from `jira-ruby`) or an array of issues
51
- * For the transition action, the ID of the transition
52
- * Any number of fields to be updated in the form: `key: value`
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.transition(my_issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
56
+ jira.transition_all('done', assignee: { name: 'username' }, customfield_11005: 'example')
56
57
  ```
57
58
 
58
- The `transition` method only takes 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` method to transition and update issues (and automatically dispatch the fields to the correct action).
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 `issue_link` to retrieve the browse URL of the Jira issue.
78
+ Use `link` to retrieve the browse URL of the Jira issue.
73
79
 
74
80
  ```rb
75
- message "<a href='#{jira.issue_link(issue)}'>#{issue.key} - #{issue.summary}</a>"
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='#{jira.issue_link(issue)}'>#{issue.key} - #{issue.summary}</a>"
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.transition_and_update(issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
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='#{jira.issue_link(issue)}'>#{issue.key}</a> is not in Dev status, please make sure the issue you're working on is in the correct status"
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.9'
33
- spec.add_development_dependency 'webmock', '~> 3.9'
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', '>= 1.0.0'
37
- spec.add_development_dependency 'yard', '~> 0.9.11'
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'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yajp
4
- VERSION = '0.1.0'
4
+ VERSION = '1.0.1'
5
5
  end
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
- require 'jira-ruby'
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='#{jira.issue_link(issue)}'>#{issue.key} - #{issue.summary}</a>"
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
- # jira.transition_and_update(issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
25
+ # issue.transition(10, assignee: { name: 'username' }, customfield_11005: 'example')
27
26
  # when 'To Do', 'Blocked'
28
- # warn "Issue <a href='#{jira.issue_link(issue)}'>#{issue.key}</a> is not in Dev status, please make sure the issue you're working on is in the correct status"
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.transition(my_issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
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 [Array<JIRA::Issue>] issue An array of issues, or a single `JIRA::Issue`
98
- # @param [Integer] transition_id
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 transition(issue, transition_id, **fields)
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.transitions.build.save(data)
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.update(my_issue, assignee: { name: 'username' }, customfield_11005: 'example')
117
+ # jira.update_all(my_issue, assignee: { name: 'username' }, customfield_11005: 'example')
120
118
  #
121
- # @param [Array<JIRA::Issue>] issue An array of issue, or a single `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 update(issue, **fields)
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.save({ fields: fields })
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.transition_and_update(my_issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
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 transition_and_update(issue, transition_id, **fields)
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(issues, transition_id, **transition_fields)
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>] issue An array of issues, or a single `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 = pr_hash[:web_url]
222
+ @pr_link = vcs_host.pr_json['web_url']
237
223
  else
238
- @pr_link = pr_hash[:html_url]
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/WEB-126')
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(['WEB-126'])
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
- return key
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/WEB-128')
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
- url = "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/WEB-131/transitions"
95
- issue = plugin.api.Issue.build
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
- allow(issue).to receive(:key_value).and_return('WEB-131')
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.transition(issue, 2, assignee: { name: 'username' }, customfield_11005: 'example')
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.update([issue1, issue2], assignee: { name: 'username' }, customfield_11005: 'example')
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 = '{"html_url":"https://github.com/test/pull/1234"}'
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.0
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: 2020-11-06 00:00:00.000000000 Z
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.9'
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.9'
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.9'
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.9'
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.0.0
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.0.0
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.11
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.11
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