-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class GiteaPayload | ||
attr_reader :event, :http_url, :webhook_payload | ||
|
||
def initialize(event, webhook_payload) | ||
@event = event | ||
@webhook_payload = webhook_payload | ||
@http_url = webhook_payload.dig(:repository, :clone_url) | ||
end | ||
|
||
def default_payload | ||
{ | ||
scm: 'gitea', | ||
event: event, | ||
api_endpoint: api_endpoint, | ||
http_url: http_url | ||
} | ||
end | ||
|
||
def payload | ||
raise AbstractMethodCalled | ||
end | ||
|
||
private | ||
|
||
def api_endpoint | ||
url = URI.parse(http_url) | ||
|
||
"#{url.scheme}://#{url.host}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,11 @@ | ||
class GiteaPayload::PullRequest | ||
attr_reader :event, :webhook_payload | ||
|
||
def initialize(event, webhook_payload) | ||
@event = event | ||
@webhook_payload = webhook_payload | ||
end | ||
|
||
class GiteaPayload::PullRequest < GiteaPayload | ||
def payload | ||
http_url = webhook_payload.dig(:repository, :clone_url) | ||
payload = { | ||
scm: 'gitea', | ||
event: event, | ||
api_endpoint: gitea_api_endpoint(http_url), | ||
http_url: http_url | ||
} | ||
|
||
payload.merge(commit_sha: webhook_payload.dig(:pull_request, :head, :sha), | ||
pr_number: webhook_payload[:number], | ||
source_branch: webhook_payload.dig(:pull_request, :head, :ref), | ||
target_branch: webhook_payload.dig(:pull_request, :base, :ref), | ||
action: webhook_payload[:action], | ||
source_repository_full_name: webhook_payload.dig(:pull_request, :head, :repo, :full_name), | ||
target_repository_full_name: webhook_payload.dig(:pull_request, :base, :repo, :full_name)) | ||
end | ||
|
||
private | ||
|
||
def gitea_api_endpoint(http_url) | ||
url = URI.parse(http_url) | ||
|
||
"#{url.scheme}://#{url.host}" | ||
default_payload.merge(commit_sha: webhook_payload.dig(:pull_request, :head, :sha), | ||
pr_number: webhook_payload[:number], | ||
source_branch: webhook_payload.dig(:pull_request, :head, :ref), | ||
target_branch: webhook_payload.dig(:pull_request, :base, :ref), | ||
action: webhook_payload[:action], | ||
source_repository_full_name: webhook_payload.dig(:pull_request, :head, :repo, :full_name), | ||
target_repository_full_name: webhook_payload.dig(:pull_request, :base, :repo, :full_name)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class GiteaPayload::Push < GiteaPayload | ||
def payload | ||
payload_ref = webhook_payload.fetch(:ref, '') | ||
payload = default_payload.merge( | ||
# We need this for Workflow::Step#branch_request_content_github | ||
source_repository_full_name: webhook_payload.dig(:repository, :full_name), | ||
# We need this for SCMStatusReporter#call | ||
target_repository_full_name: webhook_payload.dig(:repository, :full_name), | ||
ref: payload_ref, | ||
# We need this for Workflow::Step#branch_request_content_{github,gitlab} | ||
commit_sha: webhook_payload[:after], | ||
# We need this for Workflows::YAMLDownloader#download_url | ||
# when the push event is for commits, we get the branch name from ref. | ||
target_branch: payload_ref.sub('refs/heads/', '') | ||
) | ||
|
||
return payload unless payload_ref.start_with?('refs/tags/') | ||
|
||
# We need this for Workflow::Step#target_package_name | ||
# 'target_branch' will contain a commit SHA | ||
payload.merge(tag_name: payload_ref.sub('refs/tags/', ''), | ||
target_branch: webhook_payload.dig(:head_commit, :id), | ||
commit_sha: webhook_payload.dig(:head_commit, :id)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters