@@ -13,6 +13,7 @@ import (
1313 "code.gitea.io/gitea/modules/context"
1414 "code.gitea.io/gitea/modules/convert"
1515 "code.gitea.io/gitea/modules/git"
16+ "code.gitea.io/gitea/modules/setting"
1617 api "code.gitea.io/gitea/modules/structs"
1718 "code.gitea.io/gitea/modules/web"
1819 "code.gitea.io/gitea/routers/api/v1/utils"
@@ -140,7 +141,7 @@ func TestHook(ctx *context.APIContext) {
140141 // required: true
141142 // - name: ref
142143 // in: query
143- // description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master) "
144+ // description: "The name of the commit/branch/tag, indicates which commit will be loaded to the webhook payload. "
144145 // type: string
145146 // required: false
146147 // responses:
@@ -153,6 +154,11 @@ func TestHook(ctx *context.APIContext) {
153154 return
154155 }
155156
157+ ref := git .BranchPrefix + ctx .Repo .Repository .DefaultBranch
158+ if r := ctx .FormTrim ("ref" ); r != "" {
159+ ref = r
160+ }
161+
156162 hookID := ctx .ParamsInt64 (":id" )
157163 hook , err := utils .GetRepoHook (ctx , ctx .Repo .Repository .ID , hookID )
158164 if err != nil {
@@ -161,10 +167,12 @@ func TestHook(ctx *context.APIContext) {
161167
162168 commit := convert .ToPayloadCommit (ctx .Repo .Repository , ctx .Repo .Commit )
163169
170+ commitID := ctx .Repo .Commit .ID .String ()
164171 if err := webhook_service .PrepareWebhook (hook , ctx .Repo .Repository , webhook .HookEventPush , & api.PushPayload {
165- Ref : git .BranchPrefix + ctx .Repo .Repository .DefaultBranch ,
166- Before : ctx .Repo .Commit .ID .String (),
167- After : ctx .Repo .Commit .ID .String (),
172+ Ref : ref ,
173+ Before : commitID ,
174+ After : commitID ,
175+ CompareURL : setting .AppURL + ctx .Repo .Repository .ComposeCompareURL (commitID , commitID ),
168176 Commits : []* api.PayloadCommit {commit },
169177 HeadCommit : commit ,
170178 Repo : convert .ToRepo (ctx .Repo .Repository , perm .AccessModeNone ),
0 commit comments