loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add workflow error notification in ui (#23404)

![image](https://user-images.githubusercontent.com/18380374/224237847-07a30029-32d4-4af7-a36e-e55f0ed899aa.png)

![image](https://user-images.githubusercontent.com/18380374/224239309-a96120e1-5eec-41c0-89aa-9cf63d1df30c.png)

---------

Co-authored-by: techknowlogick <matti@mdranta.net>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>

authored by

yp05327
techknowlogick
techknowlogick
Lunny Xiao
and committed by
GitHub
aac07d01 6ff5400a

+64 -16
+28 -12
modules/actions/workflows.go
··· 44 44 return ret, nil 45 45 } 46 46 47 + func GetContentFromEntry(entry *git.TreeEntry) ([]byte, error) { 48 + f, err := entry.Blob().DataAsync() 49 + if err != nil { 50 + return nil, err 51 + } 52 + content, err := io.ReadAll(f) 53 + _ = f.Close() 54 + if err != nil { 55 + return nil, err 56 + } 57 + return content, nil 58 + } 59 + 60 + func GetEventsFromContent(content []byte) ([]*jobparser.Event, error) { 61 + workflow, err := model.ReadWorkflow(bytes.NewReader(content)) 62 + if err != nil { 63 + return nil, err 64 + } 65 + events, err := jobparser.ParseRawOn(&workflow.RawOn) 66 + if err != nil { 67 + return nil, err 68 + } 69 + 70 + return events, nil 71 + } 72 + 47 73 func DetectWorkflows(commit *git.Commit, triggedEvent webhook_module.HookEventType, payload api.Payloader) (map[string][]byte, error) { 48 74 entries, err := ListWorkflows(commit) 49 75 if err != nil { ··· 52 78 53 79 workflows := make(map[string][]byte, len(entries)) 54 80 for _, entry := range entries { 55 - f, err := entry.Blob().DataAsync() 56 - if err != nil { 57 - return nil, err 58 - } 59 - content, err := io.ReadAll(f) 60 - _ = f.Close() 81 + content, err := GetContentFromEntry(entry) 61 82 if err != nil { 62 83 return nil, err 63 84 } 64 - workflow, err := model.ReadWorkflow(bytes.NewReader(content)) 65 - if err != nil { 66 - log.Warn("ignore invalid workflow %q: %v", entry.Name(), err) 67 - continue 68 - } 69 - events, err := jobparser.ParseRawOn(&workflow.RawOn) 85 + events, err := GetEventsFromContent(content) 70 86 if err != nil { 71 87 log.Warn("ignore invalid workflow %q: %v", entry.Name(), err) 72 88 continue
+2
options/locale/locale_en-US.ini
··· 3360 3360 runs.closed_tab = %d Closed 3361 3361 runs.commit = Commit 3362 3362 runs.pushed_by = Pushed by 3363 + runs.valid_workflow_helper = Workflow config file is valid. 3364 + runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s 3363 3365 3364 3366 need_approval_desc = Need approval to run workflows for fork pull request.
+23 -3
routers/web/repo/actions/actions.go
··· 23 23 tplViewActions base.TplName = "repo/actions/view" 24 24 ) 25 25 26 + type Workflow struct { 27 + Entry git.TreeEntry 28 + IsInvalid bool 29 + ErrMsg string 30 + } 31 + 26 32 // MustEnableActions check if actions are enabled in settings 27 33 func MustEnableActions(ctx *context.Context) { 28 34 if !setting.Actions.Enabled { ··· 47 53 ctx.Data["Title"] = ctx.Tr("actions.actions") 48 54 ctx.Data["PageIsActions"] = true 49 55 50 - var workflows git.Entries 56 + var workflows []Workflow 51 57 if empty, err := ctx.Repo.GitRepo.IsEmpty(); err != nil { 52 58 ctx.Error(http.StatusInternalServerError, err.Error()) 53 59 return ··· 62 68 ctx.Error(http.StatusInternalServerError, err.Error()) 63 69 return 64 70 } 65 - workflows, err = actions.ListWorkflows(commit) 71 + entries, err := actions.ListWorkflows(commit) 66 72 if err != nil { 67 73 ctx.Error(http.StatusInternalServerError, err.Error()) 68 74 return 69 75 } 76 + workflows = make([]Workflow, 0, len(entries)) 77 + for _, entry := range entries { 78 + workflow := Workflow{Entry: *entry} 79 + content, err := actions.GetContentFromEntry(entry) 80 + if err != nil { 81 + ctx.Error(http.StatusInternalServerError, err.Error()) 82 + return 83 + } 84 + _, err = actions.GetEventsFromContent(content) 85 + if err != nil { 86 + workflow.IsInvalid = true 87 + workflow.ErrMsg = err.Error() 88 + } 89 + workflows = append(workflows, workflow) 90 + } 70 91 } 71 - 72 92 ctx.Data["workflows"] = workflows 73 93 ctx.Data["RepoLink"] = ctx.Repo.Repository.Link() 74 94
+11 -1
templates/repo/actions/list.tmpl
··· 9 9 <a class="item{{if not $.CurWorkflow}} active{{end}}" href="{{$.Link}}">{{.locale.Tr "actions.runs.all_workflows"}}</a> 10 10 <div class="divider"></div> 11 11 {{range .workflows}} 12 - <a class="item{{if eq .Name $.CurWorkflow}} active{{end}}" href="{{$.Link}}?workflow={{.Name}}">{{.Name}}</a> 12 + <a class="item{{if eq .Entry.Name $.CurWorkflow}} active{{end}}" href="{{$.Link}}?workflow={{.Entry.Name}}">{{.Entry.Name}} 13 + {{if .IsInvalid}} 14 + <span class="tooltip" data-content="{{$.locale.Tr "actions.runs.invalid_workflow_helper" (.ErrMsg)}}"> 15 + <i class="warning icon red"></i> 16 + </span> 17 + {{else}} 18 + <span class="tooltip" data-content="{{$.locale.Tr "actions.runs.valid_workflow_helper"}}"> 19 + <i class="check icon green"></i> 20 + </span> 21 + {{end}} 22 + </a> 13 23 {{end}} 14 24 </div> 15 25 </div>