danger 5.9.1 → 5.10.0

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: 8ca8eae46b86048ebe87922217dd3f833f70dbfc67287e216c8361039d30aa1e
4
- data.tar.gz: 9ca45aa70428acc760231c4f31d89a1c841c07003057bb05fb68c418dcb38d9c
3
+ metadata.gz: 8b735e38e22bfb612463d63cad891c3518dcb0849f4dacc50efb63df75f3414a
4
+ data.tar.gz: 63dcbbda47a2e018a1a77f767b36f6308d93d3b2fec471c152fb0652e4650ef9
5
5
  SHA512:
6
- metadata.gz: 134880b979d81ecde590364d6a3d4cdccb14eae30181106c6758fc5fa9e580f49346b46b129d054b6443e975c7305738669bb790ca0674548919f9e40c6ca68e
7
- data.tar.gz: 6e5ca5931209b7231aa048fba656aa58096a468bf6446fe39dc313fd943e89196dea4f49fe285228f635afae7b42db6a0678a5449676c7e4664c9454fc2cddef
6
+ metadata.gz: c8ba3c1cd20528a1a00e3d3d95995eaf5db5eb20396eaf9d380eb532e851a62cbcabf5c4565f8dcefab55ef80738693d3dc973eaeecb8edb1fa681f9879472c2
7
+ data.tar.gz: '049c8b22d48906ce65182e75c8c7240e8c46252a23d5f366f1f8a91dac393713de70a5507b4b0e4b4128f01e8cdff35dbf8d392787461bcef026a518ef9fa330'
@@ -33,7 +33,7 @@ module Danger
33
33
  end
34
34
 
35
35
  def supported_request_sources
36
- @supported_request_sources ||= [Danger::RequestSources::GitHub]
36
+ @supported_request_sources ||= [Danger::RequestSources::GitHub, Danger::RequestSources::BitbucketServer]
37
37
  end
38
38
 
39
39
  def initialize(env = {})
@@ -89,7 +89,9 @@ module Danger
89
89
  PullRequestFinder.new(
90
90
  remote_info.id,
91
91
  remote_info.slug,
92
- remote: true
92
+ remote: true,
93
+ remote_url: env["LOCAL_GIT_PR_URL"],
94
+ env: env
93
95
  ).call
94
96
  else
95
97
  PullRequestFinder.new(
@@ -8,16 +8,39 @@ module Danger
8
8
  (/(pull|merge_requests|pull-requests)/)
9
9
  (?<id>\d+)
10
10
  }x
11
+
12
+ # Regex used to extract info from Bitbucket server URLs, as they use a quite different format
13
+ REGEXPBB = %r{
14
+ (?:[\/:])projects
15
+ \/([^\/.]+)
16
+ \/repos\/([^\/.]+)
17
+ \/pull-requests
18
+ \/(\d+)
19
+ }x
20
+
21
+ # Regex used to extract info from Bitbucket server URLs, as they use a quite different format
22
+ REGEXPBB = %r{
23
+ (?:[\/:])projects
24
+ \/([^\/.]+)
25
+ \/repos\/([^\/.]+)
26
+ \/pull-requests
27
+ \/(\d+)
28
+ }x
11
29
 
12
30
  def initialize(url)
13
31
  @url = url
14
32
  end
15
33
 
16
34
  def call
17
- matched = url.match(REGEXP)
35
+ matched = url.match(REGEXPBB)
18
36
 
19
37
  if matched
20
- RepoInfo.new(matched[:slug], matched[:id])
38
+ RepoInfo.new("#{matched[1]}/#{matched[2]}", matched[3])
39
+ else
40
+ matched = url.match(REGEXP)
41
+ if matched
42
+ RepoInfo.new(matched[:slug], matched[:id])
43
+ end
21
44
  end
22
45
  end
23
46
 
@@ -4,11 +4,13 @@ require "danger/ci_source/support/no_pull_request"
4
4
 
5
5
  module Danger
6
6
  class PullRequestFinder
7
- def initialize(specific_pull_request_id, repo_slug = nil, remote: false, git_logs: "")
7
+ def initialize(specific_pull_request_id, repo_slug = nil, remote: false, git_logs: "", remote_url: "", env: nil)
8
8
  @specific_pull_request_id = specific_pull_request_id
9
9
  @git_logs = git_logs
10
10
  @repo_slug = repo_slug
11
11
  @remote = to_boolean(remote)
12
+ @remote_url = remote_url
13
+ @env = env
12
14
  end
13
15
 
14
16
  def call
@@ -19,7 +21,7 @@ module Danger
19
21
 
20
22
  private
21
23
 
22
- attr_reader :specific_pull_request_id, :git_logs, :repo_slug, :remote
24
+ attr_reader :specific_pull_request_id, :git_logs, :repo_slug, :remote, :remote_url, :env
23
25
 
24
26
  def to_boolean(maybe_string)
25
27
  ["true", "1", "yes", "y", true].include?(maybe_string)
@@ -47,11 +49,7 @@ module Danger
47
49
  elsif only_squash_and_merged_pull_request_present?
48
50
  LocalPullRequest.new(most_recent_squash_and_merged_pull_request)
49
51
  elsif remote && remote_pull_request
50
- RemotePullRequest.new(
51
- remote_pull_request.number.to_s,
52
- remote_pull_request.head.sha,
53
- remote_pull_request.base.sha
54
- )
52
+ generate_remote_pull_request
55
53
  else
56
54
  NoPullRequest.new
57
55
  end
@@ -63,6 +61,22 @@ module Danger
63
61
  !specific_pull_request_id.empty? ? "##{specific_pull_request_id}" : "#\\d+".freeze
64
62
  end
65
63
 
64
+ def generate_remote_pull_request
65
+ if remote_url =~ %r{/pull-requests/}
66
+ RemotePullRequest.new(
67
+ remote_pull_request[:id].to_s,
68
+ remote_pull_request[:fromRef][:latestCommit],
69
+ remote_pull_request[:toRef][:latestCommit]
70
+ )
71
+ else
72
+ RemotePullRequest.new(
73
+ remote_pull_request.number.to_s,
74
+ remote_pull_request.head.sha,
75
+ remote_pull_request.base.sha
76
+ )
77
+ end
78
+ end
79
+
66
80
  def remote_pull_request
67
81
  @_remote_pull_request ||= begin
68
82
  client.pull_request(repo_slug, specific_pull_request_id)
@@ -111,8 +125,14 @@ module Danger
111
125
  end
112
126
 
113
127
  def client
114
- require "octokit"
115
- Octokit::Client.new(access_token: ENV["DANGER_GITHUB_API_TOKEN"], api_endpoint: api_url)
128
+ if remote_url =~ %r{/pull-requests/}
129
+ require "danger/request_sources/bitbucket_server_api"
130
+ project, slug = repo_slug.split("/")
131
+ RequestSources::BitbucketServerAPI.new(project, slug, specific_pull_request_id, env)
132
+ else
133
+ require "octokit"
134
+ Octokit::Client.new(access_token: ENV["DANGER_GITHUB_API_TOKEN"], api_endpoint: api_url)
135
+ end
116
136
  end
117
137
 
118
138
  def api_url
@@ -10,16 +10,21 @@ module Danger
10
10
  def setup(verbose: false)
11
11
  source = dm.env.ci_source
12
12
  if source.nil? or source.repo_slug.empty?
13
- cork.puts "danger local failed because it only works with GitHub projects at the moment. Sorry.".red
13
+ cork.puts "danger local failed because it only works with GitHub and Bitbucket server projects at the moment. Sorry.".red
14
14
  exit 0
15
15
  end
16
-
17
16
  gh = dm.env.request_source
18
17
  # We can use tokenless here, as it's running on someone's computer
19
- # and is IP locked, as opposed to on the CI.
20
- gh.support_tokenless_auth = true
18
+ # and is IP locked, as opposed to on the CI. Only for Github PRs
19
+ if gh.instance_of? Danger::RequestSources::GitHub
20
+ gh.support_tokenless_auth = true
21
+ end
21
22
 
22
- cork.puts "Running your Dangerfile against this PR - https://#{gh.host}/#{source.repo_slug}/pull/#{source.pull_request_id}"
23
+ if gh.instance_of? Danger::RequestSources::BitbucketServer
24
+ cork.puts "Running your Dangerfile against this PR - #{gh.host}/projects/#{source.repo_slug.split('/').first}/repos/#{source.repo_slug.split('/').last}/pull-requests/#{source.pull_request_id}"
25
+ else
26
+ cork.puts "Running your Dangerfile against this PR - https://#{gh.host}/#{source.repo_slug}/pull/#{source.pull_request_id}"
27
+ end
23
28
 
24
29
  unless verbose
25
30
  cork.puts "Turning on --verbose"
@@ -31,6 +31,10 @@ module Danger
31
31
  @username && !@username.empty? && @password && !@password.empty?
32
32
  end
33
33
 
34
+ def pull_request(*)
35
+ fetch_pr_json
36
+ end
37
+
34
38
  def fetch_pr_json
35
39
  uri = URI(pr_api_endpoint)
36
40
  fetch_json(uri)
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "5.9.1".freeze
2
+ VERSION = "5.10.0".freeze
3
3
  DESCRIPTION = "Like Unit Tests, but for your Team Culture.".freeze
4
4
  end
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: 5.9.1
4
+ version: 5.10.0
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: 2018-12-09 00:00:00.000000000 Z
12
+ date: 2018-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide