From c4ed31c94b1809dbac712bc29475d91965999816 Mon Sep 17 00:00:00 2001 From: oleg-glushak Date: Thu, 16 Jan 2025 16:45:23 +0100 Subject: [PATCH 1/8] chore: clean-up Signed-off-by: oleg-glushak --- server/events/vcs/github_client.go | 117 ++++++++---- server/events/vcs/github_client_test.go | 239 +++++++++++++++--------- 2 files changed, 228 insertions(+), 128 deletions(-) diff --git a/server/events/vcs/github_client.go b/server/events/vcs/github_client.go index 9d13bb2587..3de3759e10 100644 --- a/server/events/vcs/github_client.go +++ b/server/events/vcs/github_client.go @@ -52,6 +52,27 @@ type GitHubRepoIdCache struct { cache map[githubv4.String]GithubRepoIdCacheEntry } +type pullRequestCommentsQuery struct { + Repository struct { + PullRequest struct { + Comments struct { + PageInfo struct { + HasNextPage bool + EndCursor githubv4.String + } + Nodes []struct { + ID githubv4.String + BodyText githubv4.String + IsMinimized githubv4.Boolean + Author struct { + Login githubv4.String + } + } + } `graphql:"comments(first: $pageSize, after: $after)"` + } `graphql:"pullRequest(number: $number)"` + } `graphql:"repository(owner: $owner, name: $name)"` +} + func NewGitHubRepoIdCache() GitHubRepoIdCache { return GitHubRepoIdCache{ cache: make(map[githubv4.String]GithubRepoIdCacheEntry), @@ -264,52 +285,68 @@ func (g *GithubClient) ReactToComment(logger logging.SimpleLogging, repo models. func (g *GithubClient) HidePrevCommandComments(logger logging.SimpleLogging, repo models.Repo, pullNum int, command string, dir string) error { logger.Debug("Hiding previous command comments on GitHub pull request %d", pullNum) - var allComments []*github.IssueComment - nextPage := 0 + + var ( + query pullRequestCommentsQuery + allMatchingCommentIDs []string + after *githubv4.String // for pagination + ) + + commentsQueryVariables := map[string]interface{}{ + "owner": githubv4.String(repo.Owner), + "name": githubv4.String(repo.Name), + "number": githubv4.Int(pullNum), + "pageSize": githubv4.Int(100), + "after": (*githubv4.String)(nil), + } + for { - comments, resp, err := g.client.Issues.ListComments(g.ctx, repo.Owner, repo.Name, pullNum, &github.IssueListCommentsOptions{ - Sort: github.Ptr("created"), - Direction: github.Ptr("asc"), - ListOptions: github.ListOptions{Page: nextPage}, - }) - if resp != nil { - logger.Debug("GET /repos/%v/%v/issues/%d/comments returned: %v", repo.Owner, repo.Name, pullNum, resp.StatusCode) - } + err := g.v4Client.Query(g.ctx, &query, commentsQueryVariables) if err != nil { return errors.Wrap(err, "listing comments") } - allComments = append(allComments, comments...) - if resp.NextPage == 0 { - break - } - nextPage = resp.NextPage - } - for _, comment := range allComments { - // Using a case insensitive compare here because usernames aren't case - // sensitive and users may enter their atlantis users with different - // cases. - if comment.User != nil && !strings.EqualFold(comment.User.GetLogin(), g.user) { - continue - } - // Crude filtering: The comment templates typically include the command name - // somewhere in the first line. It's a bit of an assumption, but seems like - // a reasonable one, given we've already filtered the comments by the - // configured Atlantis user. - body := strings.Split(comment.GetBody(), "\n") - if len(body) == 0 { - continue - } - firstLine := strings.ToLower(body[0]) - if !strings.Contains(firstLine, strings.ToLower(command)) { - continue + for _, comment := range query.Repository.PullRequest.Comments.Nodes { + logger.Debug("Processing commentID %s, %s, %s", comment.Author.Login, comment.IsMinimized, comment.ID) + if comment.IsMinimized { + logger.Debug("Skipping minimized commentID %s, %s, %s", comment.Author.Login, comment.IsMinimized, comment.ID) + continue + } + + // Using a case insensitive compare here because usernames aren't case + // sensitive and users may enter their atlantis users with different + // cases. + if comment.Author.Login != "" && !strings.EqualFold(string(comment.Author.Login+"[bot]"), g.user) { + continue + } + + body := strings.Split(string(comment.BodyText), "\n") + if len(body) == 0 { + continue + } + firstLine := strings.ToLower(body[0]) + if !strings.Contains(firstLine, strings.ToLower(command)) { + continue + } + + // If dir was specified, skip processing comments that don't contain the dir in the first line + if dir != "" && !strings.Contains(firstLine, strings.ToLower(dir)) { + continue + } + + allMatchingCommentIDs = append(allMatchingCommentIDs, string(comment.ID)) } - // If dir was specified, skip processing comments that don't contain the dir in the first line - if dir != "" && !strings.Contains(firstLine, strings.ToLower(dir)) { - continue + pageInfo := query.Repository.PullRequest.Comments.PageInfo + if !pageInfo.HasNextPage { + break } + after = &pageInfo.EndCursor + commentsQueryVariables["after"] = after + } + + for _, commentID := range allMatchingCommentIDs { var m struct { MinimizeComment struct { MinimizedComment struct { @@ -321,11 +358,11 @@ func (g *GithubClient) HidePrevCommandComments(logger logging.SimpleLogging, rep } input := githubv4.MinimizeCommentInput{ Classifier: githubv4.ReportedContentClassifiersOutdated, - SubjectID: comment.GetNodeID(), + SubjectID: commentID, } - logger.Debug("Hiding comment %s", comment.GetNodeID()) + logger.Debug("Hiding commentID %s", commentID) if err := g.v4Client.Mutate(g.ctx, &m, input, nil); err != nil { - return errors.Wrapf(err, "minimize comment %s", comment.GetNodeID()) + return errors.Wrapf(err, "minimize commentID %s", commentID) } } diff --git a/server/events/vcs/github_client_test.go b/server/events/vcs/github_client_test.go index 8d4912616d..aa2ff72eeb 100644 --- a/server/events/vcs/github_client_test.go +++ b/server/events/vcs/github_client_test.go @@ -9,6 +9,7 @@ import ( "net/http/httptest" "net/url" "os" + "regexp" "strings" "testing" @@ -147,26 +148,82 @@ func TestGithubClient_GetModifiedFilesMovedFile(t *testing.T) { func TestGithubClient_PaginatesComments(t *testing.T) { logger := logging.NewNoopLogger(t) calls := 0 - issueResps := []string{ - `[ - {"node_id": "1", "body": "asd\nplan\nasd", "user": {"login": "someone-else"}}, - {"node_id": "2", "body": "asd plan\nasd", "user": {"login": "user"}} -]`, - `[ - {"node_id": "3", "body": "asd", "user": {"login": "someone-else"}}, - {"node_id": "4", "body": "asdasd", "user": {"login": "someone-else"}} -]`, - `[ - {"node_id": "5", "body": "asd plan", "user": {"login": "someone-else"}}, - {"node_id": "6", "body": "asd\nplan", "user": {"login": "user"}} -]`, - `[ - {"node_id": "7", "body": "asd", "user": {"login": "user"}}, - {"node_id": "8", "body": "asd plan \n asd", "user": {"login": "user"}} -]`, + issueResps := []string{`{ + "data": { + "repository": { + "pullRequest": { + "comments": { + "nodes": [ + {"id": "1", "bodyText": "asd\nplan\nasd", "isMinimized": false, "author": {"login": "someone-else"}}, + {"id": "2", "bodyText": "asd plan\nasd", "isMinimized": false, "author": {"login": "user"}} + ], + "pageInfo": { + "hasNextPage": true, + "endCursor": "0" + } + } + } + } + } + }`, + `{ + "data": { + "repository": { + "pullRequest": { + "comments": { + "nodes": [ + {"id": "3", "bodyText": "asd", "isMinimized": false, "author": {"login": "someone-else"}}, + {"id": "4", "bodyText": "asdasd", "isMinimized": false, "author": {"login": "someone-else"}} + ], + "pageInfo": { + "hasNextPage": true, + "endCursor": "1" + } + } + } + } + } + }`, + `{ + "data": { + "repository": { + "pullRequest": { + "comments": { + "nodes": [ + {"id": "5", "bodyText": "asd plan", "isMinimized": false, "author": {"login": "someone-else"}}, + {"id": "6", "bodyText": "asd\nplan", "isMinimized": false, "author": {"login": "user"}} + ], + "pageInfo": { + "hasNextPage": true, + "endCursor": "2" + } + } + } + } + } + }`, + `{ + "data": { + "repository": { + "pullRequest": { + "comments": { + "nodes": [ + {"id": "7", "bodyText": "asd", "isMinimized": false, "author": {"login": "user"}}, + {"id": "8", "bodyText": "asd plan \n asd", "isMinimized": false, "author": {"login": "user"}} + ], + "pageInfo": { + "hasNextPage": false, + "endCursor": "3" + } + } + } + } + } + }`, } minimizeResp := "{}" type graphQLCall struct { + Query string `json:"query"` Variables struct { Input githubv4.MinimizeCommentInput `json:"input"` } `json:"variables"` @@ -174,43 +231,36 @@ func TestGithubClient_PaginatesComments(t *testing.T) { gotMinimizeCalls := make([]graphQLCall, 0, 2) testServer := httptest.NewTLSServer( http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.Method + " " + r.RequestURI { - case "POST /api/graphql": - defer r.Body.Close() // nolint: errcheck - body, err := io.ReadAll(r.Body) - if err != nil { - t.Errorf("read body error: %v", err) - http.Error(w, "server error", http.StatusInternalServerError) - return - } - call := graphQLCall{} - err = json.Unmarshal(body, &call) - if err != nil { - t.Errorf("parse body error: %v", err) - http.Error(w, "server error", http.StatusInternalServerError) - return - } - gotMinimizeCalls = append(gotMinimizeCalls, call) + t.Log(r.Method + " " + r.RequestURI) + + var gqlRequest graphQLCall + if err := json.NewDecoder(r.Body).Decode(&gqlRequest); err != nil { + t.Errorf("parse body error: %v", err) + http.Error(w, "server error", http.StatusInternalServerError) + return + } + + re := regexp.MustCompile(`(?i)^\s*(query|mutation)\b`) + matches := re.FindStringSubmatch(gqlRequest.Query) + if len(matches) < 2 { + t.Errorf("unexpected query: %q", gqlRequest.Query) + http.Error(w, "server error", http.StatusInternalServerError) + return + } + operationType := strings.ToLower(matches[1]) + + switch operationType { + case "mutation": + gotMinimizeCalls = append(gotMinimizeCalls, gqlRequest) w.Write([]byte(minimizeResp)) // nolint: errcheck return - default: - if r.Method != "GET" || !strings.HasPrefix(r.RequestURI, "/api/v3/repos/owner/repo/issues/123/comments") { - t.Errorf("got unexpected request at %q", r.RequestURI) - http.Error(w, "not found", http.StatusNotFound) - return - } - if (calls + 1) < len(issueResps) { - w.Header().Add( - "Link", - fmt.Sprintf( - `; rel="next"`, - r.Host, - calls+1, - ), - ) - } + case "query": w.Write([]byte(issueResps[calls])) // nolint: errcheck calls++ + default: + t.Errorf("got unexpected request at %q", r.RequestURI) + http.Error(w, "not found", http.StatusNotFound) + return } }), ) @@ -218,7 +268,7 @@ func TestGithubClient_PaginatesComments(t *testing.T) { testServerURL, err := url.Parse(testServer.URL) Ok(t, err) - client, err := vcs.NewGithubClient(testServerURL.Host, &vcs.GithubUserCredentials{"user", "pass", ""}, vcs.GithubConfig{}, 0, logging.NewNoopLogger(t)) + client, err := vcs.NewGithubClient(testServerURL.Host, &vcs.GithubUserCredentials{"user[bot]", "pass", ""}, vcs.GithubConfig{}, 0, logging.NewNoopLogger(t)) Ok(t, err) defer disableSSLVerification()() @@ -249,26 +299,37 @@ func TestGithubClient_PaginatesComments(t *testing.T) { func TestGithubClient_HideOldComments(t *testing.T) { logger := logging.NewNoopLogger(t) - atlantisUser := "AtlantisUser" + atlantisUser := "AtlantisUser[bot]" pullRequestNum := 123 - issueResp := strings.ReplaceAll(`[ - {"node_id": "1", "body": "asd\nplan\nasd", "user": {"login": "someone-else"}}, - {"node_id": "2", "body": "asd plan\nasd", "user": {"login": "someone-else"}}, - {"node_id": "3", "body": "asdasdasd\nasdasdasd", "user": {"login": "someone-else"}}, - {"node_id": "4", "body": "asdasdasd\nasdasdasd", "user": {"login": "AtlantisUser"}}, - {"node_id": "5", "body": "asd\nplan\nasd", "user": {"login": "AtlantisUser"}}, - {"node_id": "6", "body": "Ran Plan for 2 projects:", "user": {"login": "AtlantisUser"}}, - {"node_id": "7", "body": "Ran Apply for 2 projects:", "user": {"login": "AtlantisUser"}}, - {"node_id": "8", "body": "Ran Plan for dir: 'stack1' workspace: 'default'", "user": {"login": "AtlantisUser"}}, - {"node_id": "9", "body": "Ran Plan for dir: 'stack2' workspace: 'default'", "user": {"login": "AtlantisUser"}}, - {"node_id": "10", "body": "Continued Plan from previous comment\nasd", "user": {"login": "AtlantisUser"}} -]`, "'", "`") - minimizeResp := "{}" + issueResp := strings.ReplaceAll(`{ + "data": { + "repository": { + "pullRequest": { + "comments": { + "nodes": [ + {"id": "1", "bodyText": "asd\nplan\nasd", "isMinimized": false, "author": {"login": "someone-else"}}, + {"id": "2", "bodyText": "asd plan\nasd", "isMinimized": false, "author": {"login": "someone-else"}}, + {"id": "3", "bodyText": "asdasdasd\nasdasdasd", "isMinimized": false, "author": {"login": "someone-else"}}, + {"id": "4", "bodyText": "asdasdasd\nasdasdasd", "isMinimized": false, "author": {"login": "AtlantisUser"}}, + {"id": "5", "bodyText": "asd\nplan\nasd", "isMinimized": false, "author": {"login": "AtlantisUser"}}, + {"id": "6", "bodyText": "Ran Plan for 2 projects:", "isMinimized": true, "author": {"login": "AtlantisUser"}}, + {"id": "7", "bodyText": "Ran Apply for 2 projects:", "isMinimized": false, "author": {"login": "AtlantisUser"}}, + {"id": "8", "bodyText": "Ran Plan for dir: 'stack1' workspace: 'default'", "isMinimized": false, "author": {"login": "AtlantisUser"}}, + {"id": "9", "bodyText": "Ran Plan for dir: 'stack2' workspace: 'default'", "isMinimized": false, "author": {"login": "AtlantisUser"}}, + {"id": "10", "bodyText": "Continued Plan from previous comment\nasd", "isMinimized": false, "author": {"login": "AtlantisUser"}} + ] + } + } + } + } +}`, "'", "`") type graphQLCall struct { + Query string `json:"query"` Variables struct { Input githubv4.MinimizeCommentInput `json:"input"` } `json:"variables"` } + minimizeResp := "{}" cases := []struct { dir string @@ -276,10 +337,11 @@ func TestGithubClient_HideOldComments(t *testing.T) { processedCommentIds []string }{ { - // With no dir specified, comments 6, 8, 9 and 10 should be minimized. + // With no dir specified, comments 8, 9 and 10 should be minimized. + // Comment 6 should not be minimized, because it's already minimized. "", - 4, - []string{"6", "8", "9", "10"}, + 3, + []string{"8", "9", "10"}, }, { // With a dir of "stack1", comment 8 should be minimized. @@ -300,29 +362,30 @@ func TestGithubClient_HideOldComments(t *testing.T) { gotMinimizeCalls := make([]graphQLCall, 0, 1) testServer := httptest.NewTLSServer( http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch r.Method + " " + r.RequestURI { - // This gets the pull request's comments. - case fmt.Sprintf("GET /api/v3/repos/owner/repo/issues/%v/comments?direction=asc&sort=created", pullRequestNum): - w.Write([]byte(issueResp)) // nolint: errcheck + var gqlRequest graphQLCall + if err := json.NewDecoder(r.Body).Decode(&gqlRequest); err != nil { + t.Errorf("parse body error: %v", err) + http.Error(w, "server error", http.StatusInternalServerError) return - case "POST /api/graphql": - defer r.Body.Close() // nolint: errcheck - body, err := io.ReadAll(r.Body) - if err != nil { - t.Errorf("read body error: %v", err) - http.Error(w, "server error", http.StatusInternalServerError) - return - } - call := graphQLCall{} - err = json.Unmarshal(body, &call) - if err != nil { - t.Errorf("parse body error: %v", err) - http.Error(w, "server error", http.StatusInternalServerError) - return - } - gotMinimizeCalls = append(gotMinimizeCalls, call) + } + + re := regexp.MustCompile(`(?i)^\s*(query|mutation)\b`) + matches := re.FindStringSubmatch(gqlRequest.Query) + if len(matches) < 2 { + t.Errorf("unexpected query: %q", gqlRequest.Query) + http.Error(w, "server error", http.StatusInternalServerError) + return + } + + operationType := strings.ToLower(matches[1]) + switch operationType { + case "mutation": + gotMinimizeCalls = append(gotMinimizeCalls, gqlRequest) w.Write([]byte(minimizeResp)) // nolint: errcheck return + case "query": + w.Write([]byte(issueResp)) // nolint: errcheck + return default: t.Errorf("got unexpected request at %q", r.RequestURI) http.Error(w, "not found", http.StatusNotFound) From 7c257cd25eda2a7e7aab4634902c30f018ea5806 Mon Sep 17 00:00:00 2001 From: oleg-glushak Date: Thu, 16 Jan 2025 16:58:18 +0100 Subject: [PATCH 2/8] chore: clean-up Signed-off-by: oleg-glushak --- server/events/vcs/github_client_test.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/server/events/vcs/github_client_test.go b/server/events/vcs/github_client_test.go index aa2ff72eeb..9d39b27661 100644 --- a/server/events/vcs/github_client_test.go +++ b/server/events/vcs/github_client_test.go @@ -9,7 +9,6 @@ import ( "net/http/httptest" "net/url" "os" - "regexp" "strings" "testing" @@ -240,14 +239,16 @@ func TestGithubClient_PaginatesComments(t *testing.T) { return } - re := regexp.MustCompile(`(?i)^\s*(query|mutation)\b`) - matches := re.FindStringSubmatch(gqlRequest.Query) - if len(matches) < 2 { + operationType := "" + if strings.HasPrefix(strings.TrimSpace(gqlRequest.Query), "query") { + operationType = "query" + } else if strings.HasPrefix(strings.TrimSpace(gqlRequest.Query), "mutation") { + operationType = "mutation" + } else { t.Errorf("unexpected query: %q", gqlRequest.Query) http.Error(w, "server error", http.StatusInternalServerError) return } - operationType := strings.ToLower(matches[1]) switch operationType { case "mutation": @@ -369,15 +370,17 @@ func TestGithubClient_HideOldComments(t *testing.T) { return } - re := regexp.MustCompile(`(?i)^\s*(query|mutation)\b`) - matches := re.FindStringSubmatch(gqlRequest.Query) - if len(matches) < 2 { + operationType := "" + if strings.HasPrefix(strings.TrimSpace(gqlRequest.Query), "query") { + operationType = "query" + } else if strings.HasPrefix(strings.TrimSpace(gqlRequest.Query), "mutation") { + operationType = "mutation" + } else { t.Errorf("unexpected query: %q", gqlRequest.Query) http.Error(w, "server error", http.StatusInternalServerError) return } - operationType := strings.ToLower(matches[1]) switch operationType { case "mutation": gotMinimizeCalls = append(gotMinimizeCalls, gqlRequest) From 4fbdf70bea306174afdeb812f67f51af0466b1de Mon Sep 17 00:00:00 2001 From: oleg-glushak Date: Thu, 16 Jan 2025 17:11:01 +0100 Subject: [PATCH 3/8] fix: Avoid performance degradation with Github and --hide-prev-plan-comments enabled Signed-off-by: oleg-glushak --- server/events/vcs/github_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/events/vcs/github_client.go b/server/events/vcs/github_client.go index 3de3759e10..065a9004fa 100644 --- a/server/events/vcs/github_client.go +++ b/server/events/vcs/github_client.go @@ -362,7 +362,7 @@ func (g *GithubClient) HidePrevCommandComments(logger logging.SimpleLogging, rep } logger.Debug("Hiding commentID %s", commentID) if err := g.v4Client.Mutate(g.ctx, &m, input, nil); err != nil { - return errors.Wrapf(err, "minimize commentID %s", commentID) + return errors.Wrapf(err, "minimize comment %s", commentID) } } From f12edf68a5f8ee22a39e2529c705c9ea06c796f0 Mon Sep 17 00:00:00 2001 From: oleg-glushak Date: Thu, 16 Jan 2025 17:14:35 +0100 Subject: [PATCH 4/8] chore: clean-up Signed-off-by: oleg-glushak --- server/events/vcs/github_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/events/vcs/github_client.go b/server/events/vcs/github_client.go index 065a9004fa..f103f8a4d6 100644 --- a/server/events/vcs/github_client.go +++ b/server/events/vcs/github_client.go @@ -360,7 +360,7 @@ func (g *GithubClient) HidePrevCommandComments(logger logging.SimpleLogging, rep Classifier: githubv4.ReportedContentClassifiersOutdated, SubjectID: commentID, } - logger.Debug("Hiding commentID %s", commentID) + logger.Debug("Hiding comment %s", commentID) if err := g.v4Client.Mutate(g.ctx, &m, input, nil); err != nil { return errors.Wrapf(err, "minimize comment %s", commentID) } From 7290eef581b7a533c9a1dac3c9a337970f33fa33 Mon Sep 17 00:00:00 2001 From: oleg-glushak Date: Thu, 16 Jan 2025 17:53:40 +0100 Subject: [PATCH 5/8] chore: clean-up Signed-off-by: oleg-glushak --- server/events/vcs/github_client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/events/vcs/github_client.go b/server/events/vcs/github_client.go index f103f8a4d6..6068dc3016 100644 --- a/server/events/vcs/github_client.go +++ b/server/events/vcs/github_client.go @@ -307,9 +307,9 @@ func (g *GithubClient) HidePrevCommandComments(logger logging.SimpleLogging, rep } for _, comment := range query.Repository.PullRequest.Comments.Nodes { - logger.Debug("Processing commentID %s, %s, %s", comment.Author.Login, comment.IsMinimized, comment.ID) + logger.Debug("Processing comment user: %s, commentID: %s", comment.Author.Login, comment.ID) if comment.IsMinimized { - logger.Debug("Skipping minimized commentID %s, %s, %s", comment.Author.Login, comment.IsMinimized, comment.ID) + logger.Debug("Skipping already minimized comment user: %s, commentID: %s", comment.Author.Login, comment.ID) continue } From 40508b761c22363c59bce707652156b83b60fa62 Mon Sep 17 00:00:00 2001 From: oleg-glushak Date: Thu, 16 Jan 2025 18:14:12 +0100 Subject: [PATCH 6/8] chore: clean-up Signed-off-by: oleg-glushak --- server/events/vcs/github_client_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/events/vcs/github_client_test.go b/server/events/vcs/github_client_test.go index 9d39b27661..330489d992 100644 --- a/server/events/vcs/github_client_test.go +++ b/server/events/vcs/github_client_test.go @@ -230,8 +230,6 @@ func TestGithubClient_PaginatesComments(t *testing.T) { gotMinimizeCalls := make([]graphQLCall, 0, 2) testServer := httptest.NewTLSServer( http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - t.Log(r.Method + " " + r.RequestURI) - var gqlRequest graphQLCall if err := json.NewDecoder(r.Body).Decode(&gqlRequest); err != nil { t.Errorf("parse body error: %v", err) From 6b0868fb98a29442cfeccbb2998380e55e612358 Mon Sep 17 00:00:00 2001 From: oleg-glushak Date: Fri, 17 Jan 2025 14:57:37 +0100 Subject: [PATCH 7/8] chore: ignore linting warning Signed-off-by: oleg-glushak --- server/events/vcs/github_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/events/vcs/github_client.go b/server/events/vcs/github_client.go index 6068dc3016..4c993f52f0 100644 --- a/server/events/vcs/github_client.go +++ b/server/events/vcs/github_client.go @@ -295,7 +295,7 @@ func (g *GithubClient) HidePrevCommandComments(logger logging.SimpleLogging, rep commentsQueryVariables := map[string]interface{}{ "owner": githubv4.String(repo.Owner), "name": githubv4.String(repo.Name), - "number": githubv4.Int(pullNum), + "number": githubv4.Int(pullNum), //nolint:gosec "pageSize": githubv4.Int(100), "after": (*githubv4.String)(nil), } From b02777842aab1b86261dcdba906d02e60f2cdc84 Mon Sep 17 00:00:00 2001 From: oleg-glushak Date: Sun, 26 Jan 2025 15:09:27 +0100 Subject: [PATCH 8/8] chore: Add more meaningful comment about potential integer overflow Signed-off-by: oleg-glushak --- server/events/vcs/github_client.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/events/vcs/github_client.go b/server/events/vcs/github_client.go index 4ab88cebba..0b32ee5358 100644 --- a/server/events/vcs/github_client.go +++ b/server/events/vcs/github_client.go @@ -303,9 +303,10 @@ func (g *GithubClient) HidePrevCommandComments(logger logging.SimpleLogging, rep ) commentsQueryVariables := map[string]interface{}{ - "owner": githubv4.String(repo.Owner), - "name": githubv4.String(repo.Name), - "number": githubv4.Int(pullNum), //nolint:gosec + "owner": githubv4.String(repo.Owner), + "name": githubv4.String(repo.Name), + // TODO: This is a potential integer overflow. We should fix this. + "number": githubv4.Int(pullNum), // #nosec G115: integer overflow conversion int -> int32 "pageSize": githubv4.Int(100), "after": (*githubv4.String)(nil), }