Skip to content

Commit b6c5345

Browse files
committed
fix: address upstream CI lint + test issues
- Replace encoding/json with gitea.dev/modules/json (depguard) - sort.Slice/sort.Strings → slices.Sort (modernize) - Rename base_ → baseBranch (revive: no underscores) - Add missing test fixture for issues listing without page= param Signed-off-by: David E. Lovas <david@rexovas.com>
1 parent ec8c6da commit b6c5345

7 files changed

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Access-Control-Allow-Origin: *
2+
Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
3+
Cache-Control: private, max-age=60, s-maxage=60
4+
Content-Security-Policy: default-src 'none'
5+
Content-Type: application/json; charset=utf-8
6+
Etag: W/"4d1d8ecb86bafe76a686d250018cc158745dd6bc794ef651eeeeecbfc1a947bc"
7+
Link: <https://api.github.com/repositories/220672974/issues?direction=asc&page=2&per_page=2&sort=created&state=all>; rel="next", <https://api.github.com/repositories/220672974/issues?direction=asc&page=3&per_page=2&sort=created&state=all>; rel="last"
8+
Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
9+
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
10+
Vary: Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With
11+
X-Accepted-Github-Permissions: issues=read
12+
X-Content-Type-Options: nosniff
13+
X-Frame-Options: deny
14+
X-Github-Api-Version-Selected: 2022-11-28
15+
X-Github-Media-Type: github.v3; param=squirrel-girl-preview
16+
X-Github-Request-Id: C4F6:A93E1:6A3A9E:5B260C:69AF24E7
17+
X-Ratelimit-Limit: 5000
18+
X-Ratelimit-Remaining: 4931
19+
X-Ratelimit-Reset: 1773089427
20+
X-Ratelimit-Resource: core
21+
X-Ratelimit-Used: 69
22+
X-Xss-Protection: 0
23+
24+
[{"url":"https://api.github.com/repos/go-gitea/test_repo/issues/1","repository_url":"https://api.github.com/repos/go-gitea/test_repo","labels_url":"https://api.github.com/repos/go-gitea/test_repo/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/go-gitea/test_repo/issues/1/comments","events_url":"https://api.github.com/repos/go-gitea/test_repo/issues/1/events","html_url":"https://github.com/go-gitea/test_repo/issues/1","id":520479843,"node_id":"MDU6SXNzdWU1MjA0Nzk4NDM=","number":1,"title":"Please add an animated gif icon to the merge button","user":{"login":"guillep2k","id":18600385,"node_id":"MDQ6VXNlcjE4NjAwMzg1","avatar_url":"https://avatars.githubusercontent.com/u/18600385?v=4","gravatar_id":"","url":"https://api.github.com/users/guillep2k","html_url":"https://github.com/guillep2k","followers_url":"https://api.github.com/users/guillep2k/followers","following_url":"https://api.github.com/users/guillep2k/following{/other_user}","gists_url":"https://api.github.com/users/guillep2k/gists{/gist_id}","starred_url":"https://api.github.com/users/guillep2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guillep2k/subscriptions","organizations_url":"https://api.github.com/users/guillep2k/orgs","repos_url":"https://api.github.com/users/guillep2k/repos","events_url":"https://api.github.com/users/guillep2k/events{/privacy}","received_events_url":"https://api.github.com/users/guillep2k/received_events","type":"User","user_view_type":"public","site_admin":false},"labels":[{"id":1667254252,"node_id":"MDU6TGFiZWwxNjY3MjU0MjUy","url":"https://api.github.com/repos/go-gitea/test_repo/labels/bug","name":"bug","color":"d73a4a","default":true,"description":"Something isn't working"},{"id":1667254261,"node_id":"MDU6TGFiZWwxNjY3MjU0MjYx","url":"https://api.github.com/repos/go-gitea/test_repo/labels/good%20first%20issue","name":"good first issue","color":"7057ff","default":true,"description":"Good for newcomers"}],"state":"closed","locked":false,"assignees":[],"milestone":{"url":"https://api.github.com/repos/go-gitea/test_repo/milestones/1","html_url":"https://github.com/go-gitea/test_repo/milestone/1","labels_url":"https://api.github.com/repos/go-gitea/test_repo/milestones/1/labels","id":4839941,"node_id":"MDk6TWlsZXN0b25lNDgzOTk0MQ==","number":1,"title":"1.0.0","description":"Milestone 1.0.0","creator":{"login":"mrsdizzie","id":1669571,"node_id":"MDQ6VXNlcjE2Njk1NzE=","avatar_url":"https://avatars.githubusercontent.com/u/1669571?v=4","gravatar_id":"","url":"https://api.github.com/users/mrsdizzie","html_url":"https://github.com/mrsdizzie","followers_url":"https://api.github.com/users/mrsdizzie/followers","following_url":"https://api.github.com/users/mrsdizzie/following{/other_user}","gists_url":"https://api.github.com/users/mrsdizzie/gists{/gist_id}","starred_url":"https://api.github.com/users/mrsdizzie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrsdizzie/subscriptions","organizations_url":"https://api.github.com/users/mrsdizzie/orgs","repos_url":"https://api.github.com/users/mrsdizzie/repos","events_url":"https://api.github.com/users/mrsdizzie/events{/privacy}","received_events_url":"https://api.github.com/users/mrsdizzie/received_events","type":"User","user_view_type":"public","site_admin":false},"open_issues":1,"closed_issues":1,"state":"closed","created_at":"2019-11-12T19:37:08Z","updated_at":"2019-11-12T21:56:17Z","due_on":"2019-11-11T00:00:00Z","closed_at":"2019-11-12T19:45:49Z"},"comments":0,"created_at":"2019-11-09T17:00:29Z","updated_at":"2019-11-12T20:29:53Z","closed_at":"2019-11-12T20:22:22Z","assignee":null,"author_association":"MEMBER","type":null,"active_lock_reason":null,"sub_issues_summary":{"total":0,"completed":0,"percent_completed":0},"issue_dependencies_summary":{"blocked_by":0,"total_blocked_by":0,"blocking":0,"total_blocking":0},"body":"I just want the merge button to hurt my eyes a little. 😝 ","closed_by":{"login":"mrsdizzie","id":1669571,"node_id":"MDQ6VXNlcjE2Njk1NzE=","avatar_url":"https://avatars.githubusercontent.com/u/1669571?v=4","gravatar_id":"","url":"https://api.github.com/users/mrsdizzie","html_url":"https://github.com/mrsdizzie","followers_url":"https://api.github.com/users/mrsdizzie/followers","following_url":"https://api.github.com/users/mrsdizzie/following{/other_user}","gists_url":"https://api.github.com/users/mrsdizzie/gists{/gist_id}","starred_url":"https://api.github.com/users/mrsdizzie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrsdizzie/subscriptions","organizations_url":"https://api.github.com/users/mrsdizzie/orgs","repos_url":"https://api.github.com/users/mrsdizzie/repos","events_url":"https://api.github.com/users/mrsdizzie/events{/privacy}","received_events_url":"https://api.github.com/users/mrsdizzie/received_events","type":"User","user_view_type":"public","site_admin":false},"reactions":{"url":"https://api.github.com/repos/go-gitea/test_repo/issues/1/reactions","total_count":1,"+1":1,"-1":0,"laugh":0,"hooray":0,"confused":0,"heart":0,"rocket":0,"eyes":0},"timeline_url":"https://api.github.com/repos/go-gitea/test_repo/issues/1/timeline","performed_via_github_app":null,"state_reason":"completed","pinned_comment":null},{"url":"https://api.github.com/repos/go-gitea/test_repo/issues/2","repository_url":"https://api.github.com/repos/go-gitea/test_repo","labels_url":"https://api.github.com/repos/go-gitea/test_repo/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/go-gitea/test_repo/issues/2/comments","events_url":"https://api.github.com/repos/go-gitea/test_repo/issues/2/events","html_url":"https://github.com/go-gitea/test_repo/issues/2","id":521799485,"node_id":"MDU6SXNzdWU1MjE3OTk0ODU=","number":2,"title":"Test issue","user":{"login":"mrsdizzie","id":1669571,"node_id":"MDQ6VXNlcjE2Njk1NzE=","avatar_url":"https://avatars.githubusercontent.com/u/1669571?v=4","gravatar_id":"","url":"https://api.github.com/users/mrsdizzie","html_url":"https://github.com/mrsdizzie","followers_url":"https://api.github.com/users/mrsdizzie/followers","following_url":"https://api.github.com/users/mrsdizzie/following{/other_user}","gists_url":"https://api.github.com/users/mrsdizzie/gists{/gist_id}","starred_url":"https://api.github.com/users/mrsdizzie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrsdizzie/subscriptions","organizations_url":"https://api.github.com/users/mrsdizzie/orgs","repos_url":"https://api.github.com/users/mrsdizzie/repos","events_url":"https://api.github.com/users/mrsdizzie/events{/privacy}","received_events_url":"https://api.github.com/users/mrsdizzie/received_events","type":"User","user_view_type":"public","site_admin":false},"labels":[{"id":1667254257,"node_id":"MDU6TGFiZWwxNjY3MjU0MjU3","url":"https://api.github.com/repos/go-gitea/test_repo/labels/duplicate","name":"duplicate","color":"cfd3d7","default":true,"description":"This issue or pull request already exists"}],"state":"closed","locked":false,"assignees":[],"milestone":{"url":"https://api.github.com/repos/go-gitea/test_repo/milestones/2","html_url":"https://github.com/go-gitea/test_repo/milestone/2","labels_url":"https://api.github.com/repos/go-gitea/test_repo/milestones/2/labels","id":4839942,"node_id":"MDk6TWlsZXN0b25lNDgzOTk0Mg==","number":2,"title":"1.1.0","description":"Milestone 1.1.0","creator":{"login":"mrsdizzie","id":1669571,"node_id":"MDQ6VXNlcjE2Njk1NzE=","avatar_url":"https://avatars.githubusercontent.com/u/1669571?v=4","gravatar_id":"","url":"https://api.github.com/users/mrsdizzie","html_url":"https://github.com/mrsdizzie","followers_url":"https://api.github.com/users/mrsdizzie/followers","following_url":"https://api.github.com/users/mrsdizzie/following{/other_user}","gists_url":"https://api.github.com/users/mrsdizzie/gists{/gist_id}","starred_url":"https://api.github.com/users/mrsdizzie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrsdizzie/subscriptions","organizations_url":"https://api.github.com/users/mrsdizzie/orgs","repos_url":"https://api.github.com/users/mrsdizzie/repos","events_url":"https://api.github.com/users/mrsdizzie/events{/privacy}","received_events_url":"https://api.github.com/users/mrsdizzie/received_events","type":"User","user_view_type":"public","site_admin":false},"open_issues":0,"closed_issues":2,"state":"closed","created_at":"2019-11-12T19:37:25Z","updated_at":"2019-11-12T21:39:27Z","due_on":"2019-11-12T00:00:00Z","closed_at":"2019-11-12T19:45:46Z"},"comments":2,"created_at":"2019-11-12T21:00:06Z","updated_at":"2019-11-12T22:07:14Z","closed_at":"2019-11-12T21:01:31Z","assignee":null,"author_association":"MEMBER","type":null,"active_lock_reason":null,"sub_issues_summary":{"total":0,"completed":0,"percent_completed":0},"issue_dependencies_summary":{"blocked_by":0,"total_blocked_by":0,"blocking":0,"total_blocking":0},"body":"This is test issue 2, do not touch!","closed_by":{"login":"mrsdizzie","id":1669571,"node_id":"MDQ6VXNlcjE2Njk1NzE=","avatar_url":"https://avatars.githubusercontent.com/u/1669571?v=4","gravatar_id":"","url":"https://api.github.com/users/mrsdizzie","html_url":"https://github.com/mrsdizzie","followers_url":"https://api.github.com/users/mrsdizzie/followers","following_url":"https://api.github.com/users/mrsdizzie/following{/other_user}","gists_url":"https://api.github.com/users/mrsdizzie/gists{/gist_id}","starred_url":"https://api.github.com/users/mrsdizzie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrsdizzie/subscriptions","organizations_url":"https://api.github.com/users/mrsdizzie/orgs","repos_url":"https://api.github.com/users/mrsdizzie/repos","events_url":"https://api.github.com/users/mrsdizzie/events{/privacy}","received_events_url":"https://api.github.com/users/mrsdizzie/received_events","type":"User","user_view_type":"public","site_admin":false},"reactions":{"url":"https://api.github.com/repos/go-gitea/test_repo/issues/2/reactions","total_count":6,"+1":1,"-1":1,"laugh":1,"hooray":1,"confused":1,"heart":1,"rocket":0,"eyes":0},"timeline_url":"https://api.github.com/repos/go-gitea/test_repo/issues/2/timeline","performed_via_github_app":null,"state_reason":"completed","pinned_comment":null}]

services/migrations/github.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,10 @@ func (g *GithubDownloaderV3) getIssuesSince(ctx context.Context, page, perPage i
541541
})
542542
}
543543

544-
// End when the cursor is exhausted (no more `after` in the Link header).
545-
return allIssues, resp.After == "", nil
544+
// End when the cursor is exhausted AND a short page confirms no more results.
545+
// Both conditions together handle cursor-based and page-based responses.
546+
isEnd := resp.After == "" && len(issues) < perPage
547+
return allIssues, isEnd, nil
546548
}
547549

548550
// SupportGetRepoComments return true if it supports get repo comments

services/migrations/github_graphql.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ package migrations
2323
import (
2424
"bytes"
2525
"context"
26-
"encoding/json"
26+
"gitea.dev/modules/json"
2727
"fmt"
2828
"net/http"
29-
"sort"
29+
"slices"
3030
"strconv"
3131
"strings"
3232
"time"
@@ -120,7 +120,7 @@ func (g *GithubDownloaderV3) doGraphQL(ctx context.Context, query string, vars m
120120
}
121121

122122
var envelope struct {
123-
Data json.RawMessage `json:"data"`
123+
Data json.Value `json:"data"`
124124
Errors []graphQLError `json:"errors"`
125125
}
126126
decodeErr := json.NewDecoder(resp.Body).Decode(&envelope)
@@ -477,7 +477,7 @@ func (g *GithubDownloaderV3) getCachedComments(page, perPage int) ([]*base.Comme
477477
for n := range g.gqlComments {
478478
nums = append(nums, n)
479479
}
480-
sort.Slice(nums, func(i, j int) bool { return nums[i] < nums[j] })
480+
slices.Sort(nums)
481481
// non-nil sentinel so an empty sweep isn't re-flattened every call
482482
g.gqlCommentsFlat = make([]*base.Comment, 0)
483483
for _, n := range nums {

services/migrations/github_graphql_pr.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,10 @@ func (g *GithubDownloaderV3) convertGraphQLPullRequest(node *gqlPullRequest) *ba
300300
head.OwnerName = node.HeadRepo.Owner.Login
301301
head.CloneURL = node.HeadRepo.URL + ".git"
302302
}
303-
base_ := base.PullRequestBranch{Ref: node.BaseRefName, SHA: node.BaseRefOID}
303+
baseBranch := base.PullRequestBranch{Ref: node.BaseRefName, SHA: node.BaseRefOID}
304304
if node.BaseRepo != nil {
305-
base_.RepoName = node.BaseRepo.Name
306-
base_.OwnerName = node.BaseRepo.Owner.Login
305+
baseBranch.RepoName = node.BaseRepo.Name
306+
baseBranch.OwnerName = node.BaseRepo.Owner.Login
307307
}
308308

309309
// GitHub REST reports a merged PR as state "closed"; keep that convention.
@@ -330,7 +330,7 @@ func (g *GithubDownloaderV3) convertGraphQLPullRequest(node *gqlPullRequest) *ba
330330
MergedTime: node.MergedAt,
331331
MergeCommitSHA: mergeCommitSHA,
332332
Head: head,
333-
Base: base_,
333+
Base: baseBranch,
334334
Assignees: assignees,
335335
IsLocked: node.Locked,
336336
Reactions: convertGraphQLReactions(node.Reactions),

services/migrations/github_graphql_pr_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package migrations
55

66
import (
7-
"encoding/json"
7+
"gitea.dev/modules/json"
88
"testing"
99

1010
base "gitea.dev/modules/migration"

services/migrations/github_graphql_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package migrations
55

66
import (
7-
"encoding/json"
7+
"gitea.dev/modules/json"
88
"io"
99
"net/http"
1010
"net/http/httptest"

services/migrations/github_graphql_timeline.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"errors"
2525
"fmt"
2626
"hash/fnv"
27-
"sort"
27+
"slices"
2828
"time"
2929

3030
"gitea.dev/modules/log"
@@ -218,7 +218,7 @@ func (g *GithubDownloaderV3) attachTimelineEvents(ctx context.Context, nodeIDToI
218218
ids = append(ids, id)
219219
}
220220
}
221-
sort.Strings(ids) // deterministic batching
221+
slices.Sort(ids) // deterministic batching
222222
for start := 0; start < len(ids); start += timelineBatchSize {
223223
end := min(start+timelineBatchSize, len(ids))
224224
eventsByID, err := g.fetchTimelineEvents(ctx, ids[start:end])

0 commit comments

Comments
 (0)