Skip to content

Commit

Permalink
Support reopened pull/merge requests in OBS workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Dany Marcoux committed Sep 7, 2021
1 parent 00f8301 commit ec7307a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/api/app/models/scm_webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def closed_merged_pull_request?
(gitlab_merge_request? && ['close', 'merge'].include?(@payload[:action]))
end

def reopened_pull_request?
(github_pull_request? && @payload[:action] == 'reopened') ||
(gitlab_merge_request? && @payload[:action] == 'reopen')
end

private

def github_pull_request?
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/validators/scm_webhook_event_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class ScmWebhookEventValidator < ActiveModel::Validator
ALLOWED_GITHUB_EVENTS = ['pull_request'].freeze
ALLOWED_GITLAB_EVENTS = ['Merge Request Hook'].freeze

ALLOWED_PULL_REQUEST_ACTIONS = ['closed', 'opened', 'synchronize'].freeze
ALLOWED_MERGE_REQUEST_ACTIONS = ['close', 'merge', 'open', 'update'].freeze
ALLOWED_PULL_REQUEST_ACTIONS = ['closed', 'opened', 'reopened', 'synchronize'].freeze
ALLOWED_MERGE_REQUEST_ACTIONS = ['close', 'merge', 'open', 'reopen', 'update'].freeze

def validate(record)
@record = record
Expand Down
46 changes: 46 additions & 0 deletions src/api/spec/models/scm_webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,50 @@
it { is_expected.to be true }
end
end

describe '#reopened_pull_request?' do
subject { described_class.new(payload: payload).reopened_pull_request? }

context 'for an unsupported SCM' do
let(:payload) { { scm: 'GitHoob', event: 'pull_request', action: 'reopened' } }

it { is_expected.to be false }
end

context 'for an unsupported event from GitHub' do
let(:payload) { { scm: 'github', event: 'something', action: 'reopened' } }

it { is_expected.to be false }
end

context 'for an unsupported action from GitHub' do
let(:payload) { { scm: 'github', event: 'pull_request', action: 'something' } }

it { is_expected.to be false }
end

context 'for a reopened pull request from GitHub' do
let(:payload) { { scm: 'github', event: 'pull_request', action: 'reopened' } }

it { is_expected.to be true }
end

context 'for an unsupported event from GitLab' do
let(:payload) { { scm: 'gitlab', event: 'something', action: 'reopen' } }

it { is_expected.to be false }
end

context 'for an unsupported action from GitLab' do
let(:payload) { { scm: 'gitlab', event: 'Merge Request Hook', action: 'something' } }

it { is_expected.to be false }
end

context 'for a reopened merge request from GitLab' do
let(:payload) { { scm: 'gitlab', event: 'Merge Request Hook', action: 'reopen' } }

it { is_expected.to be true }
end
end
end
14 changes: 14 additions & 0 deletions src/api/spec/validators/scm_webhook_event_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@

it { is_expected.to be_valid }
end

context 'for a pull request which was reopened' do
let(:event) { 'pull_request' }
let(:action) { 'reopened' }

it { is_expected.to be_valid }
end
end

context 'when the SCM is GitLab' do
Expand Down Expand Up @@ -126,6 +133,13 @@

it { is_expected.to be_valid }
end

context 'for a merge request which was reopened' do
let(:event) { 'Merge Request Hook' }
let(:action) { 'reopen' }

it { is_expected.to be_valid }
end
end
end
end

0 comments on commit ec7307a

Please sign in to comment.