@@ -16,9 +16,11 @@ import (
1616 access_model "code.gitea.io/gitea/models/perm/access"
1717 repo_model "code.gitea.io/gitea/models/repo"
1818 "code.gitea.io/gitea/models/unit"
19+ user_model "code.gitea.io/gitea/models/user"
1920 "code.gitea.io/gitea/modules/actions"
2021 "code.gitea.io/gitea/modules/git"
2122 "code.gitea.io/gitea/modules/log"
23+ "code.gitea.io/gitea/modules/reqctx"
2224 api "code.gitea.io/gitea/modules/structs"
2325 "code.gitea.io/gitea/modules/util"
2426 "code.gitea.io/gitea/services/context"
@@ -81,7 +83,7 @@ func getActionWorkflowEntry(ctx *context.APIContext, commit *git.Commit, folder
8183 }
8284}
8385
84- func disableOrEnableWorkflow (ctx * context.APIContext , workflowID string , isEnable bool ) error {
86+ func EnableOrDisableWorkflow (ctx * context.APIContext , workflowID string , isEnable bool ) error {
8587 workflow , err := GetActionWorkflow (ctx , workflowID )
8688 if err != nil {
8789 return err
@@ -137,11 +139,7 @@ func GetActionWorkflow(ctx *context.APIContext, workflowID string) (*api.ActionW
137139 return nil , util .NewNotExistErrorf ("workflow %q not found" , workflowID )
138140}
139141
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 {
145143 if workflowID == "" {
146144 return util .ErrWrapLocale (
147145 util .NewNotExistErrorf ("workflowID is empty" ),
@@ -157,7 +155,7 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
157155 }
158156
159157 // can not rerun job when workflow is disabled
160- cfgUnit := ctx . Repo . Repository .MustGetUnit (ctx , unit .TypeActions )
158+ cfgUnit := repo .MustGetUnit (ctx , unit .TypeActions )
161159 cfg := cfgUnit .ActionsConfig ()
162160 if cfg .IsWorkflowDisabled (workflowID ) {
163161 return util .ErrWrapLocale (
@@ -171,12 +169,12 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
171169 var runTargetCommit * git.Commit
172170 var err error
173171 if refName .IsTag () {
174- runTargetCommit , err = ctx . Repo . GitRepo .GetTagCommit (refName .TagName ())
172+ runTargetCommit , err = gitRepo .GetTagCommit (refName .TagName ())
175173 } else if refName .IsBranch () {
176- runTargetCommit , err = ctx . Repo . GitRepo .GetBranchCommit (refName .BranchName ())
174+ runTargetCommit , err = gitRepo .GetBranchCommit (refName .BranchName ())
177175 } else {
178176 refName = git .RefNameFromBranch (ref )
179- runTargetCommit , err = ctx . Repo . GitRepo .GetBranchCommit (ref )
177+ runTargetCommit , err = gitRepo .GetBranchCommit (ref )
180178 }
181179 if err != nil {
182180 return util .ErrWrapLocale (
@@ -233,9 +231,9 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
233231 workflowDispatchPayload := & api.WorkflowDispatchPayload {
234232 Workflow : workflowID ,
235233 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 }),
237235 Inputs : inputsWithDefaults ,
238- Sender : convert .ToUserWithAccessMode (ctx , ctx . Doer , perm .AccessModeNone ),
236+ Sender : convert .ToUserWithAccessMode (ctx , doer , perm .AccessModeNone ),
239237 }
240238 var eventPayload []byte
241239 if eventPayload , err = workflowDispatchPayload .JSONPayload (); err != nil {
@@ -244,10 +242,10 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
244242
245243 run := & actions_model.ActionRun {
246244 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 ,
249247 WorkflowID : workflowID ,
250- TriggerUserID : ctx . Doer .ID ,
248+ TriggerUserID : doer .ID ,
251249 Ref : string (refName ),
252250 CommitSHA : runTargetCommit .ID .String (),
253251 IsForkPullRequest : false ,
@@ -281,7 +279,3 @@ func DispatchActionWorkflow(ctx *context.Context, workflowID, ref string, proces
281279
282280 return nil
283281}
284-
285- func EnableActionWorkflow (ctx * context.APIContext , workflowID string ) error {
286- return disableOrEnableWorkflow (ctx , workflowID , true )
287- }
0 commit comments