Class: Danger::DangerfileVSTSPlugin
- Defined in:
- lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb
Overview
Handles interacting with VSTS inside a Dangerfile. Provides a few functions which wrap ‘pr_json` and also through a few standard functions to simplify your code.
VSTS Misc collapse
-
#markdown_link(paths, full_path: true) ⇒ String
Returns a list of Markdown links for a file, or files in the head repository.
-
#pr_json ⇒ Hash
The hash that represents the PR’s JSON.
PR Metadata collapse
-
#pr_author ⇒ String
The username of the author of the Pull Request.
-
#pr_description ⇒ String
(also: #pr_body)
The body text of the Pull Request.
-
#pr_title ⇒ String
The title of the Pull Request.
PR Commit Metadata collapse
-
#base_commit ⇒ String
The base commit to which the PR is going to be merged as a parent.
-
#branch_for_base ⇒ String
The branch to which the PR is going to be merged into.
-
#branch_for_head ⇒ String
The branch to which the PR is going to be merged from.
-
#head_commit ⇒ String
The head commit to which the PR is requesting to be merged from.
-
#pr_link ⇒ String
A href that represents the current PR.
Class Method Summary collapse
-
.instance_name ⇒ String
The instance name used in the Dangerfile.
-
.new(dangerfile) ⇒ Object
So that this init can fail.
Instance Method Summary collapse
-
#initialize(dangerfile) ⇒ DangerfileVSTSPlugin
constructor
A new instance of DangerfileVSTSPlugin.
Methods inherited from Plugin
all_plugins, clear_external_plugins, inherited, #method_missing
Constructor Details
#initialize(dangerfile) ⇒ DangerfileVSTSPlugin
Returns a new instance of DangerfileVSTSPlugin.
72 73 74 75 |
# File 'lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb', line 72 def initialize(dangerfile) super(dangerfile) @source = dangerfile.env.request_source end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Danger::Plugin
Class Method Details
.instance_name ⇒ String
The instance name used in the Dangerfile
68 69 70 |
# File 'lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb', line 68 def self.instance_name "vsts" end |
.new(dangerfile) ⇒ Object
So that this init can fail.
59 60 61 62 63 |
# File 'lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb', line 59 def self.new(dangerfile) return nil if dangerfile.env.request_source.class != Danger::RequestSources::VSTS super end |
Instance Method Details
#base_commit ⇒ String
The base commit to which the PR is going to be merged as a parent.
141 142 143 |
# File 'lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb', line 141 def base_commit @source.pr_json[:lastMergeTargetCommit][:commitId].to_s end |
#branch_for_base ⇒ String
The branch to which the PR is going to be merged into.
114 115 116 |
# File 'lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb', line 114 def branch_for_base branch_name(:targetRefName) end |
#branch_for_head ⇒ String
The branch to which the PR is going to be merged from.
133 134 135 |
# File 'lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb', line 133 def branch_for_head branch_name(:sourceRefName) end |
#head_commit ⇒ String
The head commit to which the PR is requesting to be merged from.
149 150 151 |
# File 'lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb', line 149 def head_commit @source.pr_json[:lastMergeSourceCommit][:commitId].to_s end |
#markdown_link(paths, full_path: true) ⇒ String
Returns a list of Markdown links for a file, or files in the head repository. It returns a string of multiple links if passed an array.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb', line 163 def markdown_link(paths, full_path: true) paths = [paths] unless paths.kind_of?(Array) commit = head_commit repo = pr_json[:repository][:remoteUrl].to_s paths = paths.map do |path| path, line = path.split("#L") url_path = path.start_with?("/") ? path : "/#{path}" text = full_path ? path : File.basename(path) url_path = url_path.gsub(" ", "%20") line_ref = line ? "&line=#{line}" : "" create_markdown_link("#{repo}/commit/#{commit}?path=#{url_path}&_a=contents#{line_ref}", text) end return paths.first if paths.count < 2 "#{paths.first(paths.count - 1).join(', ')} & #{paths.last}" end |
#pr_author ⇒ String
The username of the author of the Pull Request.
106 107 108 |
# File 'lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb', line 106 def @source.pr_json[:createdBy][:displayName].to_s end |
#pr_description ⇒ String Also known as: pr_body
The body text of the Pull Request.
97 98 99 |
# File 'lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb', line 97 def pr_description @source.pr_json[:description].to_s end |
#pr_json ⇒ Hash
The hash that represents the PR’s JSON. For an example of what this looks like see the [Danger Fixture’d one](raw.githubusercontent.com/danger/danger/master/spec/fixtures/vsts_api/pr_response.json).
81 82 83 |
# File 'lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb', line 81 def pr_json @source.pr_json end |
#pr_link ⇒ String
A href that represents the current PR
122 123 124 125 126 127 |
# File 'lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb', line 122 def pr_link repo_path = @source.pr_json[:repository][:remoteUrl].to_s pull_request_id = @source.pr_json[:pullRequestId].to_s "#{repo_path}/pullRequest/#{pull_request_id}" end |
#pr_title ⇒ String
The title of the Pull Request.
89 90 91 |
# File 'lib/danger/danger_core/plugins/dangerfile_vsts_plugin.rb', line 89 def pr_title @source.pr_json[:title].to_s end |