refactor(git): clarify GetBranch behavior to make it only gets an existing branch (#38662)

`GetBranch` silently returned soft-deleted branches, contradicting
`IsBranchExist` and forcing callers to manually check `branch.IsDeleted`
everywhere.

Refactored it to `GetBranchExisting` to have a clear behavior: it only
returns the existing branch.

---------

Signed-off-by: Sudhanshu Singh <sudhanshuwriterblc@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Shudhanshu Singh
2026-07-27 17:45:27 +00:00
committed by GitHub
co-authored by wxiaoguang
parent 94a2c3ec18
commit d47f9f37d6
12 changed files with 55 additions and 101 deletions
+2 -6
View File
@@ -492,12 +492,8 @@ func viewSummaryBranchFromRun(ctx context.Context, run *actions_model.ActionRun,
Link: run.RefLink(),
}
if refName.IsBranch() {
b, err := git_model.GetBranch(ctx, run.RepoID, refName.ShortName())
if err != nil && !git_model.IsErrBranchNotExist(err) {
log.Error("GetBranch: %v", err)
} else if git_model.IsErrBranchNotExist(err) || (b != nil && b.IsDeleted) {
branch.IsDeleted = true
}
refBranchExists, _ := git_model.IsBranchExist(ctx, run.RepoID, refName.ShortName())
branch.IsDeleted = !refBranchExists
}
return branch
}