From dc785fdae50e243998f5b7c5b93b298c1444f592 Mon Sep 17 00:00:00 2001 From: Angel Nunez Mencias Date: Sat, 16 Nov 2024 18:12:40 +0100 Subject: [PATCH] fmt (cherry picked from commit 01c9c1953690f227dea5d60f814643280497ea46) --- routers/api/v1/repo/pull.go | 66 +++++++++++----------- tests/integration/api_repo_compare_test.go | 2 +- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 445530f85b..fcca180c41 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1089,16 +1089,16 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) // Check if base branch is valid. baseIsCommit := ctx.Repo.GitRepo.IsCommitExist(baseBranch) - baseIsBranch := ctx.Repo.GitRepo.IsBranchExist(baseBranch) - baseIsTag := ctx.Repo.GitRepo.IsTagExist(baseBranch) - if !baseIsCommit && !baseIsBranch && !baseIsTag { - // Check for short SHA usage - if baseCommit, _ := ctx.Repo.GitRepo.GetCommit(baseBranch); baseCommit != nil { - baseBranch = baseCommit.ID.String() - } else { - ctx.NotFound("BaseNotExist") - return nil, nil, nil, "", "" - } + baseIsBranch := ctx.Repo.GitRepo.IsBranchExist(baseBranch) + baseIsTag := ctx.Repo.GitRepo.IsTagExist(baseBranch) + if !baseIsCommit && !baseIsBranch && !baseIsTag { + // Check for short SHA usage + if baseCommit, _ := ctx.Repo.GitRepo.GetCommit(baseBranch); baseCommit != nil { + baseBranch = baseCommit.ID.String() + } else { + ctx.NotFound("BaseNotExist") + return nil, nil, nil, "", "" + } } // Check if current user has fork of repository or in the same repository. @@ -1173,30 +1173,30 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) // Check if head branch is valid. headIsCommit := headGitRepo.IsBranchExist(headBranch) headIsBranch := headGitRepo.IsTagExist(headBranch) - headIsTag := headGitRepo.IsCommitExist(baseBranch) - if !headIsCommit && !headIsBranch && !headIsTag { - // Check if headBranch is short sha commit hash - if headCommit, _ := headGitRepo.GetCommit(headBranch); headCommit != nil { - headBranch = headCommit.ID.String() - } else { - headGitRepo.Close() - ctx.NotFound("IsRefExist", nil) - return nil, nil, nil, "", "" - } - } + headIsTag := headGitRepo.IsCommitExist(baseBranch) + if !headIsCommit && !headIsBranch && !headIsTag { + // Check if headBranch is short sha commit hash + if headCommit, _ := headGitRepo.GetCommit(headBranch); headCommit != nil { + headBranch = headCommit.ID.String() + } else { + headGitRepo.Close() + ctx.NotFound("IsRefExist", nil) + return nil, nil, nil, "", "" + } + } - baseBranchRef := baseBranch - if baseIsBranch { - baseBranchRef = git.BranchPrefix + baseBranch - } else if baseIsTag { - baseBranchRef = git.TagPrefix + baseBranch - } - headBranchRef := headBranch - if headIsBranch { - headBranchRef = headBranch - } else if headIsTag { - headBranchRef = headBranch - } + baseBranchRef := baseBranch + if baseIsBranch { + baseBranchRef = git.BranchPrefix + baseBranch + } else if baseIsTag { + baseBranchRef = git.TagPrefix + baseBranch + } + headBranchRef := headBranch + if headIsBranch { + headBranchRef = headBranch + } else if headIsTag { + headBranchRef = headBranch + } compareInfo, err := headGitRepo.GetCompareInfo(repo_model.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseBranchRef, headBranchRef, false, false) if err != nil { diff --git a/tests/integration/api_repo_compare_test.go b/tests/integration/api_repo_compare_test.go index 17847ec360..bd800b9e79 100644 --- a/tests/integration/api_repo_compare_test.go +++ b/tests/integration/api_repo_compare_test.go @@ -56,4 +56,4 @@ func TestAPICompareCommits(t *testing.T) { assert.Equal(t, 2, apiResp.TotalCommits) assert.Len(t, apiResp.Commits, 2) -} \ No newline at end of file +}