Class: Danger::DangerfileBitbucketServerPlugin
- Defined in:
- lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb
Overview
Handles interacting with Bitbucket Server inside a Dangerfile. Provides a few functions which wrap pr_json and also through a few standard functions to simplify your code.
Bitbucket Server Misc collapse
-
#html_link(paths, full_path: true) ⇒ String
Returns a list of HTML anchors 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) ⇒ DangerfileBitbucketServerPlugin
constructor
A new instance of DangerfileBitbucketServerPlugin.
Methods inherited from Plugin
all_plugins, clear_external_plugins, inherited, #method_missing
Constructor Details
#initialize(dangerfile) ⇒ DangerfileBitbucketServerPlugin
Returns a new instance of DangerfileBitbucketServerPlugin.
70 71 72 73 |
# File 'lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb', line 70 def initialize(dangerfile) super(dangerfile) @bs = 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
66 67 68 |
# File 'lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb', line 66 def self.instance_name "bitbucket_server" end |
.new(dangerfile) ⇒ Object
So that this init can fail.
58 59 60 61 |
# File 'lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb', line 58 def self.new(dangerfile) return nil if dangerfile.env.request_source.class != Danger::RequestSources::BitbucketServer super end |
Instance Method Details
#base_commit ⇒ String
The base commit to which the PR is going to be merged as a parent.
136 137 138 |
# File 'lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb', line 136 def base_commit @bs.pr_json[:toRef][:latestCommit].to_s end |
#branch_for_base ⇒ String
The branch to which the PR is going to be merged into.
112 113 114 |
# File 'lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb', line 112 def branch_for_base @bs.pr_json[:toRef][:displayId].to_s end |
#branch_for_head ⇒ String
The branch to which the PR is going to be merged from.
128 129 130 |
# File 'lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb', line 128 def branch_for_head @bs.pr_json[:fromRef][:displayId].to_s end |
#head_commit ⇒ String
The head commit to which the PR is requesting to be merged from.
144 145 146 |
# File 'lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb', line 144 def head_commit @bs.pr_json[:fromRef][:latestCommit].to_s end |
#html_link(paths, full_path: true) ⇒ String
Returns a list of HTML anchors for a file, or files in the head repository. It returns a string of multiple anchors if passed an array.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb', line 158 def html_link(paths, full_path: true) paths = [paths] unless paths.kind_of?(Array) commit = head_commit repo = pr_json[:fromRef][:repository][:links][:self].flat_map { |l| l[:href] }.first paths = paths.map do |path| path, line = path.split("#") url_path = path.start_with?("/") ? path : "/#{path}" text = full_path ? path : File.basename(path) url_path.gsub!(" ", "%20") line_ref = line ? "##{line}" : "" create_link("#{repo}/browse/#{url_path}?at=#{commit}#{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.
104 105 106 |
# File 'lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb', line 104 def @bs.pr_json[:author][:user][:slug].to_s end |
#pr_description ⇒ String Also known as: pr_body
The body text of the Pull Request.
95 96 97 |
# File 'lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb', line 95 def pr_description @bs.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/bitbucket_server_api/pr_response.json).
79 80 81 |
# File 'lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb', line 79 def pr_json @bs.pr_json end |
#pr_link ⇒ String
A href that represents the current PR
120 121 122 |
# File 'lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb', line 120 def pr_link @bs.pr_json[:links][:self].flat_map { |l| l[:href] }.first.to_s end |
#pr_title ⇒ String
The title of the Pull Request.
87 88 89 |
# File 'lib/danger/danger_core/plugins/dangerfile_bitbucket_server_plugin.rb', line 87 def pr_title @bs.pr_json[:title].to_s end |