danger 6.0.2 → 6.0.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ed2cdc61eed91524dbc037cc0b4109298a59f79bae857ab9ab4fb91f9f16d17
|
4
|
+
data.tar.gz: 59ddea79d36ee0dca6664f1ed3ce654e88bebfb70ed9f43ed5948d7bee11349f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ed19550308a3957a370beab7524037eec4760f4c08664c7f4283ca647b2c10a909a9cf7aab934dd65b9ff518cb7f72d2ce51b2c1f4703c2c6b7fd1f061dd1b6
|
7
|
+
data.tar.gz: 99784fe747487d86ccbe6e65ac320ac5fbdcfab8818128f4c453c1161a7517b738f7611da988e1825e61d7613b96f946d412e8ea0ba71cf80c38cd784adfdac5
|
@@ -8,9 +8,11 @@ module Danger
|
|
8
8
|
# ```
|
9
9
|
#
|
10
10
|
# #### Token Setup
|
11
|
-
#
|
12
|
-
# Add `DANGER_BITBUCKETCLOUD_USERNAME` and `DANGER_BITBUCKETCLOUD_USERNAME` to your pipeline repository variable
|
13
|
-
#
|
11
|
+
#
|
12
|
+
# Add `DANGER_BITBUCKETCLOUD_USERNAME` and `DANGER_BITBUCKETCLOUD_USERNAME` to your pipeline repository variable
|
13
|
+
# or instead using `DANGER_BITBUCKETCLOUD_OAUTH_KEY` and `DANGER_BITBUCKETCLOUD_OAUTH_SECRET`.
|
14
|
+
#
|
15
|
+
# You can find them in Settings > Pipelines > Repository Variables
|
14
16
|
|
15
17
|
class BitbucketPipelines < CI
|
16
18
|
|
@@ -42,11 +42,19 @@ module Danger
|
|
42
42
|
#
|
43
43
|
# You will need to add the following environment variables as build parameters or by exporting them inside your
|
44
44
|
# Simple Command Runner.
|
45
|
-
#
|
46
|
-
#
|
45
|
+
#
|
46
|
+
#
|
47
47
|
# - `BITBUCKET_REPO_SLUG`
|
48
48
|
# - `BITBUCKET_REPO_URL`
|
49
49
|
#
|
50
|
+
# - `DANGER_BITBUCKETCLOUD_USERNAME`
|
51
|
+
# - `DANGER_BITBUCKETCLOUD_PASSWORD`
|
52
|
+
#
|
53
|
+
# or
|
54
|
+
#
|
55
|
+
# - `DANGER_BITBUCKETCLOUD_OAUTH_KEY`
|
56
|
+
# - `DANGER_BITBUCKETCLOUD_OAUTH_SECRET`
|
57
|
+
#
|
50
58
|
# You will also need to set the `BITBUCKET_BRANCH_NAME` environment variable.
|
51
59
|
# TeamCity provides `%teamcity.build.branch%`, which you can use at the top of your Simple Command Runner:
|
52
60
|
# ```sh
|
@@ -57,6 +65,7 @@ module Danger
|
|
57
65
|
#
|
58
66
|
# You will need to add the following environment variables as build parameters or by exporting them inside your
|
59
67
|
# Simple Command Runner.
|
68
|
+
#
|
60
69
|
# - `DANGER_BITBUCKETSERVER_USERNAME`
|
61
70
|
# - `DANGER_BITBUCKETSERVER_PASSWORD`
|
62
71
|
# - `DANGER_BITBUCKETSERVER_HOST`
|
@@ -5,12 +5,13 @@ require "danger/helpers/comments_helper"
|
|
5
5
|
module Danger
|
6
6
|
module RequestSources
|
7
7
|
class BitbucketCloudAPI
|
8
|
-
attr_accessor :host, :project, :slug, :pull_request_id
|
8
|
+
attr_accessor :host, :project, :slug, :access_token, :pull_request_id
|
9
9
|
|
10
10
|
def initialize(repo_slug, pull_request_id, branch_name, environment)
|
11
11
|
@username = environment["DANGER_BITBUCKETCLOUD_USERNAME"]
|
12
12
|
@password = environment["DANGER_BITBUCKETCLOUD_PASSWORD"]
|
13
13
|
self.project, self.slug = repo_slug.split("/")
|
14
|
+
self.access_token = fetch_access_token(environment)
|
14
15
|
self.pull_request_id = pull_request_id || fetch_pr_from_branch(branch_name)
|
15
16
|
self.host = "https://bitbucket.org/"
|
16
17
|
end
|
@@ -77,11 +78,32 @@ module Danger
|
|
77
78
|
fetch_json(uri)[:values][0][:id]
|
78
79
|
end
|
79
80
|
|
81
|
+
def fetch_access_token(environment)
|
82
|
+
oauth_key = environment["DANGER_BITBUCKETCLOUD_OAUTH_KEY"]
|
83
|
+
oauth_secret = environment["DANGER_BITBUCKETCLOUD_OAUTH_SECRET"]
|
84
|
+
return nil if oauth_key.nil?
|
85
|
+
return nil if oauth_secret.nil?
|
86
|
+
|
87
|
+
uri = URI.parse("https://bitbucket.org/site/oauth2/access_token")
|
88
|
+
req = Net::HTTP::Post.new(uri.request_uri, { "Content-Type" => "application/json" })
|
89
|
+
req.basic_auth oauth_key, oauth_secret
|
90
|
+
req.set_form_data({'grant_type' => 'client_credentials'})
|
91
|
+
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
92
|
+
http.request(req)
|
93
|
+
end
|
94
|
+
|
95
|
+
JSON.parse(res.body, symbolize_names: true)[:access_token]
|
96
|
+
end
|
97
|
+
|
80
98
|
def fetch_json(uri)
|
81
99
|
raise credentials_not_available unless credentials_given?
|
82
100
|
|
83
101
|
req = Net::HTTP::Get.new(uri.request_uri, { "Content-Type" => "application/json" })
|
84
|
-
|
102
|
+
if access_token.nil?
|
103
|
+
req.basic_auth @username, @password
|
104
|
+
else
|
105
|
+
req["Authorization"] = "Bearer #{access_token}"
|
106
|
+
end
|
85
107
|
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
86
108
|
http.request(req)
|
87
109
|
end
|
@@ -94,7 +116,11 @@ module Danger
|
|
94
116
|
raise credentials_not_available unless credentials_given?
|
95
117
|
|
96
118
|
req = Net::HTTP::Post.new(uri.request_uri, { "Content-Type" => "application/json" })
|
97
|
-
|
119
|
+
if access_token.nil?
|
120
|
+
req.basic_auth @username, @password
|
121
|
+
else
|
122
|
+
req["Authorization"] = "Bearer #{access_token}"
|
123
|
+
end
|
98
124
|
req.body = body
|
99
125
|
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
100
126
|
http.request(req)
|
@@ -105,7 +131,11 @@ module Danger
|
|
105
131
|
raise credentials_not_available unless credentials_given?
|
106
132
|
|
107
133
|
req = Net::HTTP::Delete.new(uri.request_uri, { "Content-Type" => "application/json" })
|
108
|
-
|
134
|
+
if access_token.nil?
|
135
|
+
req.basic_auth @username, @password
|
136
|
+
else
|
137
|
+
req["Authorization"] = "Bearer #{access_token}"
|
138
|
+
end
|
109
139
|
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
110
140
|
http.request(req)
|
111
141
|
end
|
data/lib/danger/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.
|
4
|
+
version: 6.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Orta Therox
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-04-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: claide
|