Skip to content

Commit 9792a37

Browse files
silverwindearl-warren
authored andcommitted
Fix tautological conditions (#30735)
As discovered by go-gitea/gitea#30729. --------- Co-authored-by: Giteabot <teabot@gitea.io> (cherry picked from commit 610802df85933e7a190a705bc3f7800da87ce868) Conflicts: tests/integration/git_test.go trivial conflict because of https://codeberg.org/forgejo/forgejo/pulls/2834
1 parent 51b8d96 commit 9792a37

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

routers/private/hook_post_receive.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,14 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
114114
}
115115
}
116116
if len(branchesToSync) > 0 {
117-
if gitRepo == nil {
118-
var err error
119-
gitRepo, err = gitrepo.OpenRepository(ctx, repo)
120-
if err != nil {
121-
log.Error("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err)
122-
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
123-
Err: fmt.Sprintf("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err),
124-
})
125-
return
126-
}
117+
var err error
118+
gitRepo, err = gitrepo.OpenRepository(ctx, repo)
119+
if err != nil {
120+
log.Error("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err)
121+
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
122+
Err: fmt.Sprintf("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err),
123+
})
124+
return
127125
}
128126

129127
var (

services/auth/source/oauth2/providers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func createProvider(providerName string, source *Source) (goth.Provider, error)
182182
}
183183

184184
// always set the name if provider is created so we can support multiple setups of 1 provider
185-
if err == nil && provider != nil {
185+
if provider != nil {
186186
provider.SetName(providerName)
187187
}
188188

services/convert/issue.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,11 @@ func ToLabel(label *issues_model.Label, repo *repo_model.Repository, org *user_m
211211
IsArchived: label.IsArchived(),
212212
}
213213

214+
labelBelongsToRepo := label.BelongsToRepo()
215+
214216
// calculate URL
215-
if label.BelongsToRepo() && repo != nil {
216-
if repo != nil {
217-
result.URL = fmt.Sprintf("%s/labels/%d", repo.APIURL(), label.ID)
218-
} else {
219-
log.Error("ToLabel did not get repo to calculate url for label with id '%d'", label.ID)
220-
}
217+
if labelBelongsToRepo && repo != nil {
218+
result.URL = fmt.Sprintf("%s/labels/%d", repo.APIURL(), label.ID)
221219
} else { // BelongsToOrg
222220
if org != nil {
223221
result.URL = fmt.Sprintf("%sapi/v1/orgs/%s/labels/%d", setting.AppURL, url.PathEscape(org.Name), label.ID)
@@ -226,6 +224,10 @@ func ToLabel(label *issues_model.Label, repo *repo_model.Repository, org *user_m
226224
}
227225
}
228226

227+
if labelBelongsToRepo && repo == nil {
228+
log.Error("ToLabel did not get repo to calculate url for label with id '%d'", label.ID)
229+
}
230+
229231
return result
230232
}
231233

tests/integration/git_test.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func testGit(t *testing.T, u *url.URL) {
8383
rawTest(t, &httpContext, little, big, littleLFS, bigLFS)
8484
mediaTest(t, &httpContext, little, big, littleLFS, bigLFS)
8585

86-
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &httpContext, "master", "test/head"))
86+
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &httpContext, "test/head"))
8787
t.Run("InternalReferences", doInternalReferences(&httpContext, dstPath))
8888
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&httpContext, dstPath))
8989
t.Run("AutoMerge", doAutoPRMerge(&httpContext, dstPath))
@@ -125,7 +125,7 @@ func testGit(t *testing.T, u *url.URL) {
125125
rawTest(t, &sshContext, little, big, littleLFS, bigLFS)
126126
mediaTest(t, &sshContext, little, big, littleLFS, bigLFS)
127127

128-
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &sshContext, "master", "test/head2"))
128+
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &sshContext, "test/head2"))
129129
t.Run("InternalReferences", doInternalReferences(&sshContext, dstPath))
130130
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&sshContext, dstPath))
131131
t.Run("MergeFork", func(t *testing.T) {
@@ -333,9 +333,6 @@ func generateCommitWithNewData(size int, repoPath, email, fullName, prefix strin
333333
}
334334
written += n
335335
}
336-
if err != nil {
337-
return "", err
338-
}
339336

340337
// Commit
341338
// Now here we should explicitly allow lfs filters to run
@@ -750,7 +747,7 @@ func doInternalReferences(ctx *APITestContext, dstPath string) func(t *testing.T
750747
}
751748
}
752749

753-
func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headBranch string) func(t *testing.T) {
750+
func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string) func(t *testing.T) {
754751
return func(t *testing.T) {
755752
defer tests.PrintCurrentTest(t)()
756753

0 commit comments

Comments
 (0)