Skip to content

show workflow names for other branchs on action list sidebar also #28333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions models/actions/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{
FixtureFiles: []string{
"action_runner_token.yml",
"action_run.yml",
},
})
}
12 changes: 12 additions & 0 deletions models/actions/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ func (run *ActionRun) GetPushEventPayload() (*api.PushPayload, error) {
return nil, fmt.Errorf("event %s is not a push event", run.Event)
}

func FindWorkflowIDsByRepoID(ctx context.Context, repoID int64) ([]string, error) {
ids := make([]string, 0, 10)

err := db.GetEngine(ctx).Table(new(ActionRun)).Where("repo_id = ?", repoID).
Select("workflow_id").Distinct("workflow_id").Find(&ids)
if err != nil {
return nil, err
}

return ids, nil
}

func (run *ActionRun) GetPullRequestEventPayload() (*api.PullRequestPayload, error) {
if run.Event == webhook_module.HookEventPullRequest || run.Event == webhook_module.HookEventPullRequestSync {
var payload api.PullRequestPayload
Expand Down
22 changes: 22 additions & 0 deletions models/actions/run_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package actions

import (
"testing"

"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"

"github.com/stretchr/testify/assert"
)

func TestFindWorkflowIDsByRepoID(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())

ids, err := FindWorkflowIDsByRepoID(db.DefaultContext, 4)
assert.NoError(t, err)

assert.EqualValues(t, []string{"artifact.yaml"}, ids)
}
28 changes: 27 additions & 1 deletion routers/web/repo/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/routers/web/repo"
"code.gitea.io/gitea/services/convert"
Expand All @@ -32,6 +33,7 @@ const (
type Workflow struct {
Entry git.TreeEntry
ErrMsg string
Name string
}

// MustEnableActions check if actions are enabled in settings
Expand Down Expand Up @@ -90,7 +92,7 @@ func List(ctx *context.Context) {

workflows = make([]Workflow, 0, len(entries))
for _, entry := range entries {
workflow := Workflow{Entry: *entry}
workflow := Workflow{Entry: *entry, Name: entry.Name()}
content, err := actions.GetContentFromEntry(entry)
if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
Expand Down Expand Up @@ -124,6 +126,30 @@ func List(ctx *context.Context) {
workflows = append(workflows, workflow)
}
}

// recheck workflow ids by runs because not all workflows in default branch
ids, err := actions_model.FindWorkflowIDsByRepoID(ctx, ctx.Repo.Repository.ID)
if err != nil {
log.Error("actions_model.FindWorkflowIDsByRepoID: %v", err)
}

for _, id := range ids {
found := false

for _, wf := range workflows {
if wf.Name == id {
found = true
break
}
}

if found {
continue
}

workflows = append(workflows, Workflow{Name: id})
}

ctx.Data["workflows"] = workflows
ctx.Data["RepoLink"] = ctx.Repo.Repository.Link()

Expand Down
4 changes: 2 additions & 2 deletions templates/repo/actions/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<div class="ui fluid vertical menu">
<a class="item{{if not $.CurWorkflow}} active{{end}}" href="{{$.Link}}?actor={{$.CurActor}}&status={{$.CurStatus}}">{{ctx.Locale.Tr "actions.runs.all_workflows"}}</a>
{{range .workflows}}
<a class="item{{if eq .Entry.Name $.CurWorkflow}} active{{end}}" href="{{$.Link}}?workflow={{.Entry.Name}}&actor={{$.CurActor}}&status={{$.CurStatus}}">{{.Entry.Name}}
<a class="item{{if eq .Name $.CurWorkflow}} active{{end}}" href="{{$.Link}}?workflow={{.Name}}&actor={{$.CurActor}}&status={{$.CurStatus}}">{{.Name}}
{{if .ErrMsg}}
<span data-tooltip-content="{{.ErrMsg}}">
{{svg "octicon-alert" 16 "text red"}}
</span>
{{end}}

{{if $.ActionsConfig.IsWorkflowDisabled .Entry.Name}}
{{if $.ActionsConfig.IsWorkflowDisabled .Name}}
<div class="ui red label">{{ctx.Locale.Tr "disabled"}}</div>
{{end}}
</a>
Expand Down