danger-jira_sync 0.0.5 → 0.0.6

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: 3676486d775890e8168b4c19fcb0723753c638abc1bbf234c305a389fcc74ac3
4
- data.tar.gz: 29a78685c72621bc10e6100a9606e9c674e8d7e6e3858a23f77078e4f049f18c
3
+ metadata.gz: b11f9ef73bd5db3c5d26b38c5fa285ad6d958bc28d8ea0c1143f3c5d4d1b650e
4
+ data.tar.gz: aabfa9cd7a266af8cdf860d0ec44c55db61a1300e09909600ca3556b4bf01d45
5
5
  SHA512:
6
- metadata.gz: 5779baee09ceb623ccd21a4adf03b4621f4e119c84321095bd2ee59c8fdcbdbf9651e41f51a24350acccfb8adbb134c82dd0dc13974b640bb0d69cc0955e0ed2
7
- data.tar.gz: 77208ea90084bcb5da9e548001db1f4a777cf55eb4d2ec6f8e45125427bd8c1c267744443447d7199870381e6bb9b6af380c482b1df918588f436bc505bdc1b5
6
+ metadata.gz: e00eb94c4cdee985fcd70cdc0d12680e268ebbad0e8e9849e7fe2a1c47c055d393df8de41664892abc2622817ce4c00816c69d43e12fdc5e803fec939fa5e6a9
7
+ data.tar.gz: 397899d6534b6020747fa15715a22b9b82aaa4538058bb532498d3250f9e555626cae94367f1f033fbfa8dfe36f6a21ee560be47173e475bb2c5050f4c8df7dd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-jira_sync (0.0.5)
4
+ danger-jira_sync (0.0.6)
5
5
  danger-plugin-api (~> 1.0)
6
6
  jira-ruby (~> 1.5.0)
7
7
 
data/README.md CHANGED
@@ -62,6 +62,6 @@ Labels the Pull Request with Jira Project Keys and Component Names
62
62
 
63
63
  # **:warning: Do not commit fixtures with your credentials in them :warning:**
64
64
 
65
- Before committing, check to see if you have created or changed any fixtures in `/spec/fixtures/vcr_cassettes`. If you have, it is likely that the changed file contains your credentials. Manually remove your credentials from these fixture files
65
+ Before committing, check to see if you have created or changed any fixtures in `/spec/fixtures/vcr_cassettes`. If you have, it is possible that the changed file contains your credentials. Manually remove your credentials from these fixture files
66
66
 
67
67
  When a new HTTP request is made that [VCR](https://github.com/vcr/vcr) hasn't seen before, it will record the response from the server and play it back in subsequent HTTP requests to the same URL with the same headers. This means that if a new request is made in the tests, it will actually make a request to the server in order to record the response. For this reason, development should be done within testing environments in GitHub and Jira Cloud
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JiraSync
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.6"
5
5
  end
@@ -138,7 +138,9 @@ module Danger
138
138
  end
139
139
 
140
140
  def add_labels_to_issue(labels)
141
- github.api.add_labels_to_an_issue(repo, issue_number, labels)
141
+ existing_labels = github.api.labels_for_issue(repo, issue_number).map { |label| label[:name] }
142
+ new_labels = labels - existing_labels
143
+ github.api.add_labels_to_an_issue(repo, issue_number, new_labels) unless new_labels.empty?
142
144
  rescue Octokit::Error => e
143
145
  warn "#{e.response_status} Error while adding labels [#{labels}] to GitHub issue: #{e.message}"
144
146
  end
@@ -146,6 +146,7 @@ RSpec.describe Danger::DangerJiraSync do
146
146
  def stub_github_api_labelling(labels: [])
147
147
  allow(github_api_mock).to receive(:labels).and_return(github_labels_response(labels))
148
148
  allow(github_api_mock).to receive(:add_label).and_return(nil)
149
+ allow(github_api_mock).to receive(:labels_for_issue).and_return([])
149
150
  allow(github_api_mock).to receive(:add_labels_to_an_issue).and_return(nil)
150
151
 
151
152
  allow(plugin.github).to receive(:api).and_return(github_api_mock)
@@ -312,6 +313,27 @@ RSpec.describe Danger::DangerJiraSync do
312
313
  expect(dangerfile.status_report[:warnings].count).to eq(1)
313
314
  end
314
315
 
316
+ it "creates a warning when it cannot fetch labels for the related pr" do
317
+ stub_github_api_labelling
318
+
319
+ error = Octokit::Error.from_response({
320
+ method: "GET",
321
+ url: "https://www.example.com/",
322
+ status: 503,
323
+ documentation_url: "https://developer.github.com/v3/issues/labels/#create-a-label",
324
+ message: "Forbidden"
325
+ })
326
+
327
+ expect(github_api_mock).to receive(:labels_for_issue).and_raise(error)
328
+ expect(dangerfile.status_report[:warnings].count).to eq(0), "preconditions"
329
+
330
+ VCR.use_cassette(:default_success, record: :new_episodes) do
331
+ plugin.autolabel_pull_request(issue_prefixes)
332
+ end
333
+
334
+ expect(dangerfile.status_report[:warnings].count).to eq(1)
335
+ end
336
+
315
337
  it "creates a warning when it cannot fetch existing github labels" do
316
338
  stub_github_api_labelling
317
339
 
@@ -359,6 +381,17 @@ RSpec.describe Danger::DangerJiraSync do
359
381
  end
360
382
  end
361
383
 
384
+ it "does not add existing labels to the github pr" do
385
+ expect(github_api_mock).to receive(:labels_for_issue).once.and_return github_labels_response(%w(DEV))
386
+ expect(github_api_mock).to receive(:add_labels_to_an_issue).with(anything, anything, %w(ComponentA ComponentC ABC ComponentB)).once
387
+
388
+ stub_github_api_labelling
389
+
390
+ VCR.use_cassette(:default_success, record: :new_episodes) do
391
+ plugin.autolabel_pull_request(issue_prefixes)
392
+ end
393
+ end
394
+
362
395
  it "adds missing github labels" do
363
396
  labels = pr_title_project_keys + pr_title_related_component_names
364
397
  labels.each do |label|
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.5
4
+ version: 0.0.6
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-28 00:00:00.000000000 Z
11
+ date: 2018-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api