danger-yajp 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f67dc7849b79110482c02fa779ac8e3622a7e9c82d7ff1ae84fb1a898bcb022
4
- data.tar.gz: f9faa4baac94dd08416a34c783708334a502e15e48a5cff6fc3db98a35131bfd
3
+ metadata.gz: 2b33191a7403d610580966c988913cd164f6eb2fba53b54aabb3bfc30c3d9796
4
+ data.tar.gz: b57ab4fe9c1a1b37b15647dd2358fd8640904f96801c91d680828a93d0b31779
5
5
  SHA512:
6
- metadata.gz: f580d3fc39375dfd017c6824b6900c667abd73304346f86bfc4f8b43c841b23a0c2a12806c621b0ad54b9a925f73b66223202117851e7f9cfdaee578e13b327e
7
- data.tar.gz: 12cf1174e25d554a0058aecf3261c2c87104d0f30fb351f38ea902519a34aa9f8d920320db9500fb1bafdc231c126754628efbe568262b2edc77eefee4532d81
6
+ metadata.gz: 0df505bcf5ff1c4eaa239607e4c759a09dc098e477e078b7a622bc58c97db93d7c8b9d61413b2da137cf858890ab450cebe26593bcaf249264d9adfc82c9e3a3
7
+ data.tar.gz: a2a95d33414764499d4879b52be808547343e3e6478c0f2493efa8d2db89ad91aac3a7f1d21555a88d386e5dfa9de2bc5249b511b37da1dfec05a7a5feeb22bb
@@ -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 }}
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-yajp (0.1.2)
4
+ danger-yajp (0.1.3)
5
5
  danger-plugin-api
6
6
  jira-ruby
7
7
 
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
 
@@ -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
50
  * For the transition action, the ID of the transition
52
- * Any number of fields to be updated in the form: `key: value`
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(10, 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yajp
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
@@ -0,0 +1,50 @@
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 of the transition. Transition IDs can be found in Jira under Project Workflow > Edit Workflow in Text Mode.
33
+ # 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`.
34
+ #
35
+ # @example Transition the issue and set the fields `assignee` and `customfield_11005` available on the transition screens
36
+ # jira.transition(my_issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
37
+ #
38
+ # @param [Integer] transition_id
39
+ # @param [Hash] fields Fields that can be updated on the transition screen
40
+ #
41
+ # @return [Boolean] `true` if the issue was transitioned successfully, `false` otherwise.
42
+ #
43
+ def transition(transition_id, **fields)
44
+ data = { transition: { id: transition_id.to_s } }
45
+ data[:fields] = fields unless fields.empty?
46
+
47
+ transitions.build.save(data)
48
+ end
49
+ end
50
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'jira-ruby'
3
+ require_relative 'issue'
4
4
 
5
5
  module Danger
6
6
  # Yet Another Jira Plugin (in short: yajp) provides methods to easily find and manipulate issues from within the Dangerfile.
@@ -18,13 +18,13 @@ module Danger
18
18
  # warn 'This PR does not contain any Jira issue.'
19
19
  # else
20
20
  # issues.each do |issue|
21
- # message "<a href='#{jira.issue_link(issue)}'>#{issue.key} - #{issue.summary}</a>"
21
+ # message "<a href='#{issue.link}'>#{issue.key} - #{issue.summary}</a>"
22
22
  #
23
23
  # case issue.status.name
24
24
  # when 'In Progress'
25
- # jira.transition_and_update(issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
25
+ # issue.transition(10, assignee: { name: 'username' }, customfield_11005: 'example')
26
26
  # when 'To Do', 'Blocked'
27
- # 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"
28
28
  # end
29
29
  # end
30
30
  # end
@@ -73,7 +73,7 @@ module Danger
73
73
  # @param [Boolean] search_commits Option to search Jira issues from from commit messages
74
74
  # @param [Boolean] search_branch Option to search Jira issues from the name of the PR branch
75
75
  #
76
- # @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.
77
77
  #
78
78
  def find_issues(key, search_title: true, search_commits: false, search_branch: false)
79
79
  regexp = build_regexp_from_key(key)
@@ -84,29 +84,27 @@ module Danger
84
84
  jira_issues.concat(search_branch(regexp)) if search_branch
85
85
  jira_issues.concat(search_pr_body(regexp)) if jira_issues.empty?
86
86
 
87
- jira_issues.uniq(&:downcase).map { |issue_key| @api.Issue.find(issue_key) }
87
+ @issues = jira_issues.uniq(&:downcase).map { |issue_key| @api.Issue.find(issue_key) }
88
88
  end
89
89
 
90
90
  # 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.
91
91
  # 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`.
92
92
  #
93
93
  # @example Transition the issue `my_issue` and set the fields `assignee` and `customfield_11005` available on the transition screens
94
- # jira.transition(my_issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
94
+ # jira.transition_all(my_issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
95
95
  #
96
- # @param [Array<JIRA::Issue>] issue An array of issues, or a single `JIRA::Issue`
97
96
  # @param [Integer] transition_id
97
+ # @param [Array<JIRA::Resource::Issue>, JIRA::Resource::Issue] issue An array of issues, or a single issue
98
98
  # @param [Hash] fields Fields that can be updated on the transition screen
99
99
  #
100
100
  # @return [Boolean] `true` if all the issues were transitioned successfully, `false` otherwise.
101
101
  #
102
- def transition(issue, transition_id, **fields)
102
+ def transition_all(transition_id, issue: @issues, **fields)
103
103
  issues = issue.kind_of?(Array) ? issue : [] << issue
104
- data = { transition: { id: transition_id.to_s } }
105
- data[:fields] = fields unless fields.empty?
106
104
  result = true
107
105
 
108
106
  issues.each do |key|
109
- result &= key.transitions.build.save(data)
107
+ result &= key.transition(transition_id, **fields)
110
108
  end
111
109
 
112
110
  return result
@@ -115,21 +113,21 @@ module Danger
115
113
  # Update the given Jira issue(s).
116
114
  #
117
115
  # @example Update the issue `my_issue` and set the fields `assignee` and `customfield_11005`
118
- # jira.update(my_issue, assignee: { name: 'username' }, customfield_11005: 'example')
116
+ # jira.update_all(my_issue, assignee: { name: 'username' }, customfield_11005: 'example')
119
117
  #
120
- # @param [Array<JIRA::Issue>] issue An array of issue, or a single `JIRA::Issue`
118
+ # @param [Array<JIRA::Resource::Issue>, JIRA::Resource::Issue] issue An array of issue, or a single issue
121
119
  # @param [Hash] fields Fields to update
122
120
  #
123
121
  # @return [Boolean] `true` if all the issues were updated successfully, `false` otherwise.
124
122
  #
125
- def update(issue, **fields)
123
+ def update_all(issue: @issues, **fields)
126
124
  return if fields.empty?
127
125
 
128
126
  issues = issue.kind_of?(Array) ? issue : [] << issue
129
127
  result = true
130
128
 
131
129
  issues.each do |key|
132
- result &= key.save({ fields: fields })
130
+ result &= key.update(**fields)
133
131
  end
134
132
 
135
133
  return result
@@ -137,7 +135,7 @@ module Danger
137
135
 
138
136
  # 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`.
139
137
  #
140
- # @param [JIRA::Issue] issue
138
+ # @param [JIRA::Resource::Issue] issue
141
139
  # @param [Integer] transition_id
142
140
  # @param [Hash] fields Fields to split
143
141
  #
@@ -161,39 +159,53 @@ module Danger
161
159
  # and use the other fields with the update action.
162
160
  #
163
161
  # @example Transition the issue `my_issue` and set the fields `assignee` and `customfield_11005`
164
- # jira.transition_and_update(my_issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
162
+ # jira.transition_and_update_all(my_issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
165
163
  #
166
- # @param [Array<JIRA::Issue>] issue An array of issues, or a single `JIRA::Issue`
167
164
  # @param [Integer] transition_id
165
+ # @param [Array<JIRA::Resource::Issue>, JIRA::Resource::Issue] issue An array of issues, or a single issue
168
166
  # @param [Hash] fields Fields to update
169
167
  #
170
168
  # @return [Boolean] `true` if all the issues were transitioned and updated successfully, `false` otherwise.
171
169
  #
172
- def transition_and_update(issue, transition_id, **fields)
170
+ def transition_and_update_all(transition_id, issue: @issues, **fields)
173
171
  issues = issue.kind_of?(Array) ? issue : [] << issue
174
172
  result = issues.first.split_transition_fields(transition_id, fields)
175
173
  transition_fields = result[:transition_fields]
176
174
  fields = result[:other_fields]
177
175
 
178
- result = transition(issues, transition_id, **transition_fields)
179
- result & update(issues, **fields)
176
+ result = transition(transition_id, issue: issues, **transition_fields)
177
+ result & update(issue: issues, **fields)
180
178
  end
181
179
 
182
- # Get the browse URL of a Jira issue.
183
- #
184
- # @param [JIRA::Issue] issue
185
- #
186
- # @return [String] the URL of the issue
187
- #
180
+ # @deprecated Please use the new #{transition_and_update_all} method
181
+ def transition_and_update(issue, transition_id, **fields)
182
+ Warning.warn('Deprecated use of the transition_and_update method, please use the new method definition')
183
+ transition_and_update_all(transition_id, issue: issue, **fields)
184
+ end
185
+
186
+ # @deprecated Please use the new #{update_all} method
187
+ def update(issue, **fields)
188
+ Warning.warn('Deprecated use of the update method, please use the new method definition')
189
+ update_all(issue: issue, **fields)
190
+ end
191
+
192
+ # @deprecated Please use the new #{transition_all} method
193
+ def transition(issue, transition_id, **fields)
194
+ Warning.warn('Deprecated use of the transition method, please use the new method definition')
195
+ transition_all(transition_id, issue: issue, **fields)
196
+ end
197
+
198
+ # @deprecated Please use the method available on the issue directly [#JIRA::Resource::Issue.link]
188
199
  def issue_link(issue)
200
+ Warning.warn('Deprecated use of the issue_link method, please use the same method available in the Issue class')
189
201
  "#{ENV['DANGER_JIRA_URL']}/browse/#{issue.key}"
190
202
  end
191
203
 
192
204
  # 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.
193
205
  #
194
- # @param [Array<JIRA::Issue>] issue An array of issues, or a single `JIRA::Issue`
206
+ # @param [Array<JIRA::Resource::Issue>, JIRA::Resource::Issue] issue An array of issues, or a single issue
195
207
  # @param [<String>] relation Option to set the relationship of the remote link
196
- # @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`
208
+ # @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`
197
209
  #
198
210
  # @return [Boolean] `true` if all the remote links were added successfully, `false` otherwise.
199
211
  #
@@ -92,13 +92,13 @@ module Danger
92
92
 
93
93
  it 'can transition an issue' do
94
94
  expected_json = '{"transition":{"id":"2"},"fields":{"assignee":{"name":"username"},"customfield_11005":"example"}}'
95
- url = "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/WEB-131/transitions"
96
- 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' })
97
98
 
98
- allow(issue).to receive(:key_value).and_return('WEB-131')
99
99
  stub = stub_request(:post, url).
100
100
  with(body: expected_json)
101
- result = plugin.transition(issue, 2, assignee: { name: 'username' }, customfield_11005: 'example')
101
+ result = plugin.transition_all(2, issue: issue, assignee: { name: 'username' }, customfield_11005: 'example')
102
102
 
103
103
  expect(stub).to have_been_requested.once
104
104
  expect(result).to be true
@@ -107,14 +107,12 @@ module Danger
107
107
  it 'can update issues' do
108
108
  expected_json = '{"fields":{"assignee":{"name":"username"},"customfield_11005":"example"}}'
109
109
  uri_template = Addressable::Template.new "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/{issue}"
110
- issue1 = plugin.api.Issue.build
111
- issue2 = plugin.api.Issue.build
110
+ issue1 = plugin.api.Issue.build({ 'id' => Random.rand(1000), 'self' => "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/WEB-132", 'key' => 'WEB-132' })
111
+ issue2 = plugin.api.Issue.build({ 'id' => Random.rand(1000), 'self' => "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/WEB-133", 'key' => 'WEB-133' })
112
112
 
113
- allow(issue1).to receive(:key_value).and_return('WEB-132')
114
- allow(issue2).to receive(:key_value).and_return('WEB-133')
115
113
  stub = stub_request(:put, uri_template).
116
114
  with(body: expected_json)
117
- result = plugin.update([issue1, issue2], assignee: { name: 'username' }, customfield_11005: 'example')
115
+ result = plugin.update_all(issue: [issue1, issue2], assignee: { name: 'username' }, customfield_11005: 'example')
118
116
 
119
117
  expect(stub).to have_been_requested.twice
120
118
  expect(result).to be true
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.2
4
+ version: 0.1.3
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-12 00:00:00.000000000 Z
11
+ date: 2020-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -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