aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorJason Song <i@wolfogre.com>2022-09-04 17:18:07 +0800
committerGitHub <noreply@github.com>2022-09-04 12:18:07 +0300
commit93a610a819688b54d4565b8cbbae7cc04c552073 (patch)
tree21fa5f55d958aa01eab6e6e370c02c6bc45ca869 /routers/api
parent0887459ac68a7d3605ba0f4a51df97b76e7cae9e (diff)
downloadgitea-93a610a819688b54d4565b8cbbae7cc04c552073.tar.gz
gitea-93a610a819688b54d4565b8cbbae7cc04c552073.zip
Fill the specified ref in webhook test payload (#20961)
The webhook payload should use the right ref when it‘s specified in the testing request. The compare URL should not be empty, a URL like `compare/A...A` seems useless in most cases but is helpful when testing.
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/repo/hook.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/routers/api/v1/repo/hook.go b/routers/api/v1/repo/hook.go
index 8a546e581a..b17142c0f6 100644
--- a/routers/api/v1/repo/hook.go
+++ b/routers/api/v1/repo/hook.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils"
@@ -140,7 +141,7 @@ func TestHook(ctx *context.APIContext) {
// required: true
// - name: ref
// in: query
- // description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)"
+ // description: "The name of the commit/branch/tag, indicates which commit will be loaded to the webhook payload."
// type: string
// required: false
// responses:
@@ -153,6 +154,11 @@ func TestHook(ctx *context.APIContext) {
return
}
+ ref := git.BranchPrefix + ctx.Repo.Repository.DefaultBranch
+ if r := ctx.FormTrim("ref"); r != "" {
+ ref = r
+ }
+
hookID := ctx.ParamsInt64(":id")
hook, err := utils.GetRepoHook(ctx, ctx.Repo.Repository.ID, hookID)
if err != nil {
@@ -161,10 +167,12 @@ func TestHook(ctx *context.APIContext) {
commit := convert.ToPayloadCommit(ctx.Repo.Repository, ctx.Repo.Commit)
+ commitID := ctx.Repo.Commit.ID.String()
if err := webhook_service.PrepareWebhook(hook, ctx.Repo.Repository, webhook.HookEventPush, &api.PushPayload{
- Ref: git.BranchPrefix + ctx.Repo.Repository.DefaultBranch,
- Before: ctx.Repo.Commit.ID.String(),
- After: ctx.Repo.Commit.ID.String(),
+ Ref: ref,
+ Before: commitID,
+ After: commitID,
+ CompareURL: setting.AppURL + ctx.Repo.Repository.ComposeCompareURL(commitID, commitID),
Commits: []*api.PayloadCommit{commit},
HeadCommit: commit,
Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone),