aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-07-03 09:53:05 +0800
committerGitHub <noreply@github.com>2023-07-03 01:53:05 +0000
commit807c9712efd4ae43052c971e92bda5724a9c3724 (patch)
tree1f5dce00df9b182ffda242a5fc1f90677121c0aa /models
parent640a88fa099302919320ab242aa21a2ded1c4760 (diff)
downloadgitea-807c9712efd4ae43052c971e92bda5724a9c3724.tar.gz
gitea-807c9712efd4ae43052c971e92bda5724a9c3724.zip
Get latest commit statuses from database instead of git data on dashboard for repositories (#25605)
related #24638
Diffstat (limited to 'models')
-rw-r--r--models/git/branch_list.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/models/git/branch_list.go b/models/git/branch_list.go
index da78248c0b..836d4ffc41 100644
--- a/models/git/branch_list.go
+++ b/models/git/branch_list.go
@@ -130,3 +130,20 @@ func FindBranchNames(ctx context.Context, opts FindBranchOptions) ([]string, err
}
return branches, nil
}
+
+func FindBranchesByRepoAndBranchName(ctx context.Context, repoBranches map[int64]string) (map[int64]string, error) {
+ cond := builder.NewCond()
+ for repoID, branchName := range repoBranches {
+ cond = cond.Or(builder.And(builder.Eq{"repo_id": repoID}, builder.Eq{"name": branchName}))
+ }
+ var branches []*Branch
+ if err := db.GetEngine(ctx).
+ Where(cond).Find(&branches); err != nil {
+ return nil, err
+ }
+ branchMap := make(map[int64]string, len(branches))
+ for _, branch := range branches {
+ branchMap[branch.RepoID] = branch.CommitID
+ }
+ return branchMap, nil
+}