summaryrefslogtreecommitdiffstats
path: root/modules/actions
diff options
context:
space:
mode:
authorZettat123 <zettat123@gmail.com>2024-01-31 15:55:12 +0100
committerGitHub <noreply@github.com>2024-01-31 15:55:12 +0100
commitadc3598a755b43e3911266d7fa575c121e16613d (patch)
treeba5982153851b0b1267daae8d1a152d85448cd22 /modules/actions
parentFix doc img path in profile readme (#28994) (diff)
downloadforgejo-adc3598a755b43e3911266d7fa575c121e16613d.tar.xz
forgejo-adc3598a755b43e3911266d7fa575c121e16613d.zip
Fix an actions schedule bug (#28942)
In #28691, schedule plans will be deleted when a repo's actions unit is disabled. But when the unit is enabled, the schedule plans won't be created again. This PR fixes the bug. The schedule plans will be created again when the actions unit is re-enabled
Diffstat (limited to 'modules/actions')
-rw-r--r--modules/actions/workflows.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/actions/workflows.go b/modules/actions/workflows.go
index cbc7e011d1..a883f4181b 100644
--- a/modules/actions/workflows.go
+++ b/modules/actions/workflows.go
@@ -146,6 +146,41 @@ func DetectWorkflows(
return workflows, schedules, nil
}
+func DetectScheduledWorkflows(gitRepo *git.Repository, commit *git.Commit) ([]*DetectedWorkflow, error) {
+ entries, err := ListWorkflows(commit)
+ if err != nil {
+ return nil, err
+ }
+
+ wfs := make([]*DetectedWorkflow, 0, len(entries))
+ for _, entry := range entries {
+ content, err := GetContentFromEntry(entry)
+ if err != nil {
+ return nil, err
+ }
+
+ // one workflow may have multiple events
+ events, err := GetEventsFromContent(content)
+ if err != nil {
+ log.Warn("ignore invalid workflow %q: %v", entry.Name(), err)
+ continue
+ }
+ for _, evt := range events {
+ if evt.IsSchedule() {
+ log.Trace("detect scheduled workflow: %q", entry.Name())
+ dwf := &DetectedWorkflow{
+ EntryName: entry.Name(),
+ TriggerEvent: evt,
+ Content: content,
+ }
+ wfs = append(wfs, dwf)
+ }
+ }
+ }
+
+ return wfs, nil
+}
+
func detectMatched(gitRepo *git.Repository, commit *git.Commit, triggedEvent webhook_module.HookEventType, payload api.Payloader, evt *jobparser.Event) bool {
if !canGithubEventMatch(evt.Name, triggedEvent) {
return false