enhance(actions): show workflow name from YAML instead of filename (#37833)

Use the workflow's YAML `name:` field for display in the workflow
sidebar and run list, falling back to the filename when no name is set.

Closes https://github.com/go-gitea/gitea/issues/31458
Closes https://github.com/go-gitea/gitea/issues/25912
Closes https://github.com/go-gitea/gitea/pull/31474
This commit is contained in:
Nicolas
2026-05-25 10:25:22 +02:00
committed by GitHub
parent 6f4027a6be
commit bc6054b56d
3 changed files with 17 additions and 2 deletions

View File

@@ -44,6 +44,14 @@ type WorkflowInfo struct {
Workflow *act_model.Workflow
}
// DisplayName returns the workflow name from the YAML file if present, otherwise the filename.
func (w WorkflowInfo) DisplayName() string {
if w.Workflow != nil && w.Workflow.Name != "" {
return w.Workflow.Name
}
return w.Entry.Name()
}
// MustEnableActions check if actions are enabled in settings
func MustEnableActions(ctx *context.Context) {
if !setting.Actions.Enabled {
@@ -341,6 +349,12 @@ func prepareWorkflowList(ctx *context.Context, workflows []WorkflowInfo) {
ctx.Data["Runs"] = runs
workflowNames := make(map[string]string, len(workflows))
for _, wf := range workflows {
workflowNames[wf.Entry.Name()] = wf.DisplayName()
}
ctx.Data["WorkflowNames"] = workflowNames
actors, err := actions_model.GetActors(ctx, ctx.Repo.Repository.ID)
if err != nil {
ctx.ServerError("GetActors", err)

View File

@@ -11,7 +11,7 @@
<a class="item {{if not $.CurWorkflow}}active{{end}}" href="?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="?workflow={{.Entry.Name}}&actor={{$.CurActor}}&status={{$.CurStatus}}">
<span class="gt-ellipsis">{{.Entry.Name}}</span>
<span class="gt-ellipsis">{{.DisplayName}}</span>
{{if .ErrMsg}}
<span class="flex-text-inline" data-tooltip-content="{{.ErrMsg}}">{{svg "octicon-alert" 16 "tw-text-red"}}</span>

View File

@@ -21,7 +21,8 @@
{{end}}
</span>
<div class="item-body">
<span><b>{{if not $.CurWorkflow}}{{$run.WorkflowID}} {{end}}#{{$run.Index}}</b>:</span>
{{$workflowName := index $.WorkflowNames $run.WorkflowID}}
<span><b>{{if not $.CurWorkflow}}{{if $workflowName}}{{$workflowName}}{{else}}{{$run.WorkflowID}}{{end}} {{end}}#{{$run.Index}}</b>:</span>
{{- if $run.ScheduleID -}}
{{ctx.Locale.Tr "actions.runs.scheduled"}}