From e9e900e7bcd876ee361e1626e5ea7eeab5b036c5 Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 20 Apr 2024 21:05:43 +0800 Subject: [PATCH 1/3] fix: refactor branch and tag existence checks - Update branch existence check to also include tag existence check - Adjust error message for branch/tag existence check Signed-off-by: appleboy --- routers/api/v1/repo/pull.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index e43366ff14bd..b67bc144028e 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1085,8 +1085,8 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) log.Info("Base branch: %s", baseBranch) log.Info("Repo path: %s", ctx.Repo.GitRepo.Path) // Check if base branch is valid. - if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) { - ctx.NotFound("IsBranchExist") + if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) && !ctx.Repo.GitRepo.IsTagExist(baseBranch) { + ctx.NotFound("IsBranchExist && IsTagExist") return nil, nil, nil, nil, "", "" } @@ -1149,7 +1149,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) } // Check if head branch is valid. - if !headGitRepo.IsBranchExist(headBranch) { + if !headGitRepo.IsBranchExist(headBranch) && !headGitRepo.IsTagExist(headBranch) { headGitRepo.Close() ctx.NotFound() return nil, nil, nil, nil, "", "" From 0ca2063953254c891771c18e3e75a2e893e6bf72 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 21 Apr 2024 19:16:14 +0800 Subject: [PATCH 2/3] Update routers/api/v1/repo/pull.go Co-authored-by: wxiaoguang --- routers/api/v1/repo/pull.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index b67bc144028e..0bb61a05727e 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1086,7 +1086,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) log.Info("Repo path: %s", ctx.Repo.GitRepo.Path) // Check if base branch is valid. if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) && !ctx.Repo.GitRepo.IsTagExist(baseBranch) { - ctx.NotFound("IsBranchExist && IsTagExist") + ctx.NotFound("BaseNotExist") return nil, nil, nil, nil, "", "" } From f2bce9876a07b2f38d9703bd6afae8d5401058f7 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 21 Apr 2024 19:21:04 +0800 Subject: [PATCH 3/3] Update pull.go --- routers/api/v1/repo/pull.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 0bb61a05727e..dfe34f23d07d 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1082,8 +1082,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) } ctx.Repo.PullRequest.SameRepo = isSameRepo - log.Info("Base branch: %s", baseBranch) - log.Info("Repo path: %s", ctx.Repo.GitRepo.Path) + log.Trace("Repo path: %q, base branch: %q, head branch: %q", ctx.Repo.GitRepo.Path, baseBranch, headBranch) // Check if base branch is valid. if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) && !ctx.Repo.GitRepo.IsTagExist(baseBranch) { ctx.NotFound("BaseNotExist")