gitea-branch-cleanup: drop redundant nil guards on PR model fields
gofmt / Format checking (pull_request) Successful in 6s
go-generate-check / go-generate-check (pull_request) Successful in 18s
gofmt / Linter and static analysis (pull_request) Successful in 1m30s
go-test-unit / go-test-unit (pull_request) Successful in 1m24s
Integration (Selective) / check (pull_request) Successful in 8s
Integration (Selective) / integration (pull_request) Failing after 10m30s

pr.Head/pr.Base of a PR returned by GetPullRequestsWithState are never
nil in real Gitea data. Drop the "!= nil" part of the branch-collection
guards, keeping the meaningful "Ref != ''" business condition. Complete
the test mock accordingly.

Assisted-by: Anthropic:claude-opus-4.8
This commit is contained in:
2026-07-22 10:58:16 +02:00
parent 539e4558e2
commit 2e15786d80
2 changed files with 4 additions and 2 deletions
+2 -2
View File
@@ -58,10 +58,10 @@ func (s *CleanupService) IdentifyCandidates(ctx context.Context, opts CleanupOpt
}
for _, pr := range openPRs {
if pr.Head != nil && pr.Head.Ref != "" {
if pr.Head.Ref != "" {
openPRBranches[pr.Head.Ref] = true
}
if pr.Base != nil && pr.Base.Ref != "" {
if pr.Base.Ref != "" {
openPRBranches[pr.Base.Ref] = true
}
}
@@ -31,6 +31,7 @@ func TestCleanupService_IdentifyCandidates(t *testing.T) {
mockGitea.EXPECT().GetPullRequestsWithState(owner, repo, "open").Return([]*models.PullRequest{
{
Head: &models.PRBranchInfo{Ref: "temp-has-pr"},
Base: &models.PRBranchInfo{Ref: "main"},
},
}, nil)
@@ -121,6 +122,7 @@ func TestCleanupService_IdentifyCandidates_MultiplePrefixes(t *testing.T) {
mockGitea.EXPECT().GetPullRequestsWithState(owner, repo, "open").Return([]*models.PullRequest{
{
Head: &models.PRBranchInfo{Ref: "test-has-pr"},
Base: &models.PRBranchInfo{Ref: "main"},
},
}, nil)