Class: Danger::DangerGithubExt
- Inherits:
-
DangerfileGitHubPlugin
- Object
- DangerfileGitHubPlugin
- Danger::DangerGithubExt
- Defined in:
- lib/github_ext/plugin.rb
Overview
This is Danger Plugin for GitHub extension. When installing this plugin, you can additional methods on github instance
Instance Method Summary collapse
-
#add_label(label, color = 'ffffff') ⇒ void
Add label with color to the pull request.
-
#add_labels(labels) ⇒ void
Add labels to the pull request.
-
#initialize(dangerfile) ⇒ DangerGithubExt
constructor
A new instance of DangerGithubExt.
-
#labels ⇒ [String]
deprecated
Deprecated.
Please use #pr_labels instead
-
#mergeable? ⇒ boolean
Determine if pull request is mergeable and mergeable status is clean.
-
#remove_labels(labels) ⇒ void
Remove labels from the pull request.
-
#statuses ⇒ [Hash]
List current statuses for the head commit.
-
#update_pr_body(body) ⇒ Sawyer::Resource
Update the body of pull request.
-
#update_pr_state(state) ⇒ Sawyer::Resource
Update the pull request state.
-
#update_pr_title(title) ⇒ Sawyer::Resource
Update the title of the pull request.
Constructor Details
#initialize(dangerfile) ⇒ DangerGithubExt
Returns a new instance of DangerGithubExt.
46 47 48 49 50 |
# File 'lib/github_ext/plugin.rb', line 46 def initialize(dangerfile) super(dangerfile) self.api.auto_paginate = true end |
Instance Method Details
#add_label(label, color = 'ffffff') ⇒ void
This method returns an undefined value.
Add label with color to the pull request
86 87 88 89 90 91 92 |
# File 'lib/github_ext/plugin.rb', line 86 def add_label(label, color = 'ffffff') @repo ||= self.pr_json.base.repo.full_name @number ||= self.pr_json.number self.api.update_label(@repo, label, {:color => color}) self.api.add_labels_to_an_issue(@repo, @number, Array(label)) end |
#add_labels(labels) ⇒ void
This method returns an undefined value.
Add labels to the pull request
75 76 77 78 79 |
# File 'lib/github_ext/plugin.rb', line 75 def add_labels(labels) @repo ||= self.pr_json.base.repo.full_name @number ||= self.pr_json.number self.api.add_labels_to_an_issue(@repo, @number, Array(labels)) end |
#labels ⇒ [String]
Please use #pr_labels instead
List labels for the pull request
63 64 65 66 67 68 69 |
# File 'lib/github_ext/plugin.rb', line 63 def labels @repo ||= self.pr_json.base.repo.full_name @number ||= self.pr_json.number self.api.labels_for_issue(@repo, @number).map { |issue| issue.name } end |
#mergeable? ⇒ boolean
Determine if pull request is mergeable and mergeable status is clean
55 56 57 |
# File 'lib/github_ext/plugin.rb', line 55 def mergeable? self.pr_json.attrs[:mergeable_state] == 'clean' && github.pr_json.attrs[:mergeable] end |
#remove_labels(labels) ⇒ void
This method returns an undefined value.
Remove labels from the pull request
98 99 100 101 102 103 104 |
# File 'lib/github_ext/plugin.rb', line 98 def remove_labels(labels) @repo ||= self.pr_json.base.repo.full_name @number ||= self.pr_json.number Array(labels).each do |label| self.api.remove_label(@repo, @number, label) end end |
#statuses ⇒ [Hash]
List current statuses for the head commit
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/github_ext/plugin.rb', line 109 def statuses @repo ||= self.pr_json.base.repo.full_name @sha ||= self.head_commit statuses = {} self.api.statuses(@repo, @sha).each do |status| statuses[status.context] ||= [] statuses[status.context].push({ context: status.context, state: status.state, date: status.updated_at }) end statuses.map {|_, val| val.sort{|a, b| b[:date] <=> a[:date] }[0] } end |
#update_pr_body(body) ⇒ Sawyer::Resource
Update the body of pull request
138 139 140 141 142 |
# File 'lib/github_ext/plugin.rb', line 138 def update_pr_body(body) @repo ||= self.pr_json.base.repo.full_name @number ||= self.pr_json.number self.api.update_pull_request(@repo, @number, {:body => body}) end |
#update_pr_state(state) ⇒ Sawyer::Resource
Update the pull request state
147 148 149 150 151 |
# File 'lib/github_ext/plugin.rb', line 147 def update_pr_state(state) @repo ||= self.pr_json.base.repo.full_name @number ||= self.pr_json.number self.api.update_pull_request(@repo, @number, {:state => state}) end |
#update_pr_title(title) ⇒ Sawyer::Resource
Update the title of the pull request
129 130 131 132 133 |
# File 'lib/github_ext/plugin.rb', line 129 def update_pr_title(title) @repo ||= self.pr_json.base.repo.full_name @number ||= self.pr_json.number self.api.update_pull_request(@repo, @number, {:title => title}) end |