danger 5.4.0 → 5.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06752bbffec806b31893a0befbc36c7a9fdb2fae
4
- data.tar.gz: a040e75f604c3efaa4fef0f9a4ef5525986d56f6
3
+ metadata.gz: d6ab9271203b201cc6f55cd14b8e56035da246d0
4
+ data.tar.gz: e72f44993af9e3926facdb74026e01f98dea28a3
5
5
  SHA512:
6
- metadata.gz: f67e7ec2195c040f6005238e1dc522b0be4e7976972aa110b3f91c213e420436ad3dcc1ab4d720aa5dc34c0242d321d4bdb69ce3c4b41353ce25a498e0696946
7
- data.tar.gz: b510818c68d7ff4a88152158f1254b84d02e9daa07c2d612c424a6b127561a2aec8b982b52786c453aa7692ca5d8d32726daba85c5c7f97062585e1938b41e95
6
+ metadata.gz: 863158d3cadaf5ed8506d349eebb66bc94aabf9fcde1643c36dd5603cec4e759443775624eb55d14d559f6046c896466b9a4128b1973831e543185703c7634fe
7
+ data.tar.gz: 5a9f08b4521ead063766e7486980fa52123754ff628cfceae5422198ac2aa837a3a89859c34c1a82ef895d13f5e56892554b7bbafbf098e372155422063e3e9e
@@ -10,6 +10,7 @@ require "danger/danger_core/plugins/dangerfile_github_plugin"
10
10
  require "danger/danger_core/plugins/dangerfile_gitlab_plugin"
11
11
  require "danger/danger_core/plugins/dangerfile_bitbucket_server_plugin"
12
12
  require "danger/danger_core/plugins/dangerfile_bitbucket_cloud_plugin"
13
+ require "danger/danger_core/plugins/dangerfile_vsts_plugin"
13
14
 
14
15
  module Danger
15
16
  class Dangerfile
@@ -37,7 +38,7 @@ module Danger
37
38
 
38
39
  # The ones that everything would break without
39
40
  def self.essential_plugin_classes
40
- [DangerfileMessagingPlugin, DangerfileGitPlugin, DangerfileDangerPlugin, DangerfileGitHubPlugin, DangerfileGitLabPlugin, DangerfileBitbucketServerPlugin, DangerfileBitbucketCloudPlugin]
41
+ [DangerfileMessagingPlugin, DangerfileGitPlugin, DangerfileDangerPlugin, DangerfileGitHubPlugin, DangerfileGitLabPlugin, DangerfileBitbucketServerPlugin, DangerfileBitbucketCloudPlugin, DangerfileVSTSPlugin]
41
42
  end
42
43
 
43
44
  # Both of these methods exist on all objects
@@ -0,0 +1,191 @@
1
+ # coding: utf-8
2
+
3
+ require "danger/plugin_support/plugin"
4
+
5
+ module Danger
6
+ # Handles interacting with VSTS inside a Dangerfile. Provides a few functions which wrap `pr_json` and also
7
+ # through a few standard functions to simplify your code.
8
+ #
9
+ # @example Warn when a PR is classed as work in progress
10
+ #
11
+ # warn "PR is classed as Work in Progress" if vsts.pr_title.include? "[WIP]"
12
+ #
13
+ # @example Declare a PR to be simple to avoid specific Danger rules
14
+ #
15
+ # declared_trivial = (vsts.pr_title + vsts.pr_body).include?("#trivial")
16
+ #
17
+ # @example Ensure there is a summary for a PR
18
+ #
19
+ # fail "Please provide a summary in the Pull Request description" if vsts.pr_body.length < 5
20
+ #
21
+ # @example Only accept PRs to the develop branch
22
+ #
23
+ # fail "Please re-submit this PR to develop, we may have already fixed your issue." if vsts.branch_for_base != "develop"
24
+ #
25
+ # @example Highlight when a celebrity makes a pull request
26
+ #
27
+ # message "Welcome, Danger." if vsts.pr_author == "dangermcshane"
28
+ #
29
+ # @example Ensure that all PRs have an assignee
30
+ #
31
+ # warn "This PR does not have any assignees yet." unless vsts.pr_json["reviewers"].length == 0
32
+ #
33
+ # @example Send a message with links to a collection of specific files
34
+ #
35
+ # if git.modified_files.include? "config/*.js"
36
+ # config_files = git.modified_files.select { |path| path.include? "config/" }
37
+ # message "This PR changes #{ vsts.markdown_link(config_files) }"
38
+ # end
39
+ #
40
+ # @example Highlight with a clickable link if a Package.json is changed
41
+ #
42
+ # warn "#{vsts.markdown_link("Package.json")} was edited." if git.modified_files.include? "Package.json"
43
+ #
44
+ # @example Note an issue with a particular line on a file using the #L[num] syntax, e.g. `#L23`
45
+ #
46
+ # linter_json = `my_linter lint "file"`
47
+ # results = JSON.parse linter_json
48
+ # unless results.empty?
49
+ # file, line, warning = result.first
50
+ # warn "#{vsts.markdown_link("#{file}#L#{line}")} has linter issue: #{warning}."
51
+ # end
52
+ #
53
+ #
54
+ # @see danger/danger
55
+ # @tags core, vsts
56
+ #
57
+ class DangerfileVSTSPlugin < Plugin
58
+ # So that this init can fail.
59
+ def self.new(dangerfile)
60
+ return nil if dangerfile.env.request_source.class != Danger::RequestSources::VSTS
61
+ super
62
+ end
63
+
64
+ # The instance name used in the Dangerfile
65
+ # @return [String]
66
+ #
67
+ def self.instance_name
68
+ "vsts"
69
+ end
70
+
71
+ def initialize(dangerfile)
72
+ super(dangerfile)
73
+ @source = dangerfile.env.request_source
74
+ end
75
+
76
+ # @!group VSTS Misc
77
+ # The hash that represents the PR's JSON. For an example of what this looks like
78
+ # see the [Danger Fixture'd one](https://raw.githubusercontent.com/danger/danger/master/spec/fixtures/vsts_api/pr_response.json).
79
+ # @return [Hash]
80
+ def pr_json
81
+ @source.pr_json
82
+ end
83
+
84
+ # @!group PR Metadata
85
+ # The title of the Pull Request.
86
+ # @return [String]
87
+ #
88
+ def pr_title
89
+ @source.pr_json[:title].to_s
90
+ end
91
+
92
+ # @!group PR Metadata
93
+ # The body text of the Pull Request.
94
+ # @return [String]
95
+ #
96
+ def pr_description
97
+ @source.pr_json[:description].to_s
98
+ end
99
+ alias pr_body pr_description
100
+
101
+ # @!group PR Metadata
102
+ # The username of the author of the Pull Request.
103
+ # @return [String]
104
+ #
105
+ def pr_author
106
+ @source.pr_json[:createdBy][:displayName].to_s
107
+ end
108
+
109
+ # @!group PR Commit Metadata
110
+ # The branch to which the PR is going to be merged into.
111
+ # @return [String]
112
+ #
113
+ def branch_for_base
114
+ branch_name(:targetRefName)
115
+ end
116
+
117
+ # @!group PR Commit Metadata
118
+ # A href that represents the current PR
119
+ # @return [String]
120
+ #
121
+ def pr_link
122
+ repo_path = @source.pr_json[:repository][:remoteUrl].to_s
123
+ pull_request_id = @source.pr_json[:pullRequestId].to_s
124
+
125
+ "#{repo_path}/pullRequest/#{pull_request_id}"
126
+ end
127
+
128
+ # @!group PR Commit Metadata
129
+ # The branch to which the PR is going to be merged from.
130
+ # @return [String]
131
+ #
132
+ def branch_for_head
133
+ branch_name(:sourceRefName)
134
+ end
135
+
136
+ # @!group PR Commit Metadata
137
+ # The base commit to which the PR is going to be merged as a parent.
138
+ # @return [String]
139
+ #
140
+ def base_commit
141
+ @source.pr_json[:lastMergeTargetCommit][:commitId].to_s
142
+ end
143
+
144
+ # @!group PR Commit Metadata
145
+ # The head commit to which the PR is requesting to be merged from.
146
+ # @return [String]
147
+ #
148
+ def head_commit
149
+ @source.pr_json[:lastMergeSourceCommit][:commitId].to_s
150
+ end
151
+
152
+ # @!group VSTS Misc
153
+ # Returns a list of Markdown links for a file, or files in the head repository.
154
+ # It returns a string of multiple links if passed an array.
155
+ # @param [String or Array<String>] paths
156
+ # A list of strings to convert to Markdown links
157
+ # @param [Bool] full_path
158
+ # Shows the full path as the link's text, defaults to `true`.
159
+ #
160
+ # @return [String]
161
+ #
162
+ def markdown_link(paths, full_path: true)
163
+ paths = [paths] unless paths.kind_of?(Array)
164
+ commit = head_commit
165
+ repo = pr_json[:repository][:remoteUrl].to_s
166
+
167
+ paths = paths.map do |path|
168
+ path, line = path.split("#L")
169
+ url_path = path.start_with?("/") ? path : "/#{path}"
170
+ text = full_path ? path : File.basename(path)
171
+ url_path.gsub!(" ", "%20")
172
+ line_ref = line ? "&line=#{line}" : ""
173
+ create_markdown_link("#{repo}/commit/#{commit}?path=#{url_path}&_a=contents#{line_ref}", text)
174
+ end
175
+
176
+ return paths.first if paths.count < 2
177
+ paths.first(paths.count - 1).join(", ") + " & " + paths.last
178
+ end
179
+
180
+ private
181
+
182
+ def create_markdown_link(href, text)
183
+ "[#{text}](#{href})"
184
+ end
185
+
186
+ def branch_name(key)
187
+ repo_matches = @source.pr_json[key].to_s.match(%r{refs\/heads\/(.*)})
188
+ repo_matches[1] unless repo_matches.nil?
189
+ end
190
+ end
191
+ end
@@ -21,7 +21,7 @@ module Danger
21
21
  end
22
22
 
23
23
  def self.optional_env_vars
24
- ["DANGER_GITHUB_HOST", "DANGER_GITHUB_API_BASE_URL"]
24
+ ["DANGER_GITHUB_HOST", "DANGER_GITHUB_API_BASE_URL", "DANGER_OCTOKIT_VERIFY_SSL"]
25
25
  end
26
26
 
27
27
  def initialize(ci_source, environment)
@@ -45,6 +45,10 @@ module Danger
45
45
  @host = @environment["DANGER_GITHUB_HOST"] || "github.com"
46
46
  end
47
47
 
48
+ def verify_ssl
49
+ @environment["DANGER_OCTOKIT_VERIFY_SSL"] == "false" ? false : true
50
+ end
51
+
48
52
  # `DANGER_GITHUB_API_HOST` is the old name kept for legacy reasons and
49
53
  # backwards compatibility. `DANGER_GITHUB_API_BASE_URL` is the new
50
54
  # correctly named variable.
@@ -58,8 +62,10 @@ module Danger
58
62
 
59
63
  def client
60
64
  raise "No API token given, please provide one using `DANGER_GITHUB_API_TOKEN`" if !@token && !support_tokenless_auth
61
-
62
65
  @client ||= begin
66
+ Octokit.configure do |config|
67
+ config.connection_options[:ssl] = { verify: verify_ssl }
68
+ end
63
69
  Octokit::Client.new(access_token: @token, auto_paginate: true, api_endpoint: api_url)
64
70
  end
65
71
  end
@@ -1,4 +1,4 @@
1
1
  module Danger
2
- VERSION = "5.4.0".freeze
2
+ VERSION = "5.4.1".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.4.0
4
+ version: 5.4.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: 2017-09-02 00:00:00.000000000 Z
12
+ date: 2017-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: claide
@@ -437,6 +437,7 @@ files:
437
437
  - lib/danger/danger_core/plugins/dangerfile_github_plugin.rb
438
438
  - lib/danger/danger_core/plugins/dangerfile_gitlab_plugin.rb
439
439
  - lib/danger/danger_core/plugins/dangerfile_messaging_plugin.rb
440
+ - lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb
440
441
  - lib/danger/danger_core/standard_error.rb
441
442
  - lib/danger/helpers/array_subclass.rb
442
443
  - lib/danger/helpers/comment.rb