Class: Danger::DangerfileGitHubPlugin
- Defined in:
- lib/danger/danger_core/plugins/dangerfile_github_plugin.rb
Overview
Handles interacting with GitHub inside a Dangerfile. Provides a few functions which wrap ‘pr_json` and also through a few standard functions to simplify your code.
PR Metadata collapse
-
#pr_author ⇒ String
The username of the author of the Pull Request.
-
#pr_body ⇒ String
The body text of the Pull Request.
-
#pr_labels ⇒ String
The labels assigned to the Pull Request.
-
#pr_title ⇒ String
The title of the Pull Request.
PR Commit Metadata collapse
-
#base_commit ⇒ Object
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.
GitHub Misca collapse
-
#pr_json ⇒ Hash
The hash that represents the PR’s JSON.
GitHub Misc collapse
-
#api ⇒ Octokit::Client
Provides access to the GitHub API client used inside Danger.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(dangerfile) ⇒ DangerfileGitHubPlugin
constructor
A new instance of DangerfileGitHubPlugin.
Methods inherited from Plugin
all_plugins, clear_external_plugins, inherited, #method_missing
Constructor Details
#initialize(dangerfile) ⇒ DangerfileGitHubPlugin
Returns a new instance of DangerfileGitHubPlugin.
29 30 31 32 33 34 |
# File 'lib/danger/danger_core/plugins/dangerfile_github_plugin.rb', line 29 def initialize(dangerfile) super(dangerfile) return nil unless dangerfile.env.request_source.class == Danger::RequestSources::GitHub @github = 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 ⇒ Object
36 37 38 |
# File 'lib/danger/danger_core/plugins/dangerfile_github_plugin.rb', line 36 def self.instance_name "github" end |
Instance Method Details
#api ⇒ Octokit::Client
Provides access to the GitHub API client used inside Danger. Making it easy to use the GitHub API inside a Dangerfile.
117 118 119 |
# File 'lib/danger/danger_core/plugins/dangerfile_github_plugin.rb', line 117 def api @github.client end |
#base_commit ⇒ Object
The base commit to which the PR is going to be merged as a parent.
92 93 94 |
# File 'lib/danger/danger_core/plugins/dangerfile_github_plugin.rb', line 92 def base_commit pr_json[:base][:sha] end |
#branch_for_base ⇒ String
The branch to which the PR is going to be merged into.
76 77 78 |
# File 'lib/danger/danger_core/plugins/dangerfile_github_plugin.rb', line 76 def branch_for_base pr_json[:base][:ref] end |
#branch_for_head ⇒ String
The branch to which the PR is going to be merged from.
84 85 86 |
# File 'lib/danger/danger_core/plugins/dangerfile_github_plugin.rb', line 84 def branch_for_head pr_json[:head][:ref] end |
#head_commit ⇒ String
The head commit to which the PR is requesting to be merged from.
100 101 102 |
# File 'lib/danger/danger_core/plugins/dangerfile_github_plugin.rb', line 100 def head_commit pr_json[:head][:sha] end |
#pr_author ⇒ String
The username of the author of the Pull Request.
60 61 62 |
# File 'lib/danger/danger_core/plugins/dangerfile_github_plugin.rb', line 60 def pr_json[:user][:login].to_s end |
#pr_body ⇒ String
The body text of the Pull Request.
52 53 54 |
# File 'lib/danger/danger_core/plugins/dangerfile_github_plugin.rb', line 52 def pr_body pr_json[:body].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/pr_response.json).
109 110 111 |
# File 'lib/danger/danger_core/plugins/dangerfile_github_plugin.rb', line 109 def pr_json @github.pr_json end |
#pr_labels ⇒ String
The labels assigned to the Pull Request.
68 69 70 |
# File 'lib/danger/danger_core/plugins/dangerfile_github_plugin.rb', line 68 def pr_labels @github.issue_json[:labels].map { |l| l[:name] } end |
#pr_title ⇒ String
The title of the Pull Request.
44 45 46 |
# File 'lib/danger/danger_core/plugins/dangerfile_github_plugin.rb', line 44 def pr_title @github.pr_json[:title].to_s end |