Skip to content

Commit 1f727b1

Browse files
committed
fix: address upstream CI lint issues (gci, gofumpt, modernize, nilnil)
- Fix import ordering (gci) - Fix gofumpt formatting - atomic.Int32 modernize - Replace nil,nil return with empty map (nilnil) - maps.Copy instead of manual loop (modernize) - Fix useless-assert (store value before comparing) - encoding/json → modules/json in timeline test Signed-off-by: David E. Lovas <david@rexovas.com>
1 parent b6c5345 commit 1f727b1

5 files changed

Lines changed: 24 additions & 19 deletions

File tree

services/migrations/github_graphql.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ package migrations
2323
import (
2424
"bytes"
2525
"context"
26-
"gitea.dev/modules/json"
2726
"fmt"
2827
"net/http"
2928
"slices"
3029
"strconv"
3130
"strings"
3231
"time"
3332

33+
"gitea.dev/modules/json"
3434
"gitea.dev/modules/log"
3535
base "gitea.dev/modules/migration"
3636
)
@@ -120,8 +120,8 @@ func (g *GithubDownloaderV3) doGraphQL(ctx context.Context, query string, vars m
120120
}
121121

122122
var envelope struct {
123-
Data json.Value `json:"data"`
124-
Errors []graphQLError `json:"errors"`
123+
Data json.Value `json:"data"`
124+
Errors []graphQLError `json:"errors"`
125125
}
126126
decodeErr := json.NewDecoder(resp.Body).Decode(&envelope)
127127
header := resp.Header

services/migrations/github_graphql_pr_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
package migrations
55

66
import (
7-
"gitea.dev/modules/json"
87
"testing"
98

10-
base "gitea.dev/modules/migration"
11-
129
"github.com/stretchr/testify/assert"
1310
"github.com/stretchr/testify/require"
11+
12+
"gitea.dev/modules/json"
13+
base "gitea.dev/modules/migration"
1414
)
1515

1616
// TestGraphQLPullRequestParsing validates that the PR response structs match the

services/migrations/github_graphql_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package migrations
55

66
import (
7-
"gitea.dev/modules/json"
87
"io"
98
"net/http"
109
"net/http/httptest"
@@ -14,10 +13,11 @@ import (
1413
"testing"
1514
"time"
1615

17-
base "gitea.dev/modules/migration"
18-
1916
"github.com/stretchr/testify/assert"
2017
"github.com/stretchr/testify/require"
18+
19+
"gitea.dev/modules/json"
20+
base "gitea.dev/modules/migration"
2121
)
2222

2323
func TestIsGraphQLRateLimited(t *testing.T) {
@@ -57,9 +57,9 @@ func TestGraphQLRateResetWait(t *testing.T) {
5757
// bug: a RATE_LIMITED response is waited out (per the Retry-After header) and the
5858
// request retried in place, instead of erroring and aborting the whole sync.
5959
func TestDoGraphQLRetriesOnRateLimited(t *testing.T) {
60-
var calls int32
60+
var calls atomic.Int32
6161
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
62-
if atomic.AddInt32(&calls, 1) == 1 {
62+
if calls.Add(1) == 1 {
6363
w.Header().Set("Retry-After", "1") // 1s so the test stays fast
6464
io.WriteString(w, `{"errors":[{"type":"RATE_LIMITED","message":"API rate limit exceeded"}]}`)
6565
return

services/migrations/github_graphql_timeline.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"errors"
2525
"fmt"
2626
"hash/fnv"
27+
"maps"
2728
"slices"
2829
"time"
2930

@@ -40,8 +41,10 @@ const timelineBatchSize = 100
4041
// `... on MergedEvent` fragment) is a hard GraphQL validation error that aborts the
4142
// whole timeline pass. issueTimelineItemTypes is the set valid on BOTH unions; the PR
4243
// query adds the PR-only types on top.
43-
const issueTimelineItemTypes = "CLOSED_EVENT,REOPENED_EVENT,LOCKED_EVENT,UNLOCKED_EVENT,RENAMED_TITLE_EVENT,LABELED_EVENT,UNLABELED_EVENT,MILESTONED_EVENT,DEMILESTONED_EVENT,PINNED_EVENT,UNPINNED_EVENT"
44-
const prTimelineItemTypes = issueTimelineItemTypes + ",MERGED_EVENT,HEAD_REF_DELETED_EVENT,AUTO_MERGE_ENABLED_EVENT,AUTO_MERGE_DISABLED_EVENT"
44+
const (
45+
issueTimelineItemTypes = "CLOSED_EVENT,REOPENED_EVENT,LOCKED_EVENT,UNLOCKED_EVENT,RENAMED_TITLE_EVENT,LABELED_EVENT,UNLABELED_EVENT,MILESTONED_EVENT,DEMILESTONED_EVENT,PINNED_EVENT,UNPINNED_EVENT"
46+
prTimelineItemTypes = issueTimelineItemTypes + ",MERGED_EVENT,HEAD_REF_DELETED_EVENT,AUTO_MERGE_ENABLED_EVENT,AUTO_MERGE_DISABLED_EVENT"
47+
)
4548

4649
// Inline-fragment selections, likewise split. These event types expose no databaseId,
4750
// only the node id.
@@ -57,6 +60,7 @@ const issueTimelineFragments = `
5760
... on DemilestonedEvent{id createdAt milestoneTitle actor{login ... on User{databaseId}}}
5861
... on PinnedEvent{id createdAt actor{login ... on User{databaseId}}}
5962
... on UnpinnedEvent{id createdAt actor{login ... on User{databaseId}}}`
63+
6064
const prTimelineFragments = issueTimelineFragments + `
6165
... on MergedEvent{id createdAt actor{login ... on User{databaseId}}}
6266
... on HeadRefDeletedEvent{id createdAt headRefName actor{login ... on User{databaseId}}}
@@ -241,7 +245,7 @@ func (g *GithubDownloaderV3) attachTimelineEvents(ctx context.Context, nodeIDToI
241245
// than aborting; a hot entity with more than one page sweeps the remainder.
242246
func (g *GithubDownloaderV3) fetchTimelineEvents(ctx context.Context, ids []string) (map[string][]*base.Comment, error) {
243247
if len(ids) == 0 {
244-
return nil, nil
248+
return map[string][]*base.Comment{}, nil
245249
}
246250
var resp struct {
247251
Nodes []struct {
@@ -262,9 +266,8 @@ func (g *GithubDownloaderV3) fetchTimelineEvents(ctx context.Context, ids []stri
262266
if err != nil {
263267
return nil, err
264268
}
265-
for id, events := range right {
266-
left[id] = events
267-
}
269+
maps.Copy(left, right)
270+
268271
return left, nil
269272
}
270273
return nil, err

services/migrations/github_graphql_timeline_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
package migrations
55

66
import (
7-
"encoding/json"
87
"strings"
98
"testing"
109

1110
"github.com/stretchr/testify/assert"
1211
"github.com/stretchr/testify/require"
12+
13+
"gitea.dev/modules/json"
1314
)
1415

1516
// TestConvertTimelineItems parses a timeline page (the shape of #13603's real
@@ -80,7 +81,8 @@ func TestConvertTimelineItems(t *testing.T) {
8081

8182
func TestTimelineEventIDStable(t *testing.T) {
8283
id := "MDExOkNsb3NlZEV2ZW50NDAwNjIwMjg0Mw=="
83-
assert.Equal(t, timelineEventID(id), timelineEventID(id), "same node id -> same dedup key (idempotent re-sync)")
84+
idVal := timelineEventID(id)
85+
assert.Equal(t, idVal, timelineEventID(id), "same node id -> same dedup key (idempotent re-sync)")
8486
assert.NotEqual(t, timelineEventID(id), timelineEventID("MDEyOkxhYmVsZWRFdmVudA=="))
8587
assert.Positive(t, timelineEventID(id))
8688
}

0 commit comments

Comments
 (0)