fix: avoid nil panic and refactor some trivial problems (#39251)

This commit is contained in:
wxiaoguang
2026-09-06 09:49:27 +00:00
committed by GitHub
parent 87d5497da0
commit 3176f37887
16 changed files with 91 additions and 126 deletions
+2 -14
View File
@@ -208,23 +208,11 @@ func AddBranches(ctx context.Context, branches []*Branch) error {
func GetDeletedBranchByID(ctx context.Context, repoID, branchID int64) (*Branch, error) {
var branch Branch
has, err := db.GetEngine(ctx).ID(branchID).Get(&branch)
has, err := db.GetEngine(ctx).ID(branchID).Where("repo_id=? AND is_deleted=?", repoID, true).Get(&branch)
if err != nil {
return nil, err
} else if !has {
return nil, ErrBranchNotExist{
RepoID: repoID,
}
}
if branch.RepoID != repoID {
return nil, ErrBranchNotExist{
RepoID: repoID,
}
}
if !branch.IsDeleted {
return nil, ErrBranchNotExist{
RepoID: repoID,
}
return nil, ErrBranchNotExist{RepoID: repoID}
}
return &branch, nil
}