@@ -19,6 +19,7 @@ import (
1919 "code.gitea.io/gitea/modules/base"
2020 "code.gitea.io/gitea/modules/container"
2121 "code.gitea.io/gitea/modules/git"
22+ "code.gitea.io/gitea/modules/gitrepo"
2223 "code.gitea.io/gitea/modules/log"
2324 "code.gitea.io/gitea/modules/optional"
2425 "code.gitea.io/gitea/modules/setting"
@@ -38,6 +39,7 @@ const (
3839
3940type Workflow struct {
4041 Entry git.TreeEntry
42+ Global bool
4143 ErrMsg string
4244}
4345
@@ -71,9 +73,19 @@ func List(ctx *context.Context) {
7173
7274 var workflows []Workflow
7375 var curWorkflow * model.Workflow
76+ var globalEntries []* git.TreeEntry
77+ globalWorkflow , err := db .Find [actions_model.RequireAction ](ctx , actions_model.FindRequireActionOptions {
78+ OrgID : ctx .Repo .Repository .Owner .ID ,
79+ })
80+ if err != nil {
81+ ctx .ServerError ("Global Workflow DB find fail" , err )
82+ return
83+ }
7484 if empty , err := ctx .Repo .GitRepo .IsEmpty (); err != nil {
7585 ctx .ServerError ("IsEmpty" , err )
76- return
86+ if len (globalWorkflow ) < 1 {
87+ return
88+ }
7789 } else if ! empty {
7890 commit , err := ctx .Repo .GitRepo .GetBranchCommit (ctx .Repo .Repository .DefaultBranch )
7991 if err != nil {
@@ -85,6 +97,23 @@ func List(ctx *context.Context) {
8597 ctx .ServerError ("ListWorkflows" , err )
8698 return
8799 }
100+ for _ , gEntry := range globalWorkflow {
101+ if gEntry .RepoName == ctx .Repo .Repository .Name {
102+ log .Trace ("Same Repo conflict: %s\n " , gEntry .RepoName )
103+ continue
104+ }
105+ gRepo , _ := repo_model .GetRepositoryByName (ctx , gEntry .OrgID , gEntry .RepoName )
106+ gGitRepo , _ := gitrepo .OpenRepository (git .DefaultContext , gRepo )
107+ // it may be a hack for now..... not sure any better way to do this
108+ gCommit , _ := gGitRepo .GetBranchCommit (gRepo .DefaultBranch )
109+ gEntries , _ := actions .ListWorkflows (gCommit )
110+ for _ , entry := range gEntries {
111+ if gEntry .WorkflowName == entry .Name () {
112+ globalEntries = append (globalEntries , entry )
113+ entries = append (entries , entry )
114+ }
115+ }
116+ }
88117
89118 // Get all runner labels
90119 runners , err := db .Find [actions_model.ActionRunner ](ctx , actions_model.FindRunnerOptions {
@@ -103,7 +132,14 @@ func List(ctx *context.Context) {
103132
104133 workflows = make ([]Workflow , 0 , len (entries ))
105134 for _ , entry := range entries {
106- workflow := Workflow {Entry : * entry }
135+ var workflowIsGlobal bool
136+ workflowIsGlobal = false
137+ for i := range globalEntries {
138+ if globalEntries [i ] == entry {
139+ workflowIsGlobal = true
140+ }
141+ }
142+ workflow := Workflow {Entry : * entry , Global : workflowIsGlobal }
107143 content , err := actions .GetContentFromEntry (entry )
108144 if err != nil {
109145 ctx .ServerError ("GetContentFromEntry" , err )
@@ -165,6 +201,10 @@ func List(ctx *context.Context) {
165201 page = 1
166202 }
167203
204+ workflow := ctx .FormString ("workflow" )
205+ isGlobal := false
206+ ctx .Data ["CurWorkflow" ] = workflow
207+
168208 actionsConfig := ctx .Repo .Repository .MustGetUnit (ctx , unit .TypeActions ).ActionsConfig ()
169209 ctx .Data ["ActionsConfig" ] = actionsConfig
170210
@@ -205,6 +245,9 @@ func List(ctx *context.Context) {
205245 ctx .Data ["Tags" ] = tags
206246 }
207247 }
248+ ctx .Data ["CurWorkflowDisabled" ] = actionsConfig .IsWorkflowDisabled (workflow )
249+ ctx .Data ["CurGlobalWorkflowEnable" ] = actionsConfig .IsGlobalWorkflowEnabled (workflow )
250+ isGlobal = actionsConfig .IsGlobalWorkflowEnabled (workflow )
208251 }
209252
210253 // if status or actor query param is not given to frontend href, (href="/<repoLink>/actions")
@@ -261,6 +304,9 @@ func List(ctx *context.Context) {
261304 pager .AddParamString ("workflow" , workflowID )
262305 pager .AddParamString ("actor" , fmt .Sprint (actorID ))
263306 pager .AddParamString ("status" , fmt .Sprint (status ))
307+ if isGlobal {
308+ pager .AddParamString ("global" , fmt .Sprint (isGlobal ))
309+ }
264310 ctx .Data ["Page" ] = pager
265311 ctx .Data ["HasWorkflowsOrRuns" ] = len (workflows ) > 0 || len (runs ) > 0
266312
0 commit comments