@@ -16,9 +16,11 @@ import (
16
16
access_model "code.gitea.io/gitea/models/perm/access"
17
17
repo_model "code.gitea.io/gitea/models/repo"
18
18
"code.gitea.io/gitea/models/unit"
19
+ user_model "code.gitea.io/gitea/models/user"
19
20
"code.gitea.io/gitea/modules/actions"
20
21
"code.gitea.io/gitea/modules/git"
21
22
"code.gitea.io/gitea/modules/log"
23
+ "code.gitea.io/gitea/modules/reqctx"
22
24
api "code.gitea.io/gitea/modules/structs"
23
25
"code.gitea.io/gitea/modules/util"
24
26
"code.gitea.io/gitea/services/context"
@@ -81,7 +83,7 @@ func getActionWorkflowEntry(ctx *context.APIContext, commit *git.Commit, folder
81
83
}
82
84
}
83
85
84
- func disableOrEnableWorkflow (ctx * context.APIContext , workflowID string , isEnable bool ) error {
86
+ func EnableOrDisableWorkflow (ctx * context.APIContext , workflowID string , isEnable bool ) error {
85
87
workflow , err := GetActionWorkflow (ctx , workflowID )
86
88
if err != nil {
87
89
return err
@@ -137,11 +139,7 @@ func GetActionWorkflow(ctx *context.APIContext, workflowID string) (*api.ActionW
137
139
return nil , util .NewNotExistErrorf ("workflow %q not found" , workflowID )
138
140
}
139
141
140
- func DisableActionWorkflow (ctx * context.APIContext , workflowID string ) error {
141
- return disableOrEnableWorkflow (ctx , workflowID , false )
142
- }
143
-
144
- func DispatchActionWorkflow (ctx * context.Context , workflowID , ref string , processInputs func (model * model.WorkflowDispatch , inputs map [string ]any ) error ) error {
142
+ func DispatchActionWorkflow (ctx reqctx.RequestContext , doer * user_model.User , repo * repo_model.Repository , gitRepo * git.Repository , workflowID , ref string , processInputs func (model * model.WorkflowDispatch , inputs map [string ]any ) error ) error {
145
143
if workflowID == "" {
146
144
return util .ErrWrapLocale (
147
145
util .NewNotExistErrorf ("workflowID is empty" ),
@@ -157,7 +155,7 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
157
155
}
158
156
159
157
// can not rerun job when workflow is disabled
160
- cfgUnit := ctx . Repo . Repository .MustGetUnit (ctx , unit .TypeActions )
158
+ cfgUnit := repo .MustGetUnit (ctx , unit .TypeActions )
161
159
cfg := cfgUnit .ActionsConfig ()
162
160
if cfg .IsWorkflowDisabled (workflowID ) {
163
161
return util .ErrWrapLocale (
@@ -171,12 +169,12 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
171
169
var runTargetCommit * git.Commit
172
170
var err error
173
171
if refName .IsTag () {
174
- runTargetCommit , err = ctx . Repo . GitRepo .GetTagCommit (refName .TagName ())
172
+ runTargetCommit , err = gitRepo .GetTagCommit (refName .TagName ())
175
173
} else if refName .IsBranch () {
176
- runTargetCommit , err = ctx . Repo . GitRepo .GetBranchCommit (refName .BranchName ())
174
+ runTargetCommit , err = gitRepo .GetBranchCommit (refName .BranchName ())
177
175
} else {
178
176
refName = git .RefNameFromBranch (ref )
179
- runTargetCommit , err = ctx . Repo . GitRepo .GetBranchCommit (ref )
177
+ runTargetCommit , err = gitRepo .GetBranchCommit (ref )
180
178
}
181
179
if err != nil {
182
180
return util .ErrWrapLocale (
@@ -233,9 +231,9 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
233
231
workflowDispatchPayload := & api.WorkflowDispatchPayload {
234
232
Workflow : workflowID ,
235
233
Ref : ref ,
236
- Repository : convert .ToRepo (ctx , ctx . Repo . Repository , access_model.Permission {AccessMode : perm .AccessModeNone }),
234
+ Repository : convert .ToRepo (ctx , repo , access_model.Permission {AccessMode : perm .AccessModeNone }),
237
235
Inputs : inputsWithDefaults ,
238
- Sender : convert .ToUserWithAccessMode (ctx , ctx . Doer , perm .AccessModeNone ),
236
+ Sender : convert .ToUserWithAccessMode (ctx , doer , perm .AccessModeNone ),
239
237
}
240
238
var eventPayload []byte
241
239
if eventPayload , err = workflowDispatchPayload .JSONPayload (); err != nil {
@@ -244,10 +242,10 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
244
242
245
243
run := & actions_model.ActionRun {
246
244
Title : strings .SplitN (runTargetCommit .CommitMessage , "\n " , 2 )[0 ],
247
- RepoID : ctx . Repo . Repository .ID ,
248
- OwnerID : ctx . Repo . Repository .OwnerID ,
245
+ RepoID : repo .ID ,
246
+ OwnerID : repo .OwnerID ,
249
247
WorkflowID : workflowID ,
250
- TriggerUserID : ctx . Doer .ID ,
248
+ TriggerUserID : doer .ID ,
251
249
Ref : string (refName ),
252
250
CommitSHA : runTargetCommit .ID .String (),
253
251
IsForkPullRequest : false ,
@@ -281,7 +279,3 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
281
279
282
280
return nil
283
281
}
284
-
285
- func EnableActionWorkflow (ctx * context.APIContext , workflowID string ) error {
286
- return disableOrEnableWorkflow (ctx , workflowID , true )
287
- }
0 commit comments