summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-01-12 22:50:38 +0100
committerEarl Warren <contact@earl-warren.org>2024-03-25 16:25:02 +0100
commit3b3747ffe8ebd2b15001161b017e393b8121f50a (patch)
treed6360b01ef189966e5e4abd7bee80161c54a25c5 /routers
parentRevert "[ACTIONS] on.schedule: the event is always "schedule"" (diff)
downloadforgejo-3b3747ffe8ebd2b15001161b017e393b8121f50a.tar.xz
forgejo-3b3747ffe8ebd2b15001161b017e393b8121f50a.zip
Fix schedule tasks bugs (#28691)
Fix #28157 This PR fix the possible bugs about actions schedule. - Move `UpdateRepositoryUnit` and `SetRepoDefaultBranch` from models to service layer - Remove schedules plan from database and cancel waiting & running schedules tasks in this repository when actions unit has been disabled or global disabled. - Remove schedules plan from database and cancel waiting & running schedules tasks in this repository when default branch changed. (cherry picked from commit 97292da96048b036cbe36b3ea66503ac568a73e7) Conflicts: modules/actions/github.go routers/web/repo/setting/default_branch.go routers/web/repo/setting/setting.go services/repository/branch.go services/repository/setting.go tests/integration/actions_trigger_test.go
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/repo.go2
-rw-r--r--routers/web/repo/setting/default_branch.go24
-rw-r--r--routers/web/repo/setting/setting.go2
3 files changed, 9 insertions, 19 deletions
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 316a1161da..bee605dd70 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -1001,7 +1001,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
}
if len(units)+len(deleteUnitTypes) > 0 {
- if err := repo_model.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil {
+ if err := repo_service.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateRepositoryUnits", err)
return err
}
diff --git a/routers/web/repo/setting/default_branch.go b/routers/web/repo/setting/default_branch.go
index d0b32ef079..12e1ab7d1c 100644
--- a/routers/web/repo/setting/default_branch.go
+++ b/routers/web/repo/setting/default_branch.go
@@ -12,8 +12,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/routers/web/repo"
- "code.gitea.io/gitea/services/context"
- notify_service "code.gitea.io/gitea/services/notify"
+ repo_service "code.gitea.io/gitea/services/repository"
)
// SetDefaultBranchPost set default branch
@@ -36,23 +35,14 @@ func SetDefaultBranchPost(ctx *context.Context) {
}
branch := ctx.FormString("branch")
- if !ctx.Repo.GitRepo.IsBranchExist(branch) {
- ctx.Status(http.StatusNotFound)
- return
- } else if repo.DefaultBranch != branch {
- repo.DefaultBranch = branch
- if err := gitrepo.SetDefaultBranch(ctx, repo, branch); err != nil {
- if !git.IsErrUnsupportedVersion(err) {
- ctx.ServerError("SetDefaultBranch", err)
- return
- }
- }
- if err := repo_model.UpdateDefaultBranch(ctx, repo); err != nil {
+ if err := repo_service.SetRepoDefaultBranch(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, branch); err != nil {
+ switch {
+ case ctx.Repo.GitRepo.IsErrBranchNotExist(err):
+ ctx.Status(http.StatusNotFound)
+ default:
ctx.ServerError("SetDefaultBranch", err)
- return
}
-
- notify_service.ChangeDefaultBranch(ctx, repo)
+ return
}
log.Trace("Repository basic settings updated: %s/%s", ctx.Repo.Owner.Name, repo.Name)
diff --git a/routers/web/repo/setting/setting.go b/routers/web/repo/setting/setting.go
index 99c15b74f3..00af58b44d 100644
--- a/routers/web/repo/setting/setting.go
+++ b/routers/web/repo/setting/setting.go
@@ -269,7 +269,7 @@ func UnitsPost(ctx *context.Context) {
return
}
- if err := repo_model.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil {
+ if err := repo_service.UpdateRepositoryUnits(ctx, repo, units, deleteUnitTypes); err != nil {
ctx.ServerError("UpdateRepositoryUnits", err)
return
}