Skip to content

Commit

Permalink
Avoid accessing loop value's reference
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Sep 15, 2021
1 parent 8524446 commit 43391db
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
15 changes: 7 additions & 8 deletions vcs/github/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ type QLIssue struct {
}

func (c *Client) Issues(owner string, name string) ([]vcs.Issue, error) {
var after *githubv4.String
var issues []vcs.Issue

for {
variables := map[string]interface{}{
"owner": githubv4.String(owner),
"name": githubv4.String(name),
"after": after,
}
variables := map[string]interface{}{
"owner": githubv4.String(owner),
"name": githubv4.String(name),
"after": (*githubv4.String)(nil),
}

for {
if err := c.queryWithRetry(context.Background(), &issuesQuery, variables); err != nil {
return issues, err
}
Expand All @@ -58,7 +57,7 @@ func (c *Client) Issues(owner string, name string) ([]vcs.Issue, error) {
for _, v := range issuesQuery.Repository.Issues.Edges {
issues = append(issues, IssueFromQL(v.Node.QLIssue))

after = &v.Cursor
variables["after"] = githubv4.NewString(v.Cursor)
}
}

Expand Down
15 changes: 7 additions & 8 deletions vcs/github/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ type QLPullRequest struct {
}

func (c *Client) PullRequests(owner string, name string) ([]vcs.PullRequest, error) {
var after *githubv4.String
var pullRequests []vcs.PullRequest

for {
variables := map[string]interface{}{
"owner": githubv4.String(owner),
"name": githubv4.String(name),
"after": after,
}
variables := map[string]interface{}{
"owner": githubv4.String(owner),
"name": githubv4.String(name),
"after": (*githubv4.String)(nil),
}

for {
if err := c.queryWithRetry(context.Background(), &pullRequestQuery, variables); err != nil {
return pullRequests, err
}
Expand All @@ -58,7 +57,7 @@ func (c *Client) PullRequests(owner string, name string) ([]vcs.PullRequest, err
for _, v := range pullRequestQuery.Repository.PullRequests.Edges {
pullRequests = append(pullRequests, PullRequestFromQL(v.Node.QLPullRequest))

after = &v.Cursor
variables["after"] = githubv4.NewString(v.Cursor)
}
}

Expand Down
13 changes: 6 additions & 7 deletions vcs/github/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,14 @@ func (c *Client) Repository(owner string, name string) (vcs.Repo, error) {
}

func (c *Client) Repositories(owner string) ([]vcs.Repo, error) {
var after *githubv4.String
var repos []vcs.Repo

for {
variables := map[string]interface{}{
"username": githubv4.String(owner),
"after": after,
}
variables := map[string]interface{}{
"username": githubv4.String(owner),
"after": (*githubv4.String)(nil),
}

for {
if err := c.queryWithRetry(context.Background(), &reposQuery, variables); err != nil {
return nil, err
}
Expand All @@ -96,7 +95,7 @@ func (c *Client) Repositories(owner string) ([]vcs.Repo, error) {

repos = append(repos, repo)

after = &v.Cursor
variables["after"] = githubv4.NewString(v.Cursor)
}
}

Expand Down

0 comments on commit 43391db

Please sign in to comment.