@@ -32,8 +32,9 @@ import (
3232)
3333
3434const (
35- tplListActions templates.TplName = "repo/actions/list"
36- tplViewActions templates.TplName = "repo/actions/view"
35+ tplListActions templates.TplName = "repo/actions/list"
36+ tplDispatchInputsActions templates.TplName = "repo/actions/workflow_dispatch_inputs"
37+ tplViewActions templates.TplName = "repo/actions/view"
3738)
3839
3940type Workflow struct {
@@ -62,6 +63,14 @@ func MustEnableActions(ctx *context.Context) {
6263}
6364
6465func List (ctx * context.Context ) {
66+ renderListAndWorkflowDispatchTemplate (ctx , tplListActions , false )
67+ }
68+
69+ func WorkflowDispatchInputs (ctx * context.Context ) {
70+ renderListAndWorkflowDispatchTemplate (ctx , tplDispatchInputsActions , true )
71+ }
72+
73+ func renderListAndWorkflowDispatchTemplate (ctx * context.Context , tplName templates.TplName , inputsOnly bool ) {
6574 ctx .Data ["Title" ] = ctx .Tr ("actions.actions" )
6675 ctx .Data ["PageIsActions" ] = true
6776 workflowID := ctx .FormString ("workflow" )
@@ -75,10 +84,34 @@ func List(ctx *context.Context) {
7584 ctx .ServerError ("IsEmpty" , err )
7685 return
7786 } else if ! empty {
78- commit , err := ctx .Repo .GitRepo .GetBranchCommit (ctx .Repo .Repository .DefaultBranch )
79- if err != nil {
80- ctx .ServerError ("GetBranchCommit" , err )
81- return
87+ var commit * git.Commit
88+ if inputsOnly {
89+ ref := ctx .FormString ("ref" )
90+ if len (ref ) == 0 {
91+ ctx .ServerError ("ref" , nil )
92+ return
93+ }
94+ // get target commit of run from specified ref
95+ refName := git .RefName (ref )
96+ var err error
97+ if refName .IsTag () {
98+ commit , err = ctx .Repo .GitRepo .GetTagCommit (refName .TagName ())
99+ } else if refName .IsBranch () {
100+ commit , err = ctx .Repo .GitRepo .GetBranchCommit (refName .BranchName ())
101+ } else {
102+ ctx .ServerError ("git_ref_name_error" , nil )
103+ return
104+ }
105+ if err != nil {
106+ ctx .ServerError ("target_ref_not_exist" , err )
107+ return
108+ }
109+ } else {
110+ commit , err = ctx .Repo .GitRepo .GetBranchCommit (ctx .Repo .Repository .DefaultBranch )
111+ if err != nil {
112+ ctx .ServerError ("GetBranchCommit" , err )
113+ return
114+ }
82115 }
83116 entries , err := actions .ListWorkflows (commit )
84117 if err != nil {
@@ -207,65 +240,67 @@ func List(ctx *context.Context) {
207240 }
208241 }
209242
210- // if status or actor query param is not given to frontend href, (href="/<repoLink>/actions")
211- // they will be 0 by default, which indicates get all status or actors
212- ctx .Data ["CurActor" ] = actorID
213- ctx .Data ["CurStatus" ] = status
214- if actorID > 0 || status > int (actions_model .StatusUnknown ) {
215- ctx .Data ["IsFiltered" ] = true
216- }
243+ if ! inputsOnly {
244+ // if status or actor query param is not given to frontend href, (href="/<repoLink>/actions")
245+ // they will be 0 by default, which indicates get all status or actors
246+ ctx .Data ["CurActor" ] = actorID
247+ ctx .Data ["CurStatus" ] = status
248+ if actorID > 0 || status > int (actions_model .StatusUnknown ) {
249+ ctx .Data ["IsFiltered" ] = true
250+ }
217251
218- opts := actions_model.FindRunOptions {
219- ListOptions : db.ListOptions {
220- Page : page ,
221- PageSize : convert .ToCorrectPageSize (ctx .FormInt ("limit" )),
222- },
223- RepoID : ctx .Repo .Repository .ID ,
224- WorkflowID : workflowID ,
225- TriggerUserID : actorID ,
226- }
252+ opts := actions_model.FindRunOptions {
253+ ListOptions : db.ListOptions {
254+ Page : page ,
255+ PageSize : convert .ToCorrectPageSize (ctx .FormInt ("limit" )),
256+ },
257+ RepoID : ctx .Repo .Repository .ID ,
258+ WorkflowID : workflowID ,
259+ TriggerUserID : actorID ,
260+ }
227261
228- // if status is not StatusUnknown, it means user has selected a status filter
229- if actions_model .Status (status ) != actions_model .StatusUnknown {
230- opts .Status = []actions_model.Status {actions_model .Status (status )}
231- }
262+ // if status is not StatusUnknown, it means user has selected a status filter
263+ if actions_model .Status (status ) != actions_model .StatusUnknown {
264+ opts .Status = []actions_model.Status {actions_model .Status (status )}
265+ }
232266
233- runs , total , err := db .FindAndCount [actions_model.ActionRun ](ctx , opts )
234- if err != nil {
235- ctx .ServerError ("FindAndCount" , err )
236- return
237- }
267+ runs , total , err := db .FindAndCount [actions_model.ActionRun ](ctx , opts )
268+ if err != nil {
269+ ctx .ServerError ("FindAndCount" , err )
270+ return
271+ }
238272
239- for _ , run := range runs {
240- run .Repo = ctx .Repo .Repository
241- }
273+ for _ , run := range runs {
274+ run .Repo = ctx .Repo .Repository
275+ }
242276
243- if err := actions_model .RunList (runs ).LoadTriggerUser (ctx ); err != nil {
244- ctx .ServerError ("LoadTriggerUser" , err )
245- return
246- }
277+ if err := actions_model .RunList (runs ).LoadTriggerUser (ctx ); err != nil {
278+ ctx .ServerError ("LoadTriggerUser" , err )
279+ return
280+ }
247281
248- if err := loadIsRefDeleted (ctx , ctx .Repo .Repository .ID , runs ); err != nil {
249- log .Error ("LoadIsRefDeleted" , err )
250- }
282+ if err := loadIsRefDeleted (ctx , ctx .Repo .Repository .ID , runs ); err != nil {
283+ log .Error ("LoadIsRefDeleted" , err )
284+ }
251285
252- ctx .Data ["Runs" ] = runs
286+ ctx .Data ["Runs" ] = runs
253287
254- actors , err := actions_model .GetActors (ctx , ctx .Repo .Repository .ID )
255- if err != nil {
256- ctx .ServerError ("GetActors" , err )
257- return
258- }
259- ctx .Data ["Actors" ] = shared_user .MakeSelfOnTop (ctx .Doer , actors )
288+ actors , err := actions_model .GetActors (ctx , ctx .Repo .Repository .ID )
289+ if err != nil {
290+ ctx .ServerError ("GetActors" , err )
291+ return
292+ }
293+ ctx .Data ["Actors" ] = shared_user .MakeSelfOnTop (ctx .Doer , actors )
260294
261- ctx .Data ["StatusInfoList" ] = actions_model .GetStatusInfoList (ctx )
295+ ctx .Data ["StatusInfoList" ] = actions_model .GetStatusInfoList (ctx )
262296
263- pager := context .NewPagination (int (total ), opts .PageSize , opts .Page , 5 )
264- pager .AddParamFromRequest (ctx .Req )
265- ctx .Data ["Page" ] = pager
266- ctx .Data ["HasWorkflowsOrRuns" ] = len (workflows ) > 0 || len (runs ) > 0
297+ pager := context .NewPagination (int (total ), opts .PageSize , opts .Page , 5 )
298+ pager .AddParamFromRequest (ctx .Req )
299+ ctx .Data ["Page" ] = pager
300+ ctx .Data ["HasWorkflowsOrRuns" ] = len (workflows ) > 0 || len (runs ) > 0
301+ }
267302
268- ctx .HTML (http .StatusOK , tplListActions )
303+ ctx .HTML (http .StatusOK , tplName )
269304}
270305
271306// loadIsRefDeleted loads the IsRefDeleted field for each run in the list.
0 commit comments