Skip to content

Commit

Permalink
merge: support transition via name
Browse files Browse the repository at this point in the history
Support transition by name + version 1.0.0
  • Loading branch information
juliendms authored Jan 5, 2021
2 parents ea5306f + 805a677 commit 125acf8
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 75 deletions.
76 changes: 39 additions & 37 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
PATH
remote: .
specs:
danger-yajp (0.1.3)
danger-yajp (1.0.0)
danger-plugin-api
jira-ruby

GEM
remote: https://rubygems.org/
specs:
activesupport (6.0.3.4)
activesupport (6.1.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.1)
Expand All @@ -29,7 +29,8 @@ GEM
concurrent-ruby (1.1.7)
cork (0.3.0)
colored2 (~> 3.1)
crack (0.4.4)
crack (0.4.5)
rexml
danger (8.2.1)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
Expand All @@ -46,14 +47,16 @@ GEM
danger-plugin-api (1.0.0)
danger (> 2.0)
diff-lcs (1.4.4)
faraday (1.1.0)
faraday (1.3.0)
faraday-net_http (~> 1.0)
multipart-post (>= 1.2, < 3)
ruby2_keywords
faraday-http-cache (2.2.0)
faraday (>= 0.8)
ffi (1.13.1-x64-mingw32)
faraday-net_http (1.0.0)
ffi (1.14.2-x64-mingw32)
formatador (0.2.5)
git (1.7.0)
git (1.8.1)
rchardet (~> 1.8)
guard (2.16.2)
formatador (>= 0.2.4)
Expand All @@ -70,9 +73,9 @@ GEM
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
hashdiff (1.0.1)
i18n (1.8.5)
i18n (1.8.7)
concurrent-ruby (~> 1.0)
jira-ruby (2.1.3)
jira-ruby (2.1.4)
activesupport
atlassian-jwt
multipart-post
Expand All @@ -82,7 +85,7 @@ GEM
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
listen (3.3.0)
listen (3.4.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
lumberjack (1.2.8)
Expand All @@ -96,50 +99,50 @@ GEM
nenv (~> 0.1)
shellany (~> 0.0)
oauth (0.5.4)
octokit (4.19.0)
octokit (4.20.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
open4 (1.3.4)
parallel (1.20.0)
parser (2.7.2.0)
parallel (1.20.1)
parser (3.0.0.0)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (4.0.6)
rainbow (3.0.0)
rake (13.0.1)
rake (13.0.3)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
rchardet (1.8.0)
regexp_parser (1.8.2)
regexp_parser (2.0.3)
rexml (3.2.4)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.0)
rspec-mocks (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.0)
rubocop (1.3.0)
rspec-support (3.10.1)
rubocop (1.7.0)
parallel (~> 1.10)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.1.1)
rubocop-ast (>= 1.2.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.1.1)
rubocop-ast (1.4.0)
parser (>= 2.7.1.5)
ruby-progressbar (1.10.1)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.2)
sawyer (0.8.2)
addressable (>= 2.3.5)
Expand All @@ -148,16 +151,15 @@ GEM
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
thor (1.0.1)
thread_safe (0.3.6)
tzinfo (1.2.8)
thread_safe (~> 0.1)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (1.7.0)
webmock (3.10.0)
webmock (3.11.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
yard (0.9.25)
zeitwerk (2.4.1)
yard (0.9.26)
zeitwerk (2.4.2)

PLATFORMS
x64-mingw32
Expand All @@ -169,10 +171,10 @@ DEPENDENCIES
guard-rspec (~> 4.7)
pry
rake (~> 13.0)
rspec (~> 3.9)
rubocop (>= 1.0.0)
webmock (~> 3.9)
yard (~> 0.9.11)
rspec (~> 3)
rubocop (~> 1)
webmock (~> 3)
yard (~> 0.9)

BUNDLED WITH
2.1.4
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ end

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:

* For the transition action, the ID of the transition
* For the transition action, the ID or name of the transition (which is not the name of the status)
* 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.
* Any number of fields to be updated in a hash: `key: value`

Example 1: transition all the issues found after running `find_issues`:
```rb
jira.transition_all(10, assignee: { name: 'username' }, customfield_11005: 'example')
jira.transition_all('done', assignee: { name: 'username' }, customfield_11005: 'example')
```

Example 2: update a single issue:
Expand Down
8 changes: 4 additions & 4 deletions danger-yajp.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 13.0'

# Testing support
spec.add_development_dependency 'rspec', '~> 3.9'
spec.add_development_dependency 'webmock', '~> 3.9'
spec.add_development_dependency 'rspec', '~> 3'
spec.add_development_dependency 'webmock', '~> 3'

# Linting code and docs
spec.add_development_dependency 'rubocop', '>= 1.0.0'
spec.add_development_dependency 'yard', '~> 0.9.11'
spec.add_development_dependency 'rubocop', '~> 1'
spec.add_development_dependency 'yard', '~> 0.9'

# Makes testing easy via `bundle exec guard`
spec.add_development_dependency 'guard', '~> 2.16'
Expand Down
2 changes: 1 addition & 1 deletion lib/yajp/gem_version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Yajp
VERSION = '0.1.3'
VERSION = '1.0.0'
end
24 changes: 22 additions & 2 deletions lib/yajp/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,42 @@ def update(**fields)
save({ fields: fields })
end

# Transition the issue using the ID of the transition. Transition IDs can be found in Jira under Project Workflow > Edit Workflow in Text Mode.
# 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.
# The transition name is the text that appears on the issue screen to transition it.
# 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`.
#
# @example Transition the issue and set the fields `assignee` and `customfield_11005` available on the transition screens
# jira.transition(my_issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
#
# @param [Integer] transition_id
# @param [Integer, String] transition_id ID or name of the transition
# @param [Hash] fields Fields that can be updated on the transition screen
#
# @return [Boolean] `true` if the issue was transitioned successfully, `false` otherwise.
#
def transition(transition_id, **fields)
if transition_id.kind_of?(String)
transition_id = get_transition_id(transition_id)

return false if transition_id == -1
end
data = { transition: { id: transition_id.to_s } }
data[:fields] = fields unless fields.empty?

transitions.build.save(data)
end

# Retrieve the ID of the transition matching the given name.
#
# @param [String] name
#
# @return [Integer] the ID of the transition, or -1 if no match was found
#
def get_transition_id(name)
transitions.all.each do |transition|
return transition.id if transition.name.casecmp?(name)
end

return -1
end
end
end
33 changes: 5 additions & 28 deletions lib/yajp/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ def find_issues(key, search_title: true, search_commits: false, search_branch: f
@issues = jira_issues.uniq(&:downcase).map { |issue_key| @api.Issue.find(issue_key) }
end

# 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.
# 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.
# The transition name is the text that appears on the issue screen to transition it.
# 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`.
#
# @example Transition the issue `my_issue` and set the fields `assignee` and `customfield_11005` available on the transition screens
# jira.transition_all(my_issue, 10, assignee: { name: 'username' }, customfield_11005: 'example')
# @example Transition the issue `my_issue` using the transition 'done' and set the fields `assignee` and `customfield_11005` available on the transition screens
# jira.transition_all(my_issue, 'done', assignee: { name: 'username' }, customfield_11005: 'example')
#
# @param [Integer] transition_id
# @param [Integer, String] transition_id ID or name of the transition
# @param [Array<JIRA::Resource::Issue>, JIRA::Resource::Issue] issue An array of issues, or a single issue
# @param [Hash] fields Fields that can be updated on the transition screen
#
Expand Down Expand Up @@ -177,30 +178,6 @@ def transition_and_update_all(transition_id, issue: @issues, **fields)
result & update(issue: issues, **fields)
end

# @deprecated Please use the new #{transition_and_update_all} method
def transition_and_update(issue, transition_id, **fields)
Warning.warn('Deprecated use of the transition_and_update method, please use the new method definition')
transition_and_update_all(transition_id, issue: issue, **fields)
end

# @deprecated Please use the new #{update_all} method
def update(issue, **fields)
Warning.warn('Deprecated use of the update method, please use the new method definition')
update_all(issue: issue, **fields)
end

# @deprecated Please use the new #{transition_all} method
def transition(issue, transition_id, **fields)
Warning.warn('Deprecated use of the transition method, please use the new method definition')
transition_all(transition_id, issue: issue, **fields)
end

# @deprecated Please use the method available on the issue directly [#JIRA::Resource::Issue.link]
def issue_link(issue)
Warning.warn('Deprecated use of the issue_link method, please use the same method available in the Issue class')
"#{ENV['DANGER_JIRA_URL']}/browse/#{issue.key}"
end

# 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.
#
# @param [Array<JIRA::Resource::Issue>, JIRA::Resource::Issue] issue An array of issues, or a single issue
Expand Down
5 changes: 4 additions & 1 deletion spec/yajp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,13 @@ def issue.find(key)
issue_id = Random.rand(1000)
url = "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/#{issue_id}/transitions"
issue = plugin.api.Issue.build({ 'id' => issue_id, 'key' => 'WEB-131' })
transition_1 = issue.transitions.build({ 'id' => '2', 'name' => 'TEST' })
transition_2 = issue.transitions.build({ 'id' => '3', 'name' => 'FAKE' })

allow_any_instance_of(JIRA::HasManyProxy).to receive(:all).and_return([transition_1, transition_2])
stub = stub_request(:post, url).
with(body: expected_json)
result = plugin.transition_all(2, issue: issue, assignee: { name: 'username' }, customfield_11005: 'example')
result = plugin.transition_all('test', issue: issue, assignee: { name: 'username' }, customfield_11005: 'example')

expect(stub).to have_been_requested.once
expect(result).to be true
Expand Down

0 comments on commit 125acf8

Please sign in to comment.