danger 3.2.0 → 3.2.1
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/lib/danger.rb +4 -3
- data/lib/danger/danger_core/dangerfile.rb +4 -5
- data/lib/danger/danger_core/messages/markdown.rb +4 -0
- data/lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb +0 -6
- data/lib/danger/danger_core/plugins/dangerfile_danger_plugin.rb +36 -8
- data/lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb +35 -14
- data/lib/danger/request_source/bitbucket_server_api.rb +10 -0
- data/lib/danger/request_source/request_source.rb +2 -2
- data/lib/danger/scm_source/git_repo.rb +15 -4
- data/lib/danger/version.rb +1 -1
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6408840e4167a8092819c1b40d3c409b61df856b
|
4
|
+
data.tar.gz: 036b9a85309a45403d2649949f7f63b2722d5a50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: decc456c54fc15961a5f73c92b8cf131a784bffb01842d05f97dff361f36ece7a0dbc1443e9d74fde21acd40a3c83fa070e0cc17dfc33745788f7a68441d1ead
|
7
|
+
data.tar.gz: 56c7fe3cf50c9d0b8d7fb91f2e70f195970f10c7ec1f813768c357626eac43212edde7697ccf4e6ee1b2225f76b0d3628cfaa803893dc228c5cd6eba1458909d
|
data/lib/danger.rb
CHANGED
@@ -18,13 +18,14 @@ Dir[File.expand_path("danger/*source/*.rb", File.dirname(__FILE__))].each do |fi
|
|
18
18
|
end
|
19
19
|
|
20
20
|
module Danger
|
21
|
+
GEM_NAME = "danger".freeze
|
22
|
+
|
21
23
|
# @return [String] The path to the local gem directory
|
22
24
|
def self.gem_path
|
23
|
-
|
24
|
-
unless Gem::Specification.find_all_by_name(gem_name).any?
|
25
|
+
if Gem::Specification.find_all_by_name(GEM_NAME).empty?
|
25
26
|
raise "Couldn't find gem directory for 'danger'"
|
26
27
|
end
|
27
|
-
return Gem::Specification.find_by_name(
|
28
|
+
return Gem::Specification.find_by_name(GEM_NAME).gem_dir
|
28
29
|
end
|
29
30
|
|
30
31
|
# @return [String] Latest version of Danger on https://rubygems.org
|
@@ -123,12 +123,9 @@ module Danger
|
|
123
123
|
when :pr_json
|
124
124
|
value = "[Skipped]"
|
125
125
|
|
126
|
-
when :pr_body
|
127
|
-
value = plugin.send(method)
|
128
|
-
value = value.scan(/.{,80}/).to_a.each(&:strip!).join("\n")
|
129
|
-
|
130
126
|
else
|
131
127
|
value = plugin.send(method)
|
128
|
+
value = value.scan(/.{,80}/).to_a.each(&:strip!).join("\n") if value.kind_of?(String)
|
132
129
|
# So that we either have one value per row
|
133
130
|
# or we have [] for an empty array
|
134
131
|
value = value.join("\n") if value.kind_of?(Array) && value.count > 0
|
@@ -158,7 +155,9 @@ module Danger
|
|
158
155
|
|
159
156
|
ui.section("Info:") do
|
160
157
|
ui.puts
|
161
|
-
|
158
|
+
table = Terminal::Table.new(params)
|
159
|
+
table.align_column(0, :right)
|
160
|
+
ui.puts table
|
162
161
|
ui.puts
|
163
162
|
end
|
164
163
|
end
|
@@ -17,12 +17,6 @@ module Danger
|
|
17
17
|
#
|
18
18
|
# fail "Please add labels to this PR" if bitbucket_server.pr_labels.empty?
|
19
19
|
#
|
20
|
-
# @example Check if a user is in a specific bitbucket_server org, and message them if so
|
21
|
-
#
|
22
|
-
# unless bitbucket_server.api.organization_member?('danger', bitbucket_server.pr_author)
|
23
|
-
# message "@#{bitbucket_server.pr_author} is not a contributor yet, would you like to join the Danger org?"
|
24
|
-
# end
|
25
|
-
#
|
26
20
|
# @example Ensure there is a summary for a PR
|
27
21
|
#
|
28
22
|
# fail "Please provide a summary in the Pull Request description" if bitbucket_server.pr_body.length < 5
|
@@ -1,11 +1,8 @@
|
|
1
1
|
require "danger/plugin_support/plugin"
|
2
2
|
|
3
3
|
module Danger
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# it does not have the stringent rules around documentation expected of a public plugin.
|
7
|
-
# It's worth noting, that you can also have plugins inside `./danger_plugins` and they
|
8
|
-
# will be automatically imported into your Dangerfile at launch.
|
4
|
+
# A way to interact with Danger herself. Offering APIs to import plugins,
|
5
|
+
# and Dangerfiles from muliple sources.
|
9
6
|
#
|
10
7
|
# @example Import a plugin available over HTTP
|
11
8
|
#
|
@@ -20,6 +17,18 @@ module Danger
|
|
20
17
|
#
|
21
18
|
# danger.import_plugin("danger/plugins/*.rb")
|
22
19
|
#
|
20
|
+
# @example Run a Dangerfile from inside a sub-folder
|
21
|
+
#
|
22
|
+
# danger.import_dangerfile(file: "danger/Dangerfile.private")
|
23
|
+
#
|
24
|
+
# @example Run a Dangerfile from inside a gem
|
25
|
+
#
|
26
|
+
# danger.import_dangerfile(gem: "ruby-grape-danger")
|
27
|
+
#
|
28
|
+
# @example Run a Dangerfile from inside a repo
|
29
|
+
#
|
30
|
+
# danger.import_dangerfile(gitlab: "ruby-grape/danger")
|
31
|
+
#
|
23
32
|
# @see danger/danger
|
24
33
|
# @tags core, plugins
|
25
34
|
|
@@ -53,7 +62,8 @@ module Danger
|
|
53
62
|
# Import a Dangerfile.
|
54
63
|
#
|
55
64
|
# @param [Hash] opts
|
56
|
-
# @option opts [String] :github
|
65
|
+
# @option opts [String] :github GitHub repo
|
66
|
+
# @option opts [String] :gitlab GitLab repo
|
57
67
|
# @option opts [String] :gem Gem name
|
58
68
|
# @option opts [String] :path Path to Dangerfile
|
59
69
|
# @return [void]
|
@@ -62,8 +72,8 @@ module Danger
|
|
62
72
|
warn "Use `import_dangerfile(github: '#{opts}')` instead of `import_dangerfile '#{opts}'`."
|
63
73
|
import_dangerfile_from_github(opts)
|
64
74
|
elsif opts.kind_of?(Hash)
|
65
|
-
if opts.key?(:github)
|
66
|
-
import_dangerfile_from_github(opts[:github])
|
75
|
+
if opts.key?(:github) || opts.key?(:gitlab)
|
76
|
+
import_dangerfile_from_github(opts[:github] || opts[:gitlab])
|
67
77
|
elsif opts.key?(:path)
|
68
78
|
import_dangerfile_from_path(opts[:path])
|
69
79
|
elsif opts.key?(:gem)
|
@@ -76,6 +86,24 @@ module Danger
|
|
76
86
|
end
|
77
87
|
end
|
78
88
|
|
89
|
+
# @!group Danger
|
90
|
+
# Returns the name of the current SCM Provider being used.
|
91
|
+
# @return [Symbol] The name of the SCM Provider used for the active repository.
|
92
|
+
def scm_provider
|
93
|
+
return :unknown unless env.request_source
|
94
|
+
|
95
|
+
case env.request_source
|
96
|
+
when Danger::RequestSources::GitHub
|
97
|
+
:github
|
98
|
+
when Danger::RequestSources::GitLab
|
99
|
+
:gitlab
|
100
|
+
when Danger::RequestSources::BitbucketServer
|
101
|
+
:bitbucket_server
|
102
|
+
else
|
103
|
+
:unknown
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
79
107
|
private
|
80
108
|
|
81
109
|
# @!group Danger
|
@@ -4,52 +4,52 @@ module Danger
|
|
4
4
|
# Handles interacting with GitLab inside a Dangerfile. Provides a few functions which wrap `mr_json` and also
|
5
5
|
# through a few standard functions to simplify your code.
|
6
6
|
#
|
7
|
-
# @example Warn when an MR is classed as work in progress
|
7
|
+
# @example Warn when an MR is classed as work in progress.
|
8
8
|
#
|
9
9
|
# warn "MR is classed as Work in Progress" if gitlab.mr_title.include? "[WIP]"
|
10
10
|
#
|
11
|
-
# @example Declare a MR to be simple to avoid specific Danger rules
|
11
|
+
# @example Declare a MR to be simple to avoid specific Danger rules.
|
12
12
|
#
|
13
13
|
# declared_trivial = (gitlab.mr_title + gitlab.mr_body).include?("#trivial")
|
14
14
|
#
|
15
|
-
# @example Ensure that labels have been applied to the MR
|
15
|
+
# @example Ensure that labels have been applied to the MR.
|
16
16
|
#
|
17
17
|
# fail "Please add labels to this MR" if gitlab.mr_labels.empty?
|
18
18
|
#
|
19
|
-
# @example Ensure that all MRs have an assignee
|
19
|
+
# @example Ensure that all MRs have an assignee.
|
20
20
|
#
|
21
21
|
# warn "This MR does not have any assignees yet." unless gitlab.mr_json["assignee"]
|
22
22
|
#
|
23
|
-
# @example Ensure there is a summary for a MR
|
23
|
+
# @example Ensure there is a summary for a MR.
|
24
24
|
#
|
25
|
-
# fail "Please provide a summary in the
|
25
|
+
# fail "Please provide a summary in the Merge Request description" if gitlab.mr_body.length < 5
|
26
26
|
#
|
27
|
-
# @example Only accept MRs to the develop branch
|
27
|
+
# @example Only accept MRs to the develop branch.
|
28
28
|
#
|
29
29
|
# fail "Please re-submit this MR to develop, we may have already fixed your issue." if gitlab.branch_for_merge != "develop"
|
30
30
|
#
|
31
|
-
# @example Note when MRs don't reference a milestone, which goes away when it does
|
31
|
+
# @example Note when MRs don't reference a milestone, which goes away when it does.
|
32
32
|
#
|
33
33
|
# has_milestone = gitlab.mr_json["milestone"] != nil
|
34
34
|
# warn("This MR does not refer to an existing milestone", sticky: false) unless has_milestone
|
35
35
|
#
|
36
|
-
# @example Note when a MR cannot be manually merged, which goes away when you can
|
36
|
+
# @example Note when a MR cannot be manually merged, which goes away when you can.
|
37
37
|
#
|
38
38
|
# can_merge = gitlab.mr_json["mergeable"]
|
39
39
|
# warn("This MR cannot be merged yet.", sticky: false) unless can_merge
|
40
40
|
#
|
41
|
-
# @example Highlight when a celebrity makes a
|
41
|
+
# @example Highlight when a celebrity makes a merge request.
|
42
42
|
#
|
43
43
|
# message "Welcome, Danger." if gitlab.mr_author == "dangermcshane"
|
44
44
|
#
|
45
|
-
# @example Send a message with links to a collection of specific files
|
45
|
+
# @example Send a message with links to a collection of specific files.
|
46
46
|
#
|
47
47
|
# if git.modified_files.include? "config/*.js"
|
48
48
|
# config_files = git.modified_files.select { |path| path.include? "config/" }
|
49
49
|
# message "This MR changes #{ gitlab.html_link(config_files) }"
|
50
50
|
# end
|
51
51
|
#
|
52
|
-
# @example Highlight with a clickable link if a Package.json is changed
|
52
|
+
# @example Highlight with a clickable link if a Package.json is changed.
|
53
53
|
#
|
54
54
|
# warn "#{gitlab.html_link("Package.json")} was edited." if git.modified_files.include? "Package.json"
|
55
55
|
#
|
@@ -110,7 +110,7 @@ module Danger
|
|
110
110
|
end
|
111
111
|
|
112
112
|
# @!group MR Content
|
113
|
-
# The unified diff produced by GitLab for this
|
113
|
+
# The unified diff produced by GitLab for this MR
|
114
114
|
# see [Unified diff](https://en.wikipedia.org/wiki/Diff_utility#Unified_format)
|
115
115
|
# @return [String]
|
116
116
|
#
|
@@ -120,12 +120,29 @@ module Danger
|
|
120
120
|
|
121
121
|
# @!group MR Commit Metadata
|
122
122
|
# The branch to which the MR is going to be merged into
|
123
|
+
# @deprecated Please use {#branch_for_base} instead
|
123
124
|
# @return [String]
|
124
125
|
#
|
125
126
|
def branch_for_merge
|
127
|
+
branch_for_base
|
128
|
+
end
|
129
|
+
|
130
|
+
# @!group MR Commit Metadata
|
131
|
+
# The branch to which the MR is going to be merged into.
|
132
|
+
# @return [String]
|
133
|
+
#
|
134
|
+
def branch_for_base
|
126
135
|
@gitlab.mr_json.target_branch
|
127
136
|
end
|
128
137
|
|
138
|
+
# @!group MR Commit Metadata
|
139
|
+
# The branch to which the MR is going to be merged from.
|
140
|
+
# @return [String]
|
141
|
+
#
|
142
|
+
def branch_for_head
|
143
|
+
@gitlab.mr_json.source_branch
|
144
|
+
end
|
145
|
+
|
129
146
|
# @!group MR Commit Metadata
|
130
147
|
# The base commit to which the MR is going to be merged as a parent
|
131
148
|
# @return [String]
|
@@ -153,8 +170,11 @@ module Danger
|
|
153
170
|
|
154
171
|
# @!group GitLab Misc
|
155
172
|
# Provides access to the GitLab API client used inside Danger. Making
|
156
|
-
# it easy to use the GitLab API inside a Dangerfile.
|
173
|
+
# it easy to use the GitLab API inside a Dangerfile. See the gitlab
|
174
|
+
# gem's [documentation](http://www.rubydoc.info/gems/gitlab/Gitlab/Client)
|
175
|
+
# for accessible methods.
|
157
176
|
# @return [GitLab::Client]
|
177
|
+
#
|
158
178
|
def api
|
159
179
|
@gitlab.client
|
160
180
|
end
|
@@ -168,6 +188,7 @@ module Danger
|
|
168
188
|
# Shows the full path as the link's text, defaults to `true`.
|
169
189
|
#
|
170
190
|
# @return [String]
|
191
|
+
#
|
171
192
|
def html_link(paths, full_path: true)
|
172
193
|
paths = [paths] unless paths.kind_of?(Array)
|
173
194
|
commit = head_commit
|
@@ -13,6 +13,16 @@ module Danger
|
|
13
13
|
self.pr_api_endpoint = "https://#{host}/rest/api/1.0/projects/#{project}/repos/#{slug}/pull-requests/#{pull_request_id}"
|
14
14
|
end
|
15
15
|
|
16
|
+
def inspect
|
17
|
+
inspected = super
|
18
|
+
|
19
|
+
if @password
|
20
|
+
inspected = inspected.sub! @password, "********".freeze
|
21
|
+
end
|
22
|
+
|
23
|
+
inspected
|
24
|
+
end
|
25
|
+
|
16
26
|
def credentials_given?
|
17
27
|
@username && !@username.empty? && @password && !@password.empty?
|
18
28
|
end
|
@@ -18,9 +18,9 @@ module Danger
|
|
18
18
|
raise "Subclass and overwrite initialize"
|
19
19
|
end
|
20
20
|
|
21
|
-
#
|
21
|
+
# @return [Boolean] whether scm.origins is a valid git repository or not
|
22
22
|
def validates_as_ci?
|
23
|
-
!!self.scm.origins.match(%r{#{Regexp.escape self.host}(:|/)(
|
23
|
+
!!self.scm.origins.match(%r{#{Regexp.escape self.host}(:|/)(.+/.+?)(?:\.git)?$})
|
24
24
|
end
|
25
25
|
|
26
26
|
def validates_as_api_source?
|
@@ -4,20 +4,27 @@ require "git"
|
|
4
4
|
|
5
5
|
module Danger
|
6
6
|
class GitRepo
|
7
|
-
attr_accessor :diff, :log
|
7
|
+
attr_accessor :diff, :log, :folder
|
8
8
|
|
9
9
|
def diff_for_folder(folder, from: "master", to: "HEAD")
|
10
|
-
|
10
|
+
self.folder = folder
|
11
|
+
repo = Git.open self.folder
|
11
12
|
|
13
|
+
ensure_commitish_exists!(from)
|
14
|
+
ensure_commitish_exists!(to)
|
12
15
|
merge_base = repo.merge_base(from, to)
|
16
|
+
|
17
|
+
ensure_commitish_exists!(merge_base)
|
13
18
|
self.diff = repo.diff(merge_base.to_s, to)
|
14
19
|
self.log = repo.log.between(from, to)
|
15
20
|
end
|
16
21
|
|
17
22
|
def exec(string)
|
18
23
|
require "open3"
|
19
|
-
|
20
|
-
stdout
|
24
|
+
Dir.chdir(self.folder || ".") do
|
25
|
+
Open3.popen2(default_env, "git #{string}") do |_stdin, stdout, _wait_thr|
|
26
|
+
stdout.read.rstrip
|
27
|
+
end
|
21
28
|
end
|
22
29
|
end
|
23
30
|
|
@@ -34,6 +41,10 @@ module Danger
|
|
34
41
|
def default_env
|
35
42
|
{ "LANG" => "en_US.UTF-8" }
|
36
43
|
end
|
44
|
+
|
45
|
+
def ensure_commitish_exists!(commitish)
|
46
|
+
exec "fetch" if exec("--no-pager show #{commitish}").empty?
|
47
|
+
end
|
37
48
|
end
|
38
49
|
end
|
39
50
|
|
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: 3.2.
|
4
|
+
version: 3.2.1
|
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: 2016-09-
|
12
|
+
date: 2016-09-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: claide
|
@@ -419,7 +419,7 @@ files:
|
|
419
419
|
- lib/danger/request_source/request_source.rb
|
420
420
|
- lib/danger/scm_source/git_repo.rb
|
421
421
|
- lib/danger/version.rb
|
422
|
-
homepage:
|
422
|
+
homepage: https://github.com/danger/danger
|
423
423
|
licenses:
|
424
424
|
- MIT
|
425
425
|
metadata: {}
|
@@ -439,9 +439,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
439
439
|
version: '0'
|
440
440
|
requirements: []
|
441
441
|
rubyforge_project:
|
442
|
-
rubygems_version: 2.
|
442
|
+
rubygems_version: 2.2.2
|
443
443
|
signing_key:
|
444
444
|
specification_version: 4
|
445
445
|
summary: Like Unit Tests, but for your Team Culture.
|
446
446
|
test_files: []
|
447
|
-
has_rdoc:
|