danger-jira_sync 0.0.3 → 0.0.4
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/Gemfile.lock +1 -1
- data/lib/jira_sync/gem_version.rb +1 -1
- data/lib/jira_sync/plugin.rb +14 -2
- data/spec/jira_sync_spec.rb +83 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fce89991967105fa855239f168ddcd39023c05f3a864602c0f73d625fdcf182
|
4
|
+
data.tar.gz: add9884c0ce2306212d0ac502cf20b1ab9f3d1c70d25b1ec14fa884aba97b881
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9e4d1cf4d8409f002d014e10ab3dabf0c0932c31171b24d3f0b92cb0e6772980ede2f405358cb1cb9ab4c089f9f73e793e76134b91efd4906979c6d91bf2f8a
|
7
|
+
data.tar.gz: e5403bd45a24ff908279a7e4c0f4d3397531318bd87fcca8b5ae2288d33d8fcea9a3eaadf38636789475d3fedb6023f7c1efb9ec5bf4556eb3c585820515aef2
|
data/Gemfile.lock
CHANGED
data/lib/jira_sync/plugin.rb
CHANGED
@@ -76,7 +76,7 @@ module Danger
|
|
76
76
|
return if labels.empty?
|
77
77
|
|
78
78
|
create_missing_github_labels(labels)
|
79
|
-
|
79
|
+
add_labels_to_issue(labels)
|
80
80
|
|
81
81
|
labels
|
82
82
|
end
|
@@ -93,6 +93,8 @@ module Danger
|
|
93
93
|
|
94
94
|
def github_labels
|
95
95
|
@github_labels ||= github.api.labels(repo)
|
96
|
+
rescue Octokit::Error => e
|
97
|
+
warn "#{e.response_status} Error while retrieving GitHub labels: #{e.message}"
|
96
98
|
end
|
97
99
|
|
98
100
|
def extract_issue_keys_from_pull_request(key_prefixes)
|
@@ -126,9 +128,19 @@ module Danger
|
|
126
128
|
missing_labels = labels - github_labels
|
127
129
|
missing_labels.each do |label|
|
128
130
|
color = SecureRandom.hex(3)
|
129
|
-
|
131
|
+
begin
|
132
|
+
github.api.add_label(repo, label, color)
|
133
|
+
rescue Octokit::Error => e
|
134
|
+
warn "#{e.response_status} Error while creating GitHub label \"#{label}\" with color \"#{color}\": #{e.message}"
|
135
|
+
end
|
130
136
|
end
|
131
137
|
missing_labels
|
132
138
|
end
|
139
|
+
|
140
|
+
def add_labels_to_issue(labels)
|
141
|
+
github.api.add_labels_to_an_issue(repo, issue_number, labels)
|
142
|
+
rescue Octokit::Error => e
|
143
|
+
warn "#{e.response_status} Error while adding labels [#{labels}] to GitHub issue: #{e.message}"
|
144
|
+
end
|
133
145
|
end
|
134
146
|
end
|
data/spec/jira_sync_spec.rb
CHANGED
@@ -124,10 +124,7 @@ RSpec.describe Danger::DangerJiraSync do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
context "after calling #configure" do
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
let(:github_api_mock) { GitHubAPIMock.new }
|
127
|
+
let(:github_api_mock) { Object.new }
|
131
128
|
|
132
129
|
before do
|
133
130
|
plugin.configure(jira_settings)
|
@@ -217,6 +214,16 @@ RSpec.describe Danger::DangerJiraSync do
|
|
217
214
|
expect(labels).to include(*pr_title_related_project_keys)
|
218
215
|
end
|
219
216
|
|
217
|
+
it "creates no warnings in the default case" do
|
218
|
+
stub_github_api_labelling
|
219
|
+
|
220
|
+
VCR.use_cassette(:default_success, record: :new_episodes) do
|
221
|
+
plugin.autolabel_pull_request(issue_prefixes)
|
222
|
+
end
|
223
|
+
|
224
|
+
expect(dangerfile.status_report[:warnings].count).to eq(0)
|
225
|
+
end
|
226
|
+
|
220
227
|
it "creates a warning when a related Jira ticket cannot be fetched" do
|
221
228
|
stub_jira_find_issue_404
|
222
229
|
|
@@ -245,6 +252,78 @@ RSpec.describe Danger::DangerJiraSync do
|
|
245
252
|
expect(issue_warning_count).to eq(1)
|
246
253
|
end
|
247
254
|
|
255
|
+
it "creates a warning when it cannot create a github label" do
|
256
|
+
stub_github_api_labelling
|
257
|
+
|
258
|
+
error = Octokit::Error.from_response({
|
259
|
+
method: "POST",
|
260
|
+
url: "https://www.example.com/",
|
261
|
+
status: 422,
|
262
|
+
documentation_url: "https://developer.github.com/v3/issues/labels/#create-a-label",
|
263
|
+
message: <<~HEREDOC
|
264
|
+
resource: Label
|
265
|
+
code: already_exists
|
266
|
+
field: name
|
267
|
+
HEREDOC
|
268
|
+
})
|
269
|
+
|
270
|
+
expect(github_api_mock).to receive(:add_label).and_raise(error)
|
271
|
+
expect(dangerfile.status_report[:warnings].count).to eq(0), "preconditions"
|
272
|
+
|
273
|
+
VCR.use_cassette(:default_success, record: :new_episodes) do
|
274
|
+
plugin.autolabel_pull_request(issue_prefixes)
|
275
|
+
end
|
276
|
+
|
277
|
+
expected_missing_label_count = 1
|
278
|
+
expect(dangerfile.status_report[:warnings].count).to eq(expected_missing_label_count)
|
279
|
+
end
|
280
|
+
|
281
|
+
it "creates a warning when it cannot fetch existing github labels" do
|
282
|
+
stub_github_api_labelling
|
283
|
+
|
284
|
+
error = Octokit::Error.from_response({
|
285
|
+
method: "GET",
|
286
|
+
url: "https://www.example.com/",
|
287
|
+
status: 503,
|
288
|
+
documentation_url: "https://developer.github.com/v3/issues/labels/#create-a-label",
|
289
|
+
message: "Forbidden"
|
290
|
+
})
|
291
|
+
|
292
|
+
expect(github_api_mock).to receive(:add_labels_to_an_issue).and_raise(error)
|
293
|
+
expect(dangerfile.status_report[:warnings].count).to eq(0), "preconditions"
|
294
|
+
|
295
|
+
VCR.use_cassette(:default_success, record: :new_episodes) do
|
296
|
+
plugin.autolabel_pull_request(issue_prefixes)
|
297
|
+
end
|
298
|
+
|
299
|
+
expect(dangerfile.status_report[:warnings].count).to eq(1)
|
300
|
+
end
|
301
|
+
|
302
|
+
it "creates a warning when it cannot add a label to an existing github issue" do
|
303
|
+
stub_github_api_labelling
|
304
|
+
|
305
|
+
error = Octokit::Error.from_response({
|
306
|
+
method: "POST",
|
307
|
+
url: "https://www.example.com/",
|
308
|
+
status: 422,
|
309
|
+
documentation_url: "https://developer.github.com/v3/issues/labels/#create-a-label",
|
310
|
+
message: <<~HEREDOC
|
311
|
+
resource: Label
|
312
|
+
code: already_exists
|
313
|
+
field: name
|
314
|
+
HEREDOC
|
315
|
+
})
|
316
|
+
|
317
|
+
expect(github_api_mock).to receive(:add_label).and_raise(error)
|
318
|
+
expect(dangerfile.status_report[:warnings].count).to eq(0), "preconditions"
|
319
|
+
|
320
|
+
VCR.use_cassette(:default_success, record: :new_episodes) do
|
321
|
+
plugin.autolabel_pull_request(issue_prefixes)
|
322
|
+
end
|
323
|
+
|
324
|
+
expect(dangerfile.status_report[:warnings].count).to eq(1)
|
325
|
+
end
|
326
|
+
|
248
327
|
it "adds a label to the github issue for each related jira issue component name" do
|
249
328
|
pr_title_related_component_names.each do |component_name|
|
250
329
|
expect(github_api_mock).to receive(:add_label).with(anything, component_name, anything).once.and_return(nil)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-jira_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Menesini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-plugin-api
|