danger 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assets/DangerfileTemplate +2 -2
- data/lib/danger/ci_source/buildkite.rb +30 -18
- data/lib/danger/ci_source/ci_source.rb +31 -29
- data/lib/danger/ci_source/circle.rb +57 -37
- data/lib/danger/ci_source/drone.rb +32 -17
- data/lib/danger/ci_source/jenkins.rb +29 -17
- data/lib/danger/ci_source/local_git_repo.rb +43 -45
- data/lib/danger/ci_source/semaphore.rb +23 -17
- data/lib/danger/ci_source/surf.rb +26 -15
- data/lib/danger/ci_source/teamcity.rb +36 -17
- data/lib/danger/ci_source/travis.rb +39 -18
- data/lib/danger/ci_source/xcode_server.rb +32 -19
- data/lib/danger/commands/runner.rb +1 -0
- data/lib/danger/commands/systems.rb +41 -0
- data/lib/danger/danger_core/environment_manager.rb +14 -16
- data/lib/danger/danger_core/executor.rb +31 -22
- data/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb +15 -1
- data/lib/danger/danger_core/plugins/dangerfile_github_plugin.rb +19 -7
- data/lib/danger/helpers/comments_helper.rb +105 -0
- data/lib/danger/plugin_support/plugin_file_resolver.rb +1 -1
- data/lib/danger/plugin_support/plugin_parser.rb +2 -2
- data/lib/danger/plugin_support/templates/readme_table.html.erb +3 -1
- data/lib/danger/request_source/github.rb +6 -94
- data/lib/danger/request_source/request_source.rb +2 -1
- data/lib/danger/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f22b32cdbaacb907e107d068b7533f4721b0ea9a
|
4
|
+
data.tar.gz: 8d7d99a8229047d542486c2e6a5208cee52d027b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 917ba759a6a42184ce38f1dc72bb543981830896fb15757bb8a0619a71a411922583a4f8d2610f04d0a37bacd338192a9b8539bec922d873f5e88764ac3d455c
|
7
|
+
data.tar.gz: fd38930629b2e39026f07b9371dc15ba81582223b141a05cc2c985f5085d719265d2e36984f56dad351a54999a98f2783ab5f5426f6827ed854a94d151b09df4
|
@@ -9,5 +9,5 @@ warn("PR is classed as Work in Progress") if github.pr_title.include? "[WIP]"
|
|
9
9
|
warn("Big PR") if git.lines_of_code > 500
|
10
10
|
|
11
11
|
# Don't let testing shortcuts get into master by accident
|
12
|
-
fail("fdescribe left in tests") if `grep -r fdescribe specs
|
13
|
-
fail("fit left in tests") if `grep -r
|
12
|
+
fail("fdescribe left in tests") if `grep -r fdescribe specs/ `.length > 1
|
13
|
+
fail("fit left in tests") if `grep -r fit specs/ `.length > 1
|
@@ -2,28 +2,40 @@
|
|
2
2
|
# https://buildkite.com/docs/guides/environment-variables
|
3
3
|
|
4
4
|
module Danger
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
# ### CI Setup
|
6
|
+
#
|
7
|
+
# With BuildKite you run the server yourself, so you will want to run it as a part of your build process.
|
8
|
+
# It is common to have build steps, so we would recommend adding this to your scrip:
|
9
|
+
#
|
10
|
+
# ``` shell
|
11
|
+
# echo "--- Running Danger"
|
12
|
+
# bundle exec danger
|
13
|
+
# ```
|
14
|
+
#
|
15
|
+
# ### Token Setup
|
16
|
+
#
|
17
|
+
# As this is self-hosted, you will need to add the `DANGER_GITHUB_API_TOKEN` to your build user's ENV. The alternative
|
18
|
+
# is to pass in the token as a prefix to the command `DANGER_GITHUB_API_TOKEN="123" bundle exec danger`.
|
19
|
+
#
|
20
|
+
class Buildkite < CI
|
21
|
+
def self.validates_as_ci?(env)
|
22
|
+
env.key? "BUILDKITE"
|
23
|
+
end
|
12
24
|
|
13
|
-
|
14
|
-
|
25
|
+
def self.validates_as_pr?(env)
|
26
|
+
["BUILDKITE_PULL_REQUEST_REPO", "BUILDKITE_PULL_REQUEST"].all? { |x| env[x] }
|
27
|
+
end
|
15
28
|
|
16
|
-
|
17
|
-
|
18
|
-
|
29
|
+
def initialize(env)
|
30
|
+
self.repo_url = env["BUILDKITE_PULL_REQUEST_REPO"]
|
31
|
+
self.pull_request_id = env["BUILDKITE_PULL_REQUEST"]
|
19
32
|
|
20
|
-
|
21
|
-
|
22
|
-
|
33
|
+
repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/.]+)(?:.git)?$})
|
34
|
+
self.repo_slug = repo_matches[2] unless repo_matches.nil?
|
35
|
+
end
|
23
36
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
37
|
+
def supported_request_sources
|
38
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub]
|
27
39
|
end
|
28
40
|
end
|
29
41
|
end
|
@@ -1,35 +1,37 @@
|
|
1
1
|
require "set"
|
2
2
|
|
3
3
|
module Danger
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
4
|
+
# "abstract" CI class
|
5
|
+
class CI
|
6
|
+
attr_accessor :repo_slug, :pull_request_id, :repo_url, :supported_request_sources
|
7
|
+
|
8
|
+
def self.inherited(child_class)
|
9
|
+
available_ci_sources.add child_class
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.available_ci_sources
|
14
|
+
@available_ci_sources ||= Set.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def supported_request_sources
|
18
|
+
raise "CISource subclass must specify the supported request sources"
|
19
|
+
end
|
20
|
+
|
21
|
+
def supports?(request_source)
|
22
|
+
supported_request_sources.include? request_source
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.validates_as_ci?(_env)
|
26
|
+
abort "You need to include a function for #{self} for validates_as_ci?"
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.validates_as_pr?(_env)
|
30
|
+
abort "You need to include a function for #{self} for validates_as_pr?"
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(_env)
|
34
|
+
raise "Subclass and overwrite initialize"
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -3,53 +3,73 @@ require "uri"
|
|
3
3
|
require "danger/ci_source/circle_api"
|
4
4
|
|
5
5
|
module Danger
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
# ### CI Setup
|
7
|
+
#
|
8
|
+
# For setting up Circle CI, we recommend turning on "Only Build pull requests." in "Advanced Setting." Without this enabled,
|
9
|
+
# it is _really_ tricky for Danger to know whether you are in a pull request or not, as the environment metadata
|
10
|
+
# isn't reliable.
|
11
|
+
#
|
12
|
+
# With that set up, you can you add `bundle exec danger` to your `circle.yml`. If you override the default
|
13
|
+
# `test:` section, then add it as an extra step. Otherwise add a new `pre` section to the test:
|
14
|
+
#
|
15
|
+
# ``` ruby
|
16
|
+
# test:
|
17
|
+
# override:
|
18
|
+
# - bundle exec danger
|
19
|
+
# ```
|
20
|
+
#
|
21
|
+
# ### Token Setup
|
22
|
+
#
|
23
|
+
# There is no difference here for OSS vs Closed, add your `DANGER_GITHUB_API_TOKEN` to the Environment variable settings page.
|
24
|
+
#
|
25
|
+
class CircleCI < CI
|
26
|
+
def self.validates_as_ci?(env)
|
27
|
+
env.key? "CIRCLE_BUILD_NUM"
|
28
|
+
end
|
16
29
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
30
|
+
def self.validates_as_pr?(env)
|
31
|
+
return true if env["CI_PULL_REQUEST"]
|
20
32
|
|
21
|
-
|
22
|
-
|
23
|
-
|
33
|
+
# Uses the Circle API to determine if it's a PR otherwose
|
34
|
+
@circle_token = env["CIRCLE_CI_API_TOKEN"]
|
35
|
+
!pull_request_url(env).nil?
|
36
|
+
end
|
24
37
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
38
|
+
def supported_request_sources
|
39
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub]
|
40
|
+
end
|
41
|
+
|
42
|
+
def client
|
43
|
+
@client ||= CircleAPI.new(@circle_token)
|
44
|
+
end
|
29
45
|
|
30
|
-
|
31
|
-
|
46
|
+
def fetch_pull_request_url(repo_slug, build_number)
|
47
|
+
build_json = client.fetch_build(repo_slug, build_number)
|
48
|
+
build_json[:pull_request_urls].first
|
49
|
+
end
|
32
50
|
|
33
|
-
|
34
|
-
|
35
|
-
url = fetch_pull_request_url(repo_slug, env["CIRCLE_BUILD_NUM"])
|
36
|
-
end
|
51
|
+
def pull_request_url(env)
|
52
|
+
url = env["CI_PULL_REQUEST"]
|
37
53
|
|
38
|
-
|
54
|
+
if url.nil? && !env["CIRCLE_PROJECT_USERNAME"].nil? && !env["CIRCLE_PROJECT_REPONAME"].nil?
|
55
|
+
repo_slug = env["CIRCLE_PROJECT_USERNAME"] + "/" + env["CIRCLE_PROJECT_REPONAME"]
|
56
|
+
url = fetch_pull_request_url(repo_slug, env["CIRCLE_BUILD_NUM"])
|
39
57
|
end
|
40
58
|
|
41
|
-
|
42
|
-
|
59
|
+
url
|
60
|
+
end
|
61
|
+
|
62
|
+
def initialize(env)
|
63
|
+
self.repo_url = GitRepo.new.origins # CircleCI doesn't provide a repo url env variable :/
|
43
64
|
|
44
|
-
|
45
|
-
|
65
|
+
@circle_token = env["CIRCLE_CI_API_TOKEN"]
|
66
|
+
url = pull_request_url(env)
|
46
67
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
68
|
+
if URI.parse(url).path.split("/").count == 5
|
69
|
+
paths = URI.parse(url).path.split("/")
|
70
|
+
# The first one is an extra slash, ignore it
|
71
|
+
self.repo_slug = paths[1] + "/" + paths[2]
|
72
|
+
self.pull_request_id = paths[4]
|
53
73
|
end
|
54
74
|
end
|
55
75
|
end
|
@@ -1,26 +1,41 @@
|
|
1
1
|
# http://readme.drone.io/usage/variables/
|
2
2
|
|
3
3
|
module Danger
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
# ### CI Setup
|
5
|
+
#
|
6
|
+
# With Drone you run the docker images yourself, so you will want to add `bundle exec danger` at the end of
|
7
|
+
# your `.drone.yml`.
|
8
|
+
#
|
9
|
+
# ``` shell
|
10
|
+
# build:
|
11
|
+
# image: golang
|
12
|
+
# commands:
|
13
|
+
# - ...
|
14
|
+
# - bundle exec danger
|
15
|
+
# ```
|
16
|
+
#
|
17
|
+
# ### Token Setup
|
18
|
+
#
|
19
|
+
# As this is self-hosted, you will need to add the `DANGER_GITHUB_API_TOKEN` to your build user's ENV. The alternative
|
20
|
+
# is to pass in the token as a prefix to the command `DANGER_GITHUB_API_TOKEN="123" bundle exec danger`.
|
21
|
+
#
|
22
|
+
class Drone < CI
|
23
|
+
def self.validates_as_ci?(env)
|
24
|
+
env.key? "DRONE_REPO"
|
25
|
+
end
|
11
26
|
|
12
|
-
|
13
|
-
|
27
|
+
def self.validates_as_pr?(env)
|
28
|
+
env["DRONE_PULL_REQUEST"].to_i > 0
|
29
|
+
end
|
14
30
|
|
15
|
-
|
16
|
-
|
17
|
-
|
31
|
+
def supported_request_sources
|
32
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub]
|
33
|
+
end
|
18
34
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
35
|
+
def initialize(env)
|
36
|
+
self.repo_slug = env["DRONE_REPO"]
|
37
|
+
self.pull_request_id = env["DRONE_PULL_REQUEST"]
|
38
|
+
self.repo_url = GitRepo.new.origins # Drone doesn't provide a repo url env variable :/
|
24
39
|
end
|
25
40
|
end
|
26
41
|
end
|
@@ -2,27 +2,39 @@
|
|
2
2
|
# https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin
|
3
3
|
|
4
4
|
module Danger
|
5
|
-
|
6
|
-
# https://jenkins-ci.org
|
7
|
-
class Jenkins < CI
|
8
|
-
def self.validates?(env)
|
9
|
-
return false unless env["ghprbPullId"].to_i > 0
|
10
|
-
return false unless env["GIT_URL"]
|
5
|
+
# https://jenkins-ci.org
|
11
6
|
|
12
|
-
|
13
|
-
|
7
|
+
### CI Setup
|
8
|
+
#
|
9
|
+
# Ah Jenkins, so many memories. So, if you're using Jenkins, you're hosting your own environment. You
|
10
|
+
# will want to be using the [GitHub pull request builder plugin](https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin)
|
11
|
+
# in order to ensure that you have the build environment set up for PR integration.
|
12
|
+
#
|
13
|
+
# With that set up, you can edit your job to add `bundle exec danger` at the build action.
|
14
|
+
#
|
15
|
+
# ### Token Setup
|
16
|
+
#
|
17
|
+
# As you own the machine, it's up to you to add the enviroment variable for the `DANGER_GITHUB_API_TOKEN`.
|
18
|
+
#
|
19
|
+
class Jenkins < CI
|
20
|
+
def self.validates_as_ci?(env)
|
21
|
+
env.key? "JENKINS_URL"
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.validates_as_pr?(env)
|
25
|
+
["ghprbPullId"].all? { |x| env[x] }
|
26
|
+
end
|
14
27
|
|
15
|
-
|
16
|
-
|
17
|
-
|
28
|
+
def supported_request_sources
|
29
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub]
|
30
|
+
end
|
18
31
|
|
19
|
-
|
20
|
-
|
21
|
-
|
32
|
+
def initialize(env)
|
33
|
+
self.repo_url = env["GIT_URL"]
|
34
|
+
self.pull_request_id = env["ghprbPullId"]
|
22
35
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
36
|
+
repo_matches = self.repo_url.match(%r{([\/:])([^\/]+\/[^\/.]+)(?:.git)?$})
|
37
|
+
self.repo_slug = repo_matches[2] unless repo_matches.nil?
|
26
38
|
end
|
27
39
|
end
|
28
40
|
end
|
@@ -4,62 +4,60 @@ require "git"
|
|
4
4
|
require "uri"
|
5
5
|
|
6
6
|
module Danger
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
attr_accessor :base_commit, :head_commit
|
7
|
+
# ignore
|
8
|
+
class LocalGitRepo < CI
|
9
|
+
attr_accessor :base_commit, :head_commit
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def git
|
17
|
-
@git ||= GitRepo.new
|
18
|
-
end
|
11
|
+
def self.validates_as_ci?(env)
|
12
|
+
env.key? "DANGER_USE_LOCAL_GIT"
|
13
|
+
end
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
def git
|
16
|
+
@git ||= GitRepo.new
|
17
|
+
end
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
def run_git(command)
|
20
|
+
git.exec command
|
21
|
+
end
|
27
22
|
|
28
|
-
|
29
|
-
|
23
|
+
def supported_request_sources
|
24
|
+
@supported_request_sources ||= [Danger::RequestSources::GitHub]
|
25
|
+
end
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
27
|
+
def initialize(env = {})
|
28
|
+
github_host = env["DANGER_GITHUB_HOST"] || "github.com"
|
29
|
+
|
30
|
+
# get the remote URL
|
31
|
+
remote = run_git("remote show origin -n").lines.grep(/Fetch URL/)[0].split(": ", 2)[1]
|
32
|
+
if remote
|
33
|
+
remote_url_matches = remote.match(%r{#{Regexp.escape github_host}(:|/)(?<repo_slug>.+/.+?)(?:\.git)?$})
|
34
|
+
if !remote_url_matches.nil? and remote_url_matches["repo_slug"]
|
35
|
+
self.repo_slug = remote_url_matches["repo_slug"]
|
36
|
+
else
|
37
|
+
puts "Danger local requires a repository hosted on GitHub.com or GitHub Enterprise."
|
40
38
|
end
|
39
|
+
end
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
specific_pr = env["LOCAL_GIT_PR_ID"]
|
42
|
+
pr_ref = specific_pr ? "##{specific_pr}" : ""
|
43
|
+
pr_command = "log --merges --oneline"
|
45
44
|
|
46
|
-
|
47
|
-
|
45
|
+
# get the most recent PR merge
|
46
|
+
pr_merge = run_git(pr_command.strip).lines.grep(Regexp.new("Merge pull request " + pr_ref))[0]
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
48
|
+
if pr_merge.to_s.empty?
|
49
|
+
if specific_pr
|
50
|
+
raise "Could not find the pull request (#{specific_pr}) inside the git history for this repo."
|
51
|
+
else
|
52
|
+
raise "No recent pull requests found for this repo, danger requires at least one PR for the local mode."
|
55
53
|
end
|
56
|
-
|
57
|
-
self.pull_request_id = pr_merge.match("#([0-9]+)")[1]
|
58
|
-
sha = pr_merge.split(" ")[0]
|
59
|
-
parents = run_git("rev-list --parents -n 1 #{sha}").strip.split(" ")
|
60
|
-
self.base_commit = parents[0]
|
61
|
-
self.head_commit = parents[1]
|
62
54
|
end
|
55
|
+
|
56
|
+
self.pull_request_id = pr_merge.match("#([0-9]+)")[1]
|
57
|
+
sha = pr_merge.split(" ")[0]
|
58
|
+
parents = run_git("rev-list --parents -n 1 #{sha}").strip.split(" ")
|
59
|
+
self.base_commit = parents[0]
|
60
|
+
self.head_commit = parents[1]
|
63
61
|
end
|
64
62
|
end
|
65
63
|
end
|