Skip to content

Commit 6459c50

Browse files
appleboywxiaoguangGiteaBot
authored
fix(api): refactor branch and tag existence checks (#30618)
- Update branch existence check to also include tag existence check - Adjust error message for branch/tag existence check ref: #30349 --------- Signed-off-by: appleboy <[email protected]> Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: Giteabot <[email protected]>
1 parent 0606284 commit 6459c50

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

routers/api/v1/repo/pull.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,11 +1082,10 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
10821082
}
10831083

10841084
ctx.Repo.PullRequest.SameRepo = isSameRepo
1085-
log.Info("Base branch: %s", baseBranch)
1086-
log.Info("Repo path: %s", ctx.Repo.GitRepo.Path)
1085+
log.Trace("Repo path: %q, base branch: %q, head branch: %q", ctx.Repo.GitRepo.Path, baseBranch, headBranch)
10871086
// Check if base branch is valid.
1088-
if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) {
1089-
ctx.NotFound("IsBranchExist")
1087+
if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) && !ctx.Repo.GitRepo.IsTagExist(baseBranch) {
1088+
ctx.NotFound("BaseNotExist")
10901089
return nil, nil, nil, nil, "", ""
10911090
}
10921091

@@ -1149,7 +1148,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
11491148
}
11501149

11511150
// Check if head branch is valid.
1152-
if !headGitRepo.IsBranchExist(headBranch) {
1151+
if !headGitRepo.IsBranchExist(headBranch) && !headGitRepo.IsTagExist(headBranch) {
11531152
headGitRepo.Close()
11541153
ctx.NotFound()
11551154
return nil, nil, nil, nil, "", ""

0 commit comments

Comments
 (0)