Skip to content

Commit f7fd1c7

Browse files
committed
Revert "Fix an actions schedule bug (go-gitea#28942)"
This reverts commit adc3598.
1 parent d4396ac commit f7fd1c7

File tree

7 files changed

+19
-104
lines changed

7 files changed

+19
-104
lines changed

modules/actions/workflows.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -149,41 +149,6 @@ func DetectWorkflows(
149149
return workflows, schedules, nil
150150
}
151151

152-
func DetectScheduledWorkflows(gitRepo *git.Repository, commit *git.Commit) ([]*DetectedWorkflow, error) {
153-
entries, err := ListWorkflows(commit)
154-
if err != nil {
155-
return nil, err
156-
}
157-
158-
wfs := make([]*DetectedWorkflow, 0, len(entries))
159-
for _, entry := range entries {
160-
content, err := GetContentFromEntry(entry)
161-
if err != nil {
162-
return nil, err
163-
}
164-
165-
// one workflow may have multiple events
166-
events, err := GetEventsFromContent(content)
167-
if err != nil {
168-
log.Warn("ignore invalid workflow %q: %v", entry.Name(), err)
169-
continue
170-
}
171-
for _, evt := range events {
172-
if evt.IsSchedule() {
173-
log.Trace("detect scheduled workflow: %q", entry.Name())
174-
dwf := &DetectedWorkflow{
175-
EntryName: entry.Name(),
176-
TriggerEvent: evt,
177-
Content: content,
178-
}
179-
wfs = append(wfs, dwf)
180-
}
181-
}
182-
}
183-
184-
return wfs, nil
185-
}
186-
187152
func detectMatched(gitRepo *git.Repository, commit *git.Commit, triggedEvent webhook_module.HookEventType, payload api.Payloader, evt *jobparser.Event) bool {
188153
if !canGithubEventMatch(evt.Name, triggedEvent) {
189154
return false

routers/api/v1/repo/wiki.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func getWikiPage(ctx *context.APIContext, wikiName wiki_service.WebPath) *api.Wi
203203
}
204204

205205
return &api.WikiPage{
206-
WikiPageMetaData: wiki_service.ToWikiPageMetaData(wikiName, lastCommit, ctx.Repo.Repository),
206+
WikiPageMetaData: convert.ToWikiPageMetaData(wikiName, lastCommit, ctx.Repo.Repository),
207207
ContentBase64: content,
208208
CommitCount: commitsCount,
209209
Sidebar: sidebarContent,
@@ -333,7 +333,7 @@ func ListWikiPages(ctx *context.APIContext) {
333333
ctx.Error(http.StatusInternalServerError, "WikiFilenameToName", err)
334334
return
335335
}
336-
pages = append(pages, wiki_service.ToWikiPageMetaData(wikiName, c, ctx.Repo.Repository))
336+
pages = append(pages, convert.ToWikiPageMetaData(wikiName, c, ctx.Repo.Repository))
337337
}
338338

339339
ctx.SetTotalCountHeader(int64(len(entries)))

services/actions/notifier_helper.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -478,35 +478,3 @@ func handleSchedules(
478478

479479
return actions_model.CreateScheduleTask(ctx, crons)
480480
}
481-
482-
// DetectAndHandleSchedules detects the schedule workflows on the default branch and create schedule tasks
483-
func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository) error {
484-
gitRepo, err := gitrepo.OpenRepository(context.Background(), repo)
485-
if err != nil {
486-
return fmt.Errorf("git.OpenRepository: %w", err)
487-
}
488-
defer gitRepo.Close()
489-
490-
// Only detect schedule workflows on the default branch
491-
commit, err := gitRepo.GetCommit(repo.DefaultBranch)
492-
if err != nil {
493-
return fmt.Errorf("gitRepo.GetCommit: %w", err)
494-
}
495-
scheduleWorkflows, err := actions_module.DetectScheduledWorkflows(gitRepo, commit)
496-
if err != nil {
497-
return fmt.Errorf("detect schedule workflows: %w", err)
498-
}
499-
if len(scheduleWorkflows) == 0 {
500-
return nil
501-
}
502-
503-
// We need a notifyInput to call handleSchedules
504-
// Here we use the commit author as the Doer of the notifyInput
505-
commitUser, err := user_model.GetUserByEmail(ctx, commit.Author.Email)
506-
if err != nil {
507-
return fmt.Errorf("get user by email: %w", err)
508-
}
509-
notifyInput := newNotifyInput(repo, commitUser, webhook_module.HookEventSchedule)
510-
511-
return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch)
512-
}

services/actions/schedule_tasks.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
actions_model "code.gitea.io/gitea/models/actions"
1212
"code.gitea.io/gitea/models/db"
13-
repo_model "code.gitea.io/gitea/models/repo"
1413
"code.gitea.io/gitea/models/unit"
1514
"code.gitea.io/gitea/modules/log"
1615
"code.gitea.io/gitea/modules/timeutil"
@@ -66,15 +65,8 @@ func startTasks(ctx context.Context) error {
6665
}
6766
}
6867

69-
cfg, err := row.Repo.GetUnit(ctx, unit.TypeActions)
70-
if err != nil {
71-
if repo_model.IsErrUnitTypeNotExist(err) {
72-
// Skip the actions unit of this repo is disabled.
73-
continue
74-
}
75-
return fmt.Errorf("GetUnit: %w", err)
76-
}
77-
if cfg.ActionsConfig().IsWorkflowDisabled(row.Schedule.WorkflowID) {
68+
cfg := row.Repo.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
69+
if cfg.IsWorkflowDisabled(row.Schedule.WorkflowID) {
7870
continue
7971
}
8072

services/convert/wiki.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ package convert
66
import (
77
"time"
88

9+
repo_model "code.gitea.io/gitea/models/repo"
910
"code.gitea.io/gitea/modules/git"
1011
api "code.gitea.io/gitea/modules/structs"
12+
"code.gitea.io/gitea/modules/util"
13+
wiki_service "code.gitea.io/gitea/services/wiki"
1114
)
1215

1316
// ToWikiCommit convert a git commit into a WikiCommit
@@ -43,3 +46,15 @@ func ToWikiCommitList(commits []*git.Commit, total int64) *api.WikiCommitList {
4346
Count: total,
4447
}
4548
}
49+
50+
// ToWikiPageMetaData converts meta information to a WikiPageMetaData
51+
func ToWikiPageMetaData(wikiName wiki_service.WebPath, lastCommit *git.Commit, repo *repo_model.Repository) *api.WikiPageMetaData {
52+
subURL := string(wikiName)
53+
_, title := wiki_service.WebPathToUserTitle(wikiName)
54+
return &api.WikiPageMetaData{
55+
Title: title,
56+
HTMLURL: util.URLJoin(repo.HTMLURL(), "wiki", subURL),
57+
SubURL: subURL,
58+
LastCommit: ToWikiCommit(lastCommit),
59+
}
60+
}

services/repository/setting.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
repo_model "code.gitea.io/gitea/models/repo"
1313
"code.gitea.io/gitea/models/unit"
1414
"code.gitea.io/gitea/modules/log"
15-
actions_service "code.gitea.io/gitea/services/actions"
1615
)
1716

1817
// UpdateRepositoryUnits updates a repository's units
@@ -34,15 +33,6 @@ func UpdateRepositoryUnits(ctx context.Context, repo *repo_model.Repository, uni
3433
}
3534
}
3635

37-
for _, u := range units {
38-
if u.Type == unit.TypeActions {
39-
if err := actions_service.DetectAndHandleSchedules(ctx, repo); err != nil {
40-
log.Error("DetectAndHandleSchedules: %v", err)
41-
}
42-
break
43-
}
44-
}
45-
4636
if _, err = db.GetEngine(ctx).Where("repo_id = ?", repo.ID).In("type", deleteUnitTypes).Delete(new(repo_model.RepoUnit)); err != nil {
4737
return err
4838
}

services/wiki/wiki_path.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import (
99
"strings"
1010

1111
repo_model "code.gitea.io/gitea/models/repo"
12-
"code.gitea.io/gitea/modules/git"
13-
api "code.gitea.io/gitea/modules/structs"
1412
"code.gitea.io/gitea/modules/util"
15-
"code.gitea.io/gitea/services/convert"
1613
)
1714

1815
// To define the wiki related concepts:
@@ -158,15 +155,3 @@ func UserTitleToWebPath(base, title string) WebPath {
158155
}
159156
return WebPath(title)
160157
}
161-
162-
// ToWikiPageMetaData converts meta information to a WikiPageMetaData
163-
func ToWikiPageMetaData(wikiName WebPath, lastCommit *git.Commit, repo *repo_model.Repository) *api.WikiPageMetaData {
164-
subURL := string(wikiName)
165-
_, title := WebPathToUserTitle(wikiName)
166-
return &api.WikiPageMetaData{
167-
Title: title,
168-
HTMLURL: util.URLJoin(repo.HTMLURL(), "wiki", subURL),
169-
SubURL: subURL,
170-
LastCommit: convert.ToWikiCommit(lastCommit),
171-
}
172-
}

0 commit comments

Comments
 (0)