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_labels(labels) ⇒ void
add labels to pull request.
-
#close ⇒ Sawyer::Resource
Close the pull request.
-
#initialize(dangerfile) ⇒ DangerGithubExt
constructor
A new instance of DangerGithubExt.
-
#labels ⇒ [String]
Get labels.
-
#mergeable? ⇒ boolean
Whether mergeable and mergeable status is clean.
-
#open ⇒ Sawyer::Resource
Open the pull request.
-
#remove_labels(labels) ⇒ void
remove labels from pull request.
-
#statuses ⇒ [Hash]
get current commit statuses.
-
#update_pr_body(body) ⇒ Sawyer::Resource
Update the body of pull request.
-
#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_labels(labels) ⇒ void
This method returns an undefined value.
add labels to pull request
74 75 76 77 78 |
# File 'lib/github_ext/plugin.rb', line 74 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 |
#close ⇒ Sawyer::Resource
Close the pull request
133 134 135 136 137 |
# File 'lib/github_ext/plugin.rb', line 133 def close @repo ||= self.pr_json.base.repo.full_name @number ||= self.pr_json.number self.api.update_pull_request(@repo, @number, {:state => 'closed'}) end |
#labels ⇒ [String]
Get labels
62 63 64 65 66 67 68 |
# File 'lib/github_ext/plugin.rb', line 62 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
Whether 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 |
#open ⇒ Sawyer::Resource
Open the pull request
142 143 144 145 146 |
# File 'lib/github_ext/plugin.rb', line 142 def open @repo ||= self.pr_json.base.repo.full_name @number ||= self.pr_json.number self.api.update_pull_request(@repo, @number, {:state => 'open'}) end |
#remove_labels(labels) ⇒ void
This method returns an undefined value.
remove labels from pull request
84 85 86 87 88 89 90 |
# File 'lib/github_ext/plugin.rb', line 84 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]
get current commit statuses
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/github_ext/plugin.rb', line 95 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
124 125 126 127 128 |
# File 'lib/github_ext/plugin.rb', line 124 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_title(title) ⇒ Sawyer::Resource
Update the title of the pull request
115 116 117 118 119 |
# File 'lib/github_ext/plugin.rb', line 115 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 |