Skip to content

Commit

Permalink
Add Gitea to SCMWebhookEventValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
krauselukas authored and eduardoj committed Sep 27, 2022
1 parent 981aaa9 commit 380f399
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/api/app/validators/scm_webhook_event_validator.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
class SCMWebhookEventValidator < ActiveModel::Validator
ALLOWED_GITHUB_EVENTS = ['pull_request', 'push'].freeze
ALLOWED_GITHUB_AND_GITEA_EVENTS = ['pull_request', 'push'].freeze
ALLOWED_GITLAB_EVENTS = ['Merge Request Hook', 'Push Hook', 'Tag Push Hook'].freeze

def validate(record)
@record = record

return if valid_github_event? || valid_gitlab_event?
return if valid_github_or_gitea_event? || valid_gitlab_event?

# FIXME: This error message is wrong when the SCM isn't supported. This is an edge case, somebody most probably fiddled with the payload.
@record.errors.add(:base, 'Event not supported.')
end

private

def valid_github_event?
return false unless @record.payload[:scm] == 'github'
return false unless ALLOWED_GITHUB_EVENTS.include?(@record.payload[:event])
def valid_github_or_gitea_event?
return false unless ['github', 'gitea'].include?(@record.payload[:scm])
return false unless ALLOWED_GITHUB_AND_GITEA_EVENTS.include?(@record.payload[:event])

case @record.payload[:event]
when 'pull_request'
Expand Down

0 comments on commit 380f399

Please sign in to comment.