@@ -13,6 +13,7 @@ import (
13
13
"code.gitea.io/gitea/modules/context"
14
14
"code.gitea.io/gitea/modules/convert"
15
15
"code.gitea.io/gitea/modules/git"
16
+ "code.gitea.io/gitea/modules/setting"
16
17
api "code.gitea.io/gitea/modules/structs"
17
18
"code.gitea.io/gitea/modules/web"
18
19
"code.gitea.io/gitea/routers/api/v1/utils"
@@ -140,7 +141,7 @@ func TestHook(ctx *context.APIContext) {
140
141
// required: true
141
142
// - name: ref
142
143
// 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. "
144
145
// type: string
145
146
// required: false
146
147
// responses:
@@ -153,6 +154,11 @@ func TestHook(ctx *context.APIContext) {
153
154
return
154
155
}
155
156
157
+ ref := git .BranchPrefix + ctx .Repo .Repository .DefaultBranch
158
+ if r := ctx .FormTrim ("ref" ); r != "" {
159
+ ref = r
160
+ }
161
+
156
162
hookID := ctx .ParamsInt64 (":id" )
157
163
hook , err := utils .GetRepoHook (ctx , ctx .Repo .Repository .ID , hookID )
158
164
if err != nil {
@@ -161,10 +167,12 @@ func TestHook(ctx *context.APIContext) {
161
167
162
168
commit := convert .ToPayloadCommit (ctx .Repo .Repository , ctx .Repo .Commit )
163
169
170
+ commitID := ctx .Repo .Commit .ID .String ()
164
171
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 ),
168
176
Commits : []* api.PayloadCommit {commit },
169
177
HeadCommit : commit ,
170
178
Repo : convert .ToRepo (ctx .Repo .Repository , perm .AccessModeNone ),
0 commit comments