diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-12-12 20:28:23 +0100 |
---|---|---|
committer | Earl Warren <contact@earl-warren.org> | 2024-12-15 09:45:10 +0100 |
commit | 2b5c69c451a684b20119e2521dc23734c7869241 (patch) | |
tree | 325388e2913aea14366476a0243731991e081f04 /models | |
parent | Implement update branch API (#32433) (diff) | |
download | forgejo-2b5c69c451a684b20119e2521dc23734c7869241.tar.xz forgejo-2b5c69c451a684b20119e2521dc23734c7869241.zip |
Detect whether action view branch was deleted (#32764)
Fix #32761
![图片](https://github.com/user-attachments/assets/a5a7eef8-0fea-4242-b199-1b0b73d9bbdb)
(cherry picked from commit 6370d2fb93a5ee897b82969ca30a9feb33667714)
Conflicts:
routers/web/repo/actions/actions.go
routers/web/repo/actions/view.go
trivial context conflicts
Diffstat (limited to 'models')
-rw-r--r-- | models/actions/run.go | 1 | ||||
-rw-r--r-- | models/git/branch.go | 18 |
2 files changed, 17 insertions, 2 deletions
diff --git a/models/actions/run.go b/models/actions/run.go index 06a1290d5d..c5512106b9 100644 --- a/models/actions/run.go +++ b/models/actions/run.go @@ -37,6 +37,7 @@ type ActionRun struct { TriggerUser *user_model.User `xorm:"-"` ScheduleID int64 Ref string `xorm:"index"` // the commit/tag/… that caused the run + IsRefDeleted bool `xorm:"-"` CommitSHA string IsForkPullRequest bool // If this is triggered by a PR from a forked repository or an untrusted user, we need to check if it is approved and limit permissions when running the workflow. NeedApproval bool // may need approval if it's a fork pull request diff --git a/models/git/branch.go b/models/git/branch.go index 74923f2b9b..702d767c75 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" @@ -162,9 +163,22 @@ func GetBranch(ctx context.Context, repoID int64, branchName string) (*Branch, e return &branch, nil } -func GetBranches(ctx context.Context, repoID int64, branchNames []string) ([]*Branch, error) { +func GetBranches(ctx context.Context, repoID int64, branchNames []string, includeDeleted bool) ([]*Branch, error) { branches := make([]*Branch, 0, len(branchNames)) - return branches, db.GetEngine(ctx).Where("repo_id=?", repoID).In("name", branchNames).Find(&branches) + + sess := db.GetEngine(ctx).Where("repo_id=?", repoID).In("name", branchNames) + if !includeDeleted { + sess.And("is_deleted=?", false) + } + return branches, sess.Find(&branches) +} + +func BranchesToNamesSet(branches []*Branch) container.Set[string] { + names := make(container.Set[string], len(branches)) + for _, branch := range branches { + names.Add(branch.Name) + } + return names } func AddBranches(ctx context.Context, branches []*Branch) error { |