danger-yajp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ ROOT = Pathname.new(File.expand_path('..', __dir__))
5
+ $:.unshift("#{ROOT}lib".to_s)
6
+ $:.unshift("#{ROOT}spec".to_s)
7
+
8
+ require 'bundler/setup'
9
+ require 'pry'
10
+
11
+ require 'rspec'
12
+ require 'webmock/rspec'
13
+ require 'danger'
14
+
15
+ if `git remote -v` == ''
16
+ puts 'You cannot run tests without setting a local git remote on this repo'
17
+ puts "It's a weird side-effect of Danger's internals."
18
+ exit(0)
19
+ end
20
+
21
+ # Use coloured output, it's the best.
22
+ RSpec.configure do |config|
23
+ config.filter_gems_from_backtrace 'bundler'
24
+ config.color = true
25
+ config.tty = true
26
+ end
27
+
28
+ require 'danger_plugin'
29
+
30
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
31
+ # If you are expanding these files, see if it's already been done ^.
32
+
33
+ # A silent version of the user interface,
34
+ # it comes with an extra function `.string` which will
35
+ # strip all ANSI colours from the string.
36
+
37
+ # rubocop:disable Lint/NestedMethodDefinition
38
+ def testing_ui
39
+ @output = StringIO.new
40
+ def @output.winsize
41
+ [20, 9999]
42
+ end
43
+
44
+ cork = Cork::Board.new(out: @output)
45
+ def cork.string
46
+ out.string.gsub(/\e\[([;\d]+)?m/, '')
47
+ end
48
+ cork
49
+ end
50
+ # rubocop:enable Lint/NestedMethodDefinition
51
+
52
+ # Example environment (ENV) that would come from
53
+ # running a PR on TravisCI
54
+ def testing_env
55
+ {
56
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
57
+ 'TRAVIS_PULL_REQUEST' => '800',
58
+ 'TRAVIS_REPO_SLUG' => 'artsy/eigen',
59
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
60
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
61
+ }
62
+ end
63
+
64
+ # A stubbed out Dangerfile for use in tests
65
+ def testing_dangerfile
66
+ env = Danger::EnvironmentManager.new(testing_env)
67
+ Danger::Dangerfile.new(env, testing_ui)
68
+ end
@@ -0,0 +1,106 @@
1
+ {
2
+ "expand": "transitions",
3
+ "transitions": [
4
+ {
5
+ "id": "2",
6
+ "name": "Close Issue",
7
+ "to": {
8
+ "self": "http://localhost:8090/jira/rest/api/2.0/status/10000",
9
+ "description": "The issue is currently being worked on.",
10
+ "iconUrl": "http://localhost:8090/jira/images/icons/progress.gif",
11
+ "name": "In Progress",
12
+ "id": "10000",
13
+ "statusCategory": {
14
+ "self": "http://localhost:8090/jira/rest/api/2.0/statuscategory/1",
15
+ "id": 1,
16
+ "key": "in-flight",
17
+ "colorName": "yellow",
18
+ "name": "In Progress"
19
+ }
20
+ },
21
+ "fields": {
22
+ "summary": {
23
+ "required": false,
24
+ "schema": {
25
+ "type": "array",
26
+ "items": "option",
27
+ "custom": "com.atlassian.jira.plugin.system.customfieldtypes:multiselect",
28
+ "customId": 10001
29
+ },
30
+ "name": "My Multi Select",
31
+ "hasDefaultValue": false,
32
+ "operations": [
33
+ "set",
34
+ "add"
35
+ ],
36
+ "allowedValues": [
37
+ "red",
38
+ "blue"
39
+ ]
40
+ },
41
+ "assignee": {
42
+ "required": true,
43
+ "name":"Assignee",
44
+ "operations": ["set"]
45
+ }
46
+ }
47
+ },
48
+ {
49
+ "id": "711",
50
+ "name": "QA Review",
51
+ "to": {
52
+ "self": "http://localhost:8090/jira/rest/api/2.0/status/5",
53
+ "description": "The issue is closed.",
54
+ "iconUrl": "http://localhost:8090/jira/images/icons/closed.gif",
55
+ "name": "Closed",
56
+ "id": "5",
57
+ "statusCategory": {
58
+ "self": "http://localhost:8090/jira/rest/api/2.0/statuscategory/9",
59
+ "id": 9,
60
+ "key": "completed",
61
+ "colorName": "green"
62
+ }
63
+ },
64
+ "fields": {
65
+ "colour": {
66
+ "required": false,
67
+ "schema": {
68
+ "type": "array",
69
+ "items": "option",
70
+ "custom": "com.atlassian.jira.plugin.system.customfieldtypes:multiselect",
71
+ "customId": 10001
72
+ },
73
+ "name": "My Multi Select",
74
+ "hasDefaultValue": false,
75
+ "operations": [
76
+ "set",
77
+ "add"
78
+ ],
79
+ "allowedValues": [
80
+ "red",
81
+ "blue"
82
+ ]
83
+ },
84
+ "summary": {
85
+ "required": false,
86
+ "schema": {
87
+ "type": "array",
88
+ "items": "option",
89
+ "custom": "com.atlassian.jira.plugin.system.customfieldtypes:multiselect",
90
+ "customId": 10001
91
+ },
92
+ "name": "My Multi Select",
93
+ "hasDefaultValue": false,
94
+ "operations": [
95
+ "set",
96
+ "add"
97
+ ],
98
+ "allowedValues": [
99
+ "red",
100
+ "blue"
101
+ ]
102
+ }
103
+ }
104
+ }
105
+ ]
106
+ }
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('spec_helper', __dir__)
4
+
5
+ module Danger
6
+ describe Danger::DangerYajp do
7
+ it 'should be a plugin' do
8
+ expect(Danger::DangerYajp.new(nil)).to be_a Danger::Plugin
9
+ end
10
+
11
+ describe 'with Dangerfile' do
12
+ let(:dangerfile) { testing_dangerfile }
13
+ let(:plugin) { dangerfile.jira }
14
+
15
+ before do
16
+ ENV['DANGER_JIRA_URL'] = 'https://jira.company.com/jira'
17
+ ENV['DANGER_JIRA_USER'] = 'username'
18
+ ENV['DANGER_JIRA_PASSWORD'] = 'password'
19
+ DangerYajp.send(:public, *DangerYajp.private_instance_methods)
20
+ end
21
+
22
+ it 'should return a JIRA::Client instance' do
23
+ expect(plugin.api).to be_a(JIRA::Client)
24
+ end
25
+
26
+ it 'can find jira issues via title' do
27
+ allow(plugin).to receive_message_chain('github.pr_title').and_return('Ticket [WEB-123] and WEB-124')
28
+ issues = plugin.search_title(plugin.build_regexp_from_key('WEB'))
29
+ expect(issues).to eq(['WEB-123', 'WEB-124'])
30
+ end
31
+
32
+ it 'can find jira issues in commits' do
33
+ single_commit = Object.new
34
+
35
+ def single_commit.message
36
+ 'WIP [WEB-125]'
37
+ end
38
+
39
+ commits = [single_commit]
40
+ allow(plugin).to receive_message_chain('git.commits').and_return(commits)
41
+ issues = plugin.search_commits(plugin.build_regexp_from_key('WEB'))
42
+ expect(issues).to eq(['WEB-125'])
43
+ end
44
+
45
+ it 'can find jira issues via branch name' do
46
+ allow(plugin).to receive_message_chain('github.branch_for_head').and_return('bugfix/WEB-126')
47
+ issues = plugin.search_branch(plugin.build_regexp_from_key('WEB'))
48
+ expect(issues).to eq(['WEB-126'])
49
+ end
50
+
51
+ it 'can find jira issues in pr body' do
52
+ allow(plugin).to receive_message_chain('github.pr_body').and_return('Closes WEB-127')
53
+ issues = plugin.search_pr_body(plugin.build_regexp_from_key('WEB'))
54
+ expect(issues).to eq(['WEB-127'])
55
+ end
56
+
57
+ it 'can remove duplicates issue' do
58
+ issue = Object.new
59
+
60
+ def issue.find(key)
61
+ return key
62
+ end
63
+
64
+ allow_any_instance_of(JIRA::Client).to receive(:Issue).and_return(issue)
65
+
66
+ allow(plugin).to receive_message_chain('github.pr_title').and_return('Fix for WEB-128 and WEB-129')
67
+ allow(plugin).to receive_message_chain('github.branch_for_head').and_return('bugfix/WEB-128')
68
+ issues = plugin.find_issues('WEB', search_branch: true)
69
+ expect(issues).to eq(['WEB-128', 'WEB-129'])
70
+ end
71
+
72
+ it 'can split transition field from other fields' do
73
+ json = File.read("#{File.dirname(__FILE__)}/support/transitions.all.json")
74
+ url = "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/WEB-130/transitions"
75
+ transition_data = { assignee: { name: 'username' }, summary: 'new_summary' }
76
+ fields = { colour: 'red', customfield_11005: 'example' }
77
+
78
+ allow_any_instance_of(JIRA::Base).to receive(:self).and_return(url)
79
+ stub = stub_request(:get, "#{url}/transitions?expand=transitions.fields").
80
+ to_return(body: json)
81
+ result = plugin.split_transition_fields(plugin.api.Issue.build, 2, transition_data.merge(fields))
82
+
83
+ expect(stub).to have_been_requested.once
84
+ expect(result).to eq({ transition_fields: transition_data, other_fields: fields })
85
+ end
86
+
87
+ it 'can transition an issue' do
88
+ expected_json = '{"transition":{"id":"2"},"fields":{"assignee":{"name":"username"},"customfield_11005":"example"}}'
89
+ url = "#{ENV['DANGER_JIRA_URL']}/rest/api/2/issue/WEB-131/transitions"
90
+ issue = plugin.api.Issue.build
91
+
92
+ allow(issue).to receive(:key_value).and_return('WEB-131')
93
+ stub = stub_request(:post, url).
94
+ with(body: expected_json)
95
+ plugin.transition(issue, 2, assignee: { name: 'username' }, customfield_11005: 'example')
96
+
97
+ expect(stub).to have_been_requested.once
98
+ end
99
+ end
100
+ end
101
+ end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-yajp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - juliendms
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jira-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.11
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.11
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.16'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.16'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '4.7'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '4.7'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Synchronize your Jira issues with your PR/MR, and more.
168
+ email:
169
+ - j-dumas@live.fr
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".github/workflows/gem-push.yml"
175
+ - ".gitignore"
176
+ - ".rubocop.yml"
177
+ - ".travis.yml"
178
+ - Gemfile
179
+ - Gemfile.lock
180
+ - Guardfile
181
+ - LICENSE
182
+ - README.md
183
+ - Rakefile
184
+ - danger-yajp.gemspec
185
+ - lib/danger_plugin.rb
186
+ - lib/danger_yajp.rb
187
+ - lib/yajp/gem_version.rb
188
+ - lib/yajp/plugin.rb
189
+ - spec/spec_helper.rb
190
+ - spec/support/transitions.all.json
191
+ - spec/yajp_spec.rb
192
+ homepage: https://github.com/juliendms/danger-yajp
193
+ licenses:
194
+ - MIT
195
+ metadata: {}
196
+ post_install_message:
197
+ rdoc_options: []
198
+ require_paths:
199
+ - lib
200
+ required_ruby_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: 2.6.0
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ requirements: []
211
+ rubygems_version: 3.0.3
212
+ signing_key:
213
+ specification_version: 4
214
+ summary: Yet Another Jira Plugin is a danger plugin to find issues, access their parameters
215
+ and perform operations on them.
216
+ test_files:
217
+ - spec/spec_helper.rb
218
+ - spec/support/transitions.all.json
219
+ - spec/yajp_spec.rb