class Danger::DangerfileVSTSPlugin
@tags core, vsts
@see danger/danger
end
warn “#{vsts.markdown_link(”#{file}#L#{line}“)} has linter issue: #{warning}.”
file, line, warning = result.first
unless results.empty?
results = JSON.parse linter_json
linter_json = ‘my_linter lint “file”`
@example Note an issue with a particular line on a file using the #L syntax, e.g. `#L23`
warn “#{vsts.markdown_link(”Package.json“)} was edited.” if git.modified_files.include? “Package.json”
@example Highlight with a clickable link if a Package.json is changed
end
message “This PR changes #{ vsts.markdown_link(config_files) }”
config_files = git.modified_files.select { |path| path.include? “config/” }
if git.modified_files.include? “config/*.js”
@example Send a message with links to a collection of specific files
warn “This PR does not have any assignees yet.” unless vsts.pr_json.length == 0
@example Ensure that all PRs have an assignee
message “Welcome, Danger.” if vsts.pr_author == “dangermcshane”
@example Highlight when a celebrity makes a pull request
failure “Please re-submit this PR to develop, we may have already fixed your issue.” if vsts.branch_for_base != “develop”
@example Only accept PRs to the develop branch
failure “Please provide a summary in the Pull Request description” if vsts.pr_body.length < 5
@example Ensure there is a summary for a PR
declared_trivial = (vsts.pr_title + vsts.pr_body).include?(“#trivial”)
@example Declare a PR to be simple to avoid specific Danger rules
warn “PR is classed as Work in Progress” if vsts.pr_title.include? “[WIP]”
@example Warn when a PR is classed as work in progress
through a few standard functions to simplify your code.
Handles interacting with VSTS inside a Dangerfile. Provides a few functions which wrap `pr_json` and also
def self.instance_name
-
(String)-
def self.instance_name "vsts" end
def self.new(dangerfile)
def self.new(dangerfile) return nil if dangerfile.env.request_source.class != Danger::RequestSources::VSTS super end
def base_commit
-
(String)-
def base_commit @source.pr_json[:lastMergeTargetCommit][:commitId].to_s end
def branch_for_base
-
(String)-
def branch_for_base branch_name(:targetRefName) end
def branch_for_head
-
(String)-
def branch_for_head branch_name(:sourceRefName) end
def branch_name(key)
def branch_name(key) repo_matches = @source.pr_json[key].to_s.match(%r{refs/heads/(.*)}) repo_matches[1] unless repo_matches.nil? end
def create_markdown_link(href, text)
def create_markdown_link(href, text) "[#{text}](#{href})" end
def head_commit
-
(String)-
def head_commit @source.pr_json[:lastMergeSourceCommit][:commitId].to_s end
def initialize(dangerfile)
def initialize(dangerfile) super(dangerfile) @source = dangerfile.env.request_source end
def markdown_link(paths, full_path: true)
-
(String)-
Parameters:
-
full_path(Bool) -- -
paths(String or Array) --
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.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
def pr_author
-
(String)-
def pr_author @source.pr_json[:createdBy][:displayName].to_s end
def pr_description
-
(String)-
def pr_description @source.pr_json[:description].to_s end
def pr_json
-
(Hash)-
def pr_json @source.pr_json end
def pr_link
-
(String)-
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
def pr_title
-
(String)-
def pr_title @source.pr_json[:title].to_s end