Skip to content
Open
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
3 changes: 2 additions & 1 deletion app/controllers/redmine_github/webhooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class WebhooksController < ActionController::Base
def dispatch_event
event = request.headers['x-github-event']
case event
when 'pull_request', 'pull_request_review', 'push', 'status'
# As documented in: https://docs.github.com/en/webhooks/webhook-events-and-payloads
when 'commit_comment', 'pull_request', 'pull_request_review', 'pull_request_review_comment', 'push', 'status'
PullRequestHandler.handle(@repository, event, params)
head :ok
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create_github_webhook_if_needed
content_type: 'json',
secret: @repository.webhook_secret
},
events: %w[pull_request pull_request_review push status],
events: %w[commit_comment pull_request pull_request_review pull_request_review_comment push status],
active: true
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/github_rest_api/show_webhook_response.json.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type":"Repository","id":<%= variables[:webhook_id] %>,"name":"web","active":true,"events":["pull_request","pull_request_review","push","status"],"config":{"content_type":"json","insecure_ssl":"0","secret":"********","url":"<%= variables[:webhook_url] %>"},"url":"https://api.github.com/repos/company/repo/hooks/<%= variables[:webhook_id] %>","test_url":"https://api.github.com/repos/company/repo/hooks/<%= variables[:webhook_id] %>/test","ping_url":"https://api.github.com/repos/company/repo/hooks/<%= variables[:webhook_id] %>/pings","last_response":{"code":200,"status":"active","message":"OK"}}
{"type":"Repository","id":<%= variables[:webhook_id] %>,"name":"web","active":true,"events":["commit_comment","pull_request","pull_request_review","pull_request_review","push","status"],"config":{"content_type":"json","insecure_ssl":"0","secret":"********","url":"<%= variables[:webhook_url] %>"},"url":"https://api.github.com/repos/company/repo/hooks/<%= variables[:webhook_id] %>","test_url":"https://api.github.com/repos/company/repo/hooks/<%= variables[:webhook_id] %>/test","ping_url":"https://api.github.com/repos/company/repo/hooks/<%= variables[:webhook_id] %>/pings","last_response":{"code":200,"status":"active","message":"OK"}}
2 changes: 1 addition & 1 deletion spec/github_rest_api/update_webhook_response.json.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type":"Repository","id":<%= variables[:webhook_id] %>,"name":"web","active":true,"events":["commit_comment","pull_request","pull_request_review","push","status"],"config":{"content_type":"json","insecure_ssl":"0","secret":"********","url":"<%= variables[:webhook_url] %>"},"url":"https://api.github.com/repos/company/repo/hooks/<%= variables[:webhook_id] %>","test_url":"https://api.github.com/repos/company/repo/hooks/<%= variables[:webhook_id] %>/test","ping_url":"https://api.github.com/repos/company/repo/hooks/<%= variables[:webhook_id] %>/pings","last_response":{"code":200,"status":"active","message":"OK"}}
{"type":"Repository","id":<%= variables[:webhook_id] %>,"name":"web","active":true,"events":["commit_comment","pull_request","pull_request_review","pull_request_review_comment","push","status"],"config":{"content_type":"json","insecure_ssl":"0","secret":"********","url":"<%= variables[:webhook_url] %>"},"url":"https://api.github.com/repos/company/repo/hooks/<%= variables[:webhook_id] %>","test_url":"https://api.github.com/repos/company/repo/hooks/<%= variables[:webhook_id] %>/test","ping_url":"https://api.github.com/repos/company/repo/hooks/<%= variables[:webhook_id] %>/pings","last_response":{"code":200,"status":"active","message":"OK"}}
2 changes: 1 addition & 1 deletion spec/lib/github_api/rest/webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

let(:project) { create :project }
let(:webhook_url) { "https://host.site/project/#{project.id}/hook" }
let(:events) { %w[pull_request pull_request_review push status] }
let(:events) { %w[pull_request pull_request_review pull_request_review_comment push status] }
let(:repository) { create :github_repository, url: 'https://github.com/company/repo.git' }
let(:new_webhook) { RedmineGithub::GithubApi::Rest::Webhook.new(repository) }
let(:params) do
Expand Down
13 changes: 13 additions & 0 deletions spec/models/redmine_github/pull_request_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@
}
end

describe '.handle pull_request_review_comment' do
subject { RedmineGithub::PullRequestHandler.handle(repository, 'pull_request_review_comment', payload) }

let(:payload) { {} }

it {
expect(RedmineGithub::PullRequestHandler).to(
receive(:handle_pull_request).with(repository, payload)
)
subject
}
end

describe '.handle push' do
subject { RedmineGithub::PullRequestHandler.handle(repository, 'push', payload) }

Expand Down
12 changes: 11 additions & 1 deletion spec/requests/hooks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
let(:signature) { 'sha256=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), repository.webhook_secret, params) }
let(:repository) { create(:github_repository) }

context 'event type with commit_comment' do
let(:event) { 'commit_comment' }
include_examples 'call handler with correct arguments and return http ok'
end

context 'event type with pull_request' do
let(:event) { 'pull_request' }
include_examples 'call handler with correct arguments and return http ok'
Expand All @@ -36,6 +41,11 @@
include_examples 'call handler with correct arguments and return http ok'
end

context 'event type with pull_request_review_comment' do
let(:event) { 'pull_request_review_comment' }
include_examples 'call handler with correct arguments and return http ok'
end

context 'event type with push' do
let(:event) { 'push' }
include_examples 'call handler with correct arguments and return http ok'
Expand All @@ -51,7 +61,7 @@
include_examples 'ignored and return http ok'
end

context 'signure is wrong' do
context 'signature is wrong' do
it {
headers = { 'x-hub-signature-256' => 'bad-signature', 'x-github-event' => 'status', content_type: :json }
post redmine_github_webhook_path(repository_id: repository.id.to_s, format: :json), params: params, headers: headers
Expand Down