diff --git a/app/controllers/redmine_github/webhooks_controller.rb b/app/controllers/redmine_github/webhooks_controller.rb index 203d819..620d671 100644 --- a/app/controllers/redmine_github/webhooks_controller.rb +++ b/app/controllers/redmine_github/webhooks_controller.rb @@ -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 diff --git a/lib/redmine_github/include/repositories_controller_patch.rb b/lib/redmine_github/include/repositories_controller_patch.rb index 1fb6b27..4cbf124 100644 --- a/lib/redmine_github/include/repositories_controller_patch.rb +++ b/lib/redmine_github/include/repositories_controller_patch.rb @@ -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 diff --git a/spec/github_rest_api/show_webhook_response.json.erb b/spec/github_rest_api/show_webhook_response.json.erb index 7223f29..6fe7455 100644 --- a/spec/github_rest_api/show_webhook_response.json.erb +++ b/spec/github_rest_api/show_webhook_response.json.erb @@ -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"}} diff --git a/spec/github_rest_api/update_webhook_response.json.erb b/spec/github_rest_api/update_webhook_response.json.erb index 62aa8b1..52c1c02 100644 --- a/spec/github_rest_api/update_webhook_response.json.erb +++ b/spec/github_rest_api/update_webhook_response.json.erb @@ -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"}} diff --git a/spec/lib/github_api/rest/webhook_spec.rb b/spec/lib/github_api/rest/webhook_spec.rb index 5b3ae55..06514dc 100644 --- a/spec/lib/github_api/rest/webhook_spec.rb +++ b/spec/lib/github_api/rest/webhook_spec.rb @@ -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 diff --git a/spec/models/redmine_github/pull_request_handler_spec.rb b/spec/models/redmine_github/pull_request_handler_spec.rb index d8d019e..22f9a0f 100644 --- a/spec/models/redmine_github/pull_request_handler_spec.rb +++ b/spec/models/redmine_github/pull_request_handler_spec.rb @@ -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) } diff --git a/spec/requests/hooks_spec.rb b/spec/requests/hooks_spec.rb index 77ea1ff..7ae6ae9 100644 --- a/spec/requests/hooks_spec.rb +++ b/spec/requests/hooks_spec.rb @@ -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' @@ -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' @@ -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