fix: prefix webhook action in header bot not the payload

This commit is contained in:
Derrick Hammer 2024-02-12 04:14:46 -05:00
parent 7453fa48ee
commit 6aed2bfaae
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 6 additions and 4 deletions

View File

@ -389,7 +389,7 @@ func countReaction(reactions []*gitea.Reaction, reactionType string) int {
return count return count
} }
func translatePrAction(action structs.HookIssueAction) string { func translatePrAction(action structs.HookIssueAction, prefix bool) string {
translatedAction := "" translatedAction := ""
switch action { switch action {
@ -429,7 +429,9 @@ func translatePrAction(action structs.HookIssueAction) string {
translatedAction = "unknown_action" translatedAction = "unknown_action"
} }
translatedAction = fmt.Sprintf("pull_request.%s", translatedAction) if prefix {
translatedAction = fmt.Sprintf("pull_request.%s", translatedAction)
}
return translatedAction return translatedAction
} }

View File

@ -15,7 +15,7 @@ func convertPullRequestEvent(event *structs.PullRequestPayload) *github.PullRequ
} }
return &github.PullRequestEvent{ return &github.PullRequestEvent{
Action: stringPtr(translatePrAction(event.Action)), Action: stringPtr(translatePrAction(event.Action, false)),
PullRequest: convertPullRequest(event.PullRequest), PullRequest: convertPullRequest(event.PullRequest),
Repo: convertCoreRepo(event.Repository), Repo: convertCoreRepo(event.Repository),
Assignee: convertCoreUser(event.PullRequest.Assignee), Assignee: convertCoreUser(event.PullRequest.Assignee),

View File

@ -30,7 +30,7 @@ func NewWebhookManager(cfg *config.Config, db *gorm.DB, logger *zap.Logger) *Web
func (whm *WebhookManager) HandlePullRequest(request *giteaTypes.PullRequestPayload, r *http.Request) { func (whm *WebhookManager) HandlePullRequest(request *giteaTypes.PullRequestPayload, r *http.Request) {
ghEvent := convertPullRequestEvent(request) ghEvent := convertPullRequestEvent(request)
githubAction := translatePrAction(request.Action) githubAction := translatePrAction(request.Action, true)
r.Header.Set("X-GitHub-Event", githubAction) r.Header.Set("X-GitHub-Event", githubAction)
whm.sendWebhooks(ghEvent, r) whm.sendWebhooks(ghEvent, r)