Skip to content

Commit 1db2a9a

Browse files
committed
fix lint
1 parent 65fbffe commit 1db2a9a

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

routers/api/v1/repo/pull.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,23 +1096,20 @@ type parseCompareInfoResult struct {
10961096
}
10971097

10981098
// parseCompareInfo returns non-nil if it succeeds, it always writes to the context and returns nil if it fails
1099-
func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (result *parseCompareInfoResult, closer func() error) {
1099+
func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (result *parseCompareInfoResult, closer func()) {
11001100
var err error
11011101
// Get compared branches information
11021102
// format: <base branch>...[<head repo>:]<head branch>
11031103
// base<-head: master...head:feature
11041104
// same repo: master...feature
11051105
baseRepo := ctx.Repo.Repository
11061106
baseRefToGuess := form.Base
1107-
headRefToGuess := form.Head
1108-
1109-
var headUser *user_model.User
11101107

1111-
headInfos := strings.Split(form.Head, ":")
1112-
if len(headInfos) == 1 {
1108+
headUser := ctx.Repo.Owner
1109+
headRefToGuess := form.Head
1110+
if headInfos := strings.Split(form.Head, ":"); len(headInfos) == 1 {
11131111
// If there is no head repository, it means pull request between same repository.
1114-
headUser = ctx.Repo.Owner
1115-
headRefToGuess = headInfos[0]
1112+
// Do nothing here because the head variables have been assigned above.
11161113
} else if len(headInfos) == 2 {
11171114
// There is a head repository (the head repository could also be the same base repo)
11181115
headRefToGuess = headInfos[1]
@@ -1155,14 +1152,14 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
11551152
if isSameRepo {
11561153
headRepo = ctx.Repo.Repository
11571154
headGitRepo = ctx.Repo.GitRepo
1158-
closer = func() error { return nil } // no need to close the head repo because it shares the base repo
1155+
closer = func() {} // no need to close the head repo because it shares the base repo
11591156
} else {
11601157
headGitRepo, err = gitrepo.OpenRepository(ctx, headRepo)
11611158
if err != nil {
11621159
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
11631160
return nil, nil
11641161
}
1165-
closer = headGitRepo.Close
1162+
closer = func() { _ = headGitRepo.Close() }
11661163
}
11671164
defer func() {
11681165
if result == nil && !isSameRepo {

tests/integration/api_repo_compare_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestAPICompareBranches(t *testing.T) {
3636
assert.Len(t, apiResp.Commits, 2)
3737
})
3838

39-
t.Run("CompareBranches", func(t *testing.T) {
39+
t.Run("CompareCommits", func(t *testing.T) {
4040
defer tests.PrintCurrentTest(t)()
4141
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo20/compare/808038d2f71b0ab02099...c8e31bc7688741a5287f").AddTokenAuth(token)
4242
resp := MakeRequest(t, req, http.StatusOK)

0 commit comments

Comments
 (0)