Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit a18b3a9

Browse files
authored
Merge pull request #159 from ndmckinley/add-label
Add a label to the PR.
2 parents 456b299 + 72e8fc4 commit a18b3a9

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ Set the status message for `concourse-ci` context on specified pull request.
182182

183183
* `merge.commit_msg`: *Optional.* Used with `merge` to set the commit message for the merge. Specify a file path to the merge commit message.
184184

185+
* `label`: *Optional.* A label to add to the pull request.
186+
185187
## Example pipeline
186188

187189
Please see this repo's [pipeline](https://github.com/jtarchie/pullrequest-resource/blob/master/.concourse.yml) for a perfect example.

assets/lib/commands/out.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ def output
6666
metadata << { 'name' => 'comment', 'value' => comment }
6767
end
6868

69+
if params.label
70+
Octokit.add_labels_to_an_issue(input.source.repo, id, [params.label])
71+
metadata << { 'name' => 'label', 'value' => params.label }
72+
end
73+
6974
if params.merge.method
7075
commit_msg = if params.merge.commit_msg
7176
commit_path = File.join(destination, params.merge.commit_msg)

spec/commands/out_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,26 @@ def stub_json(method, uri, body)
195195
end
196196
end
197197

198+
context 'when setting a status with a label' do
199+
before do
200+
stub_request(:post, "https://api.github.com/repos/jtarchie/test/issues/1/labels").with(
201+
body: "[\"test_label\"]").to_return(
202+
status: 200, body: "", headers: {})
203+
end
204+
it 'posts a comment to the PR\'s SHA' do
205+
stub_status_post
206+
stub_json(:post, 'https://api.github.com:443/repos/jtarchie/test/issues/1/comments', id: 1)
207+
208+
output, = put('params' => { 'status' => 'success', 'path' => 'resource', 'label' => 'test_label' }, 'source' => { 'repo' => 'jtarchie/test' })
209+
expect(output).to eq('version' => { 'ref' => @sha, 'pr' => '1' },
210+
'metadata' => [
211+
{ 'name' => 'status', 'value' => 'success' },
212+
{ 'name' => 'url', 'value' => 'http://example.com' },
213+
{ 'name' => 'label', 'value' => 'test_label' },
214+
])
215+
end
216+
end
217+
198218
context 'when the pull request is being release' do
199219
context 'and the build passed' do
200220
it 'sets into success mode' do

0 commit comments

Comments
 (0)