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

post a comment when the 'comment' param exists #24

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Set the status message for `concourse-ci` context on specified pull request.
(defaults to `status`). Any context will be prepended with `concourse-ci`, so
a context of `unit-tests` will appear as `concourse-ci/unit-tests` on Github.

* `comment`: *Optional.* The file path of the comment message. Comment owner is same with the owner of `access_token`.

## Example pipeline

This is what I am currently using to test this resource on Concourse.
Expand Down
8 changes: 8 additions & 0 deletions assets/lib/out.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@
context: context
).create!

if input['params']['comment']
comment_path = File.join(destination, input['params']['comment'])
raise %(`path` "#{input['params']['comment']}" does not exist) unless File.exist?(comment_path)

comment = File.read(comment_path, encoding: Encoding::UTF_8)
Octokit.add_comment(input['source']['repo'], id, comment)
end

json!(version: version, metadata: metadata)
17 changes: 17 additions & 0 deletions spec/integration/out_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ def request_body(method, url)
])
end

it 'set into success mode with posting a comment' do
File.open(File.join(dest_dir, 'comment'), 'w+') do |f|
f.write('message')
end
proxy.stub("https://api.github.com:443/repos/jtarchie/test/statuses/#{@sha}", method: :post)
proxy.stub("https://api.github.com:443/repos/jtarchie/test/issues/1/comments", method: :post)
.and_return(json: { id: 1 })

output, error = put(params: { status: 'success', path: 'resource', comment: 'resource/comment' }, source: { repo: 'jtarchie/test' })
expect(output).to eq('version' => { 'ref' => @sha, 'pr' => '1' },
'metadata' => [
{ 'name' => 'status', 'value' => 'success' },
{ 'name' => 'url', 'value' => 'http://example.com' }
])
end


context 'with bad params' do
it 'raises an error when path is missing' do
_, error = put(params: { status: 'pending' }, source: { repo: 'jtarchie/test' })
Expand Down