diff options
author | yp05327 <576951401@qq.com> | 2023-03-14 16:27:03 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-14 15:27:03 +0800 |
commit | aac07d010f261c00fb3bd9644c71dc108c668c11 (patch) | |
tree | 1270a43ca5eec3c2cb392f63788250e755a37e36 /modules | |
parent | 6ff5400af91aefb02cbc7dd59f6be23cc2bf7865 (diff) | |
download | gitea-aac07d010f261c00fb3bd9644c71dc108c668c11.tar.gz gitea-aac07d010f261c00fb3bd9644c71dc108c668c11.zip |
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>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/actions/workflows.go | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/modules/actions/workflows.go b/modules/actions/workflows.go index 7f0e6e4564..98fc831c31 100644 --- a/modules/actions/workflows.go +++ b/modules/actions/workflows.go @@ -44,6 +44,32 @@ func ListWorkflows(commit *git.Commit) (git.Entries, error) { return ret, nil } +func GetContentFromEntry(entry *git.TreeEntry) ([]byte, error) { + f, err := entry.Blob().DataAsync() + if err != nil { + return nil, err + } + content, err := io.ReadAll(f) + _ = f.Close() + if err != nil { + return nil, err + } + return content, nil +} + +func GetEventsFromContent(content []byte) ([]*jobparser.Event, error) { + workflow, err := model.ReadWorkflow(bytes.NewReader(content)) + if err != nil { + return nil, err + } + events, err := jobparser.ParseRawOn(&workflow.RawOn) + if err != nil { + return nil, err + } + + return events, nil +} + func DetectWorkflows(commit *git.Commit, triggedEvent webhook_module.HookEventType, payload api.Payloader) (map[string][]byte, error) { entries, err := ListWorkflows(commit) if err != nil { @@ -52,21 +78,11 @@ func DetectWorkflows(commit *git.Commit, triggedEvent webhook_module.HookEventTy workflows := make(map[string][]byte, len(entries)) for _, entry := range entries { - f, err := entry.Blob().DataAsync() - if err != nil { - return nil, err - } - content, err := io.ReadAll(f) - _ = f.Close() + content, err := GetContentFromEntry(entry) if err != nil { return nil, err } - workflow, err := model.ReadWorkflow(bytes.NewReader(content)) - if err != nil { - log.Warn("ignore invalid workflow %q: %v", entry.Name(), err) - continue - } - events, err := jobparser.ParseRawOn(&workflow.RawOn) + events, err := GetEventsFromContent(content) if err != nil { log.Warn("ignore invalid workflow %q: %v", entry.Name(), err) continue |