From 3241e6a73c2d20650108d1b70bde8d45444fee0c Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Tue, 29 Aug 2023 20:08:32 +0530 Subject: [PATCH 01/27] add: issue url check open or closed --- tools/checkcomments/checkcomments.go | 29 ++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index f5a60dc98fa5..cd3c4629103e 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -16,6 +16,7 @@ package main import ( + "net/http" "regexp" "strings" @@ -49,8 +50,8 @@ func run(pass *analysis.Pass) (any, error) { continue } - if !todoRE.MatchString(c.Text) { - pass.Reportf(c.Pos(), "invalid TODO comment") + if !todoRE.MatchString(c.Text) && isIssueOpen(c.Text) { + pass.Reportf(c.Pos(), "invalid TODO comment and issue is still open") } } } @@ -59,3 +60,27 @@ func run(pass *analysis.Pass) (any, error) { return nil, nil } + +func isIssueOpen(todoText string) bool { + issueURL := getURL(todoText) + if issueURL == "" { + return false + } + resp, err := http.Get(issueURL) + if err != nil { + return false + } + defer resp.Body.Close() + + return resp.StatusCode == http.StatusOK +} + +func getURL(todoText string) string { + arrText := strings.Split(todoText, " ") + for _, text := range arrText { + if strings.Contains(text, "https://") { + return text + } + } + return "" +} From e324aaef7fcd4c7e224d09b18c2abf18df56a060 Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Fri, 1 Sep 2023 07:59:06 +0530 Subject: [PATCH 02/27] fix: lint check --- tools/checkcomments/checkcomments.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index cd3c4629103e..be37b24df765 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -67,10 +67,11 @@ func isIssueOpen(todoText string) bool { return false } resp, err := http.Get(issueURL) + if err != nil { return false } - defer resp.Body.Close() + defer resp.Body.Close() //nolint:errcheck // we are only reading it return resp.StatusCode == http.StatusOK } @@ -82,5 +83,6 @@ func getURL(todoText string) string { return text } } + return "" } From 40b39bc6b75783c87674a1db2d843d6bda9bf1a8 Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Fri, 1 Sep 2023 08:01:48 +0530 Subject: [PATCH 03/27] fix: lint check --- tools/checkcomments/checkcomments.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index be37b24df765..c89e3f8aa386 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -67,7 +67,6 @@ func isIssueOpen(todoText string) bool { return false } resp, err := http.Get(issueURL) - if err != nil { return false } From 628fb00681cc41a8d4b50c204efd84f993873bef Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Fri, 1 Sep 2023 18:32:09 +0530 Subject: [PATCH 04/27] fix: added comments above methods --- tools/checkcomments/checkcomments.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index c89e3f8aa386..5d1a54bdafb8 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -61,12 +61,14 @@ func run(pass *analysis.Pass) (any, error) { return nil, nil } +// isIssueopen check the issue open or closed func isIssueOpen(todoText string) bool { issueURL := getURL(todoText) if issueURL == "" { return false } resp, err := http.Get(issueURL) + if err != nil { return false } @@ -75,6 +77,7 @@ func isIssueOpen(todoText string) bool { return resp.StatusCode == http.StatusOK } +// extracting url from TODO comment if present func getURL(todoText string) string { arrText := strings.Split(todoText, " ") for _, text := range arrText { From 891f15ddcd515faa63886fb351d3d20f9631ba62 Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Mon, 25 Sep 2023 20:36:07 +0530 Subject: [PATCH 05/27] add: chjeck open issue check initial draft --- tools/checkcomments/checkcomments.go | 50 +++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index 5d1a54bdafb8..1ba7d04816a5 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -16,10 +16,16 @@ package main import ( - "net/http" + "context" + "fmt" + "log" + "os" "regexp" + "strconv" "strings" + "github.com/google/go-github/github" + "golang.org/x/oauth2" "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis/singlechecker" ) @@ -67,14 +73,34 @@ func isIssueOpen(todoText string) bool { if issueURL == "" { return false } - resp, err := http.Get(issueURL) + token := os.Getenv("GITHUB_TOKEN") + if token == "" { + log.Fatalf("%s is not set.", token) + return false + } + + ctx := context.Background() + httpClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource( + &oauth2.Token{AccessToken: token}, + )) + + client := github.NewClient(httpClient) + + owner := "owner" + repo := "https://github.com/FerretDB/FerretDB" + issueNumber, err := getIssueNumber(issueURL) + if err != nil { + log.Fatalf("error in getting issue number: %s", err.Error()) + return false + } + issue, _, err := client.Issues.Get(ctx, owner, repo, issueNumber) if err != nil { + log.Fatalf("error in getting status of issue: %s for issue: %s", err.Error(), issueURL) return false } - defer resp.Body.Close() //nolint:errcheck // we are only reading it - return resp.StatusCode == http.StatusOK + return issue.GetState() == "open" } // extracting url from TODO comment if present @@ -88,3 +114,19 @@ func getURL(todoText string) string { return "" } + +// get the issue number from issue url +func getIssueNumber(todoText string) (int, error) { + pattern := `\/issues\/(\d+)` + re := regexp.MustCompile(pattern) + match := re.FindStringSubmatch(todoText) + if len(match) >= 2 { + issueNumberStr := match[1] + issueNumber, err := strconv.Atoi(issueNumberStr) + if err != nil { + return 0, err + } + return issueNumber, nil + } + return 0, fmt.Errorf("invalid issue url: %s", todoText) +} From 46bccfbac635956b7bd02bda185f11956ad87c86 Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Mon, 25 Sep 2023 21:36:12 +0530 Subject: [PATCH 06/27] remove: env get token --- tools/checkcomments/checkcomments.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index 1ba7d04816a5..dcbf836d34a3 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -19,7 +19,6 @@ import ( "context" "fmt" "log" - "os" "regexp" "strconv" "strings" @@ -74,12 +73,7 @@ func isIssueOpen(todoText string) bool { return false } - token := os.Getenv("GITHUB_TOKEN") - if token == "" { - log.Fatalf("%s is not set.", token) - return false - } - + token := "" ctx := context.Background() httpClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource( &oauth2.Token{AccessToken: token}, From 634bd9c8729d055d1090d4a5c7a4970f61716859 Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Wed, 27 Sep 2023 13:36:05 +0530 Subject: [PATCH 07/27] fix: create a api url --- tools/checkcomments/checkcomments.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index dcbf836d34a3..618ce2f77f74 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -102,7 +102,12 @@ func getURL(todoText string) string { arrText := strings.Split(todoText, " ") for _, text := range arrText { if strings.Contains(text, "https://") { - return text + parts := strings.Split(text, "/") + if len(parts) >= 5 { + issueNumber := parts[6] + apiURL := fmt.Sprintf("https://api.github.com/repos/FerretDB/FerretDB/issues/%s", issueNumber) + return apiURL + } } } From ba11db945f2240c784b9357e06b0dafaa308429b Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Thu, 28 Sep 2023 01:01:27 +0530 Subject: [PATCH 08/27] fix: ran task init fmt --- tools/checkcomments/checkcomments.go | 10 +++++++--- tools/checkcomments/testdata/testdata.go | 2 ++ tools/go.mod | 1 + tools/go.sum | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index 618ce2f77f74..0c9a47720ecf 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -66,7 +66,7 @@ func run(pass *analysis.Pass) (any, error) { return nil, nil } -// isIssueopen check the issue open or closed +// isIssueopen check the issue open or closed. func isIssueOpen(todoText string) bool { issueURL := getURL(todoText) if issueURL == "" { @@ -97,7 +97,7 @@ func isIssueOpen(todoText string) bool { return issue.GetState() == "open" } -// extracting url from TODO comment if present +// extracting url from TODO comment if present. func getURL(todoText string) string { arrText := strings.Split(todoText, " ") for _, text := range arrText { @@ -106,6 +106,7 @@ func getURL(todoText string) string { if len(parts) >= 5 { issueNumber := parts[6] apiURL := fmt.Sprintf("https://api.github.com/repos/FerretDB/FerretDB/issues/%s", issueNumber) + return apiURL } } @@ -114,18 +115,21 @@ func getURL(todoText string) string { return "" } -// get the issue number from issue url +// get the issue number from issue url. func getIssueNumber(todoText string) (int, error) { pattern := `\/issues\/(\d+)` re := regexp.MustCompile(pattern) match := re.FindStringSubmatch(todoText) + if len(match) >= 2 { issueNumberStr := match[1] issueNumber, err := strconv.Atoi(issueNumberStr) if err != nil { return 0, err } + return issueNumber, nil } + return 0, fmt.Errorf("invalid issue url: %s", todoText) } diff --git a/tools/checkcomments/testdata/testdata.go b/tools/checkcomments/testdata/testdata.go index 11745d6de2dc..1646e778aefa 100644 --- a/tools/checkcomments/testdata/testdata.go +++ b/tools/checkcomments/testdata/testdata.go @@ -16,6 +16,8 @@ package testdata func testCorrect() { + // below issue url will be changed to https://api.github.com/repos/FerretDB/FerretDB/issues/2733 + // and checked issue open or closed. // TODO https://github.com/FerretDB/FerretDB/issues/2733 } diff --git a/tools/go.mod b/tools/go.mod index 4635dde757df..d87acf64f259 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -5,6 +5,7 @@ go 1.21.1 require ( github.com/BurntSushi/go-sumtype v0.0.0-20221020234012-480526a59796 github.com/go-task/task/v3 v3.29.1 + github.com/google/go-github v17.0.0+incompatible github.com/google/go-github/v41 v41.0.0 github.com/goreleaser/nfpm/v2 v2.32.0 github.com/quasilyte/go-consistent v0.6.0 diff --git a/tools/go.sum b/tools/go.sum index 205e6cc621f0..54d41d0555ea 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -102,6 +102,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= +github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-github/v41 v41.0.0 h1:HseJrM2JFf2vfiZJ8anY2hqBjdfY1Vlj/K27ueww4gg= github.com/google/go-github/v41 v41.0.0/go.mod h1:XgmCA5H323A9rtgExdTcnDkcqp6S30AVACCBDOonIxg= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= From d8fc96176f4b67a1f94f608815180152496a3448 Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Thu, 28 Sep 2023 01:57:48 +0530 Subject: [PATCH 09/27] fix: ran task init fmt --- tools/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/go.mod b/tools/go.mod index d87acf64f259..1290be546598 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -4,7 +4,7 @@ go 1.21.1 require ( github.com/BurntSushi/go-sumtype v0.0.0-20221020234012-480526a59796 - github.com/go-task/task/v3 v3.29.1 + github.com/go-task/task/v3 v3.30.1 github.com/google/go-github v17.0.0+incompatible github.com/google/go-github/v41 v41.0.0 github.com/goreleaser/nfpm/v2 v2.32.0 From aef36fea71c3e618a56057a73170e6f7762194eb Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Thu, 28 Sep 2023 01:59:12 +0530 Subject: [PATCH 10/27] fix: resolve conflicts --- tools/go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/go.mod b/tools/go.mod index 1290be546598..b6c930e37700 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -5,7 +5,6 @@ go 1.21.1 require ( github.com/BurntSushi/go-sumtype v0.0.0-20221020234012-480526a59796 github.com/go-task/task/v3 v3.30.1 - github.com/google/go-github v17.0.0+incompatible github.com/google/go-github/v41 v41.0.0 github.com/goreleaser/nfpm/v2 v2.32.0 github.com/quasilyte/go-consistent v0.6.0 From 13098b0a4f6da38bfe5674a5a37911c90cbc785d Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Fri, 29 Sep 2023 12:18:23 +0530 Subject: [PATCH 11/27] sdd: test for URL check --- tools/checkcomments/testdata/testdata.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/checkcomments/testdata/testdata.go b/tools/checkcomments/testdata/testdata.go index 1646e778aefa..b3c49a2cb59d 100644 --- a/tools/checkcomments/testdata/testdata.go +++ b/tools/checkcomments/testdata/testdata.go @@ -16,15 +16,21 @@ package testdata func testCorrect() { - // below issue url will be changed to https://api.github.com/repos/FerretDB/FerretDB/issues/2733 - // and checked issue open or closed. - // TODO https://github.com/FerretDB/FerretDB/issues/2733 + // TODO https://github.com/FerretDB/FerretDB/issues/2733 // want "valid TODO comment" } func testCorrectForNow() { - // TODO no URL + // TODO no URL // want "invalid TODO comment because we need https" } func testIncorrect() { // TODO: https://github.com/FerretDB/FerretDB/issues/2733 // want "invalid TODO comment" } + +func testCorrectButClosedIssue() { + // TODO: https://github.com/FerretDB/FerretDB/issues/3341 // want "invalid TODO comment because closed issue" +} + +func testIncorrectCorrect() { + // TODO: https://github.com/FerretDB/FerretDB/issues/2733 // want "valid TODO comment open issue" +} From 7f3253006b70d92327451d6d07a0fc1f628d328e Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Fri, 29 Sep 2023 12:23:14 +0530 Subject: [PATCH 12/27] add: test for URL check --- tools/checkcomments/testdata/testdata.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/checkcomments/testdata/testdata.go b/tools/checkcomments/testdata/testdata.go index b3c49a2cb59d..d3b22e457529 100644 --- a/tools/checkcomments/testdata/testdata.go +++ b/tools/checkcomments/testdata/testdata.go @@ -16,21 +16,17 @@ package testdata func testCorrect() { - // TODO https://github.com/FerretDB/FerretDB/issues/2733 // want "valid TODO comment" + // TODO https://github.com/FerretDB/FerretDB/issues/2733 } func testCorrectForNow() { - // TODO no URL // want "invalid TODO comment because we need https" + // TODO no URL } func testIncorrect() { // TODO: https://github.com/FerretDB/FerretDB/issues/2733 // want "invalid TODO comment" } -func testCorrectButClosedIssue() { - // TODO: https://github.com/FerretDB/FerretDB/issues/3341 // want "invalid TODO comment because closed issue" -} - -func testIncorrectCorrect() { - // TODO: https://github.com/FerretDB/FerretDB/issues/2733 // want "valid TODO comment open issue" +func testCorrectTodoButClosedIssue() { + // TODO https://github.com/FerretDB/FerretDB/issues/3341 // want "invalid TODO comment" } From f982de6ffdc63114218904c932c95d4eb0402ea1 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Wed, 4 Oct 2023 08:56:15 +0400 Subject: [PATCH 13/27] Use newer version --- tools/checkcomments/checkcomments.go | 2 +- tools/go.sum | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index 0c9a47720ecf..a0ba5859197a 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -23,7 +23,7 @@ import ( "strconv" "strings" - "github.com/google/go-github/github" + "github.com/google/go-github/v41/github" "golang.org/x/oauth2" "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis/singlechecker" diff --git a/tools/go.sum b/tools/go.sum index 92c60523329a..2ac1b17d090e 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -104,8 +104,6 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= -github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-github/v41 v41.0.0 h1:HseJrM2JFf2vfiZJ8anY2hqBjdfY1Vlj/K27ueww4gg= github.com/google/go-github/v41 v41.0.0/go.mod h1:XgmCA5H323A9rtgExdTcnDkcqp6S30AVACCBDOonIxg= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= From 368e023d84ccbdb48168de9e9f43f083efe8a761 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Wed, 4 Oct 2023 08:56:26 +0400 Subject: [PATCH 14/27] Update tests --- tools/checkcomments/testdata/testdata.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/checkcomments/testdata/testdata.go b/tools/checkcomments/testdata/testdata.go index d3b22e457529..e4af60dc5d3f 100644 --- a/tools/checkcomments/testdata/testdata.go +++ b/tools/checkcomments/testdata/testdata.go @@ -16,17 +16,21 @@ package testdata func testCorrect() { - // TODO https://github.com/FerretDB/FerretDB/issues/2733 + // TODO https://github.com/FerretDB/FerretDB/issues/3413 } func testCorrectForNow() { // TODO no URL } -func testIncorrect() { - // TODO: https://github.com/FerretDB/FerretDB/issues/2733 // want "invalid TODO comment" +func testIncorrectFormat() { + // TODO: https://github.com/FerretDB/FerretDB/issues/3413 // want "invalid TODO: incorrect format" } -func testCorrectTodoButClosedIssue() { - // TODO https://github.com/FerretDB/FerretDB/issues/3341 // want "invalid TODO comment" +func testIncorrectClosed() { + // TODO https://github.com/FerretDB/FerretDB/issues/1 // want "invalid TODO: linked issue is closed" +} + +func testIncorrectFormatClosed() { + // TODO: https://github.com/FerretDB/FerretDB/issues/1 // want "invalid TODO: incorrect format" } From bfb897ef05f4939101e15768db7f1929d1108f51 Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Wed, 4 Oct 2023 14:35:31 +0530 Subject: [PATCH 15/27] add: test case passed --- tools/checkcomments/checkcomments.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index a0ba5859197a..35527f038bd3 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -55,8 +55,13 @@ func run(pass *analysis.Pass) (any, error) { continue } - if !todoRE.MatchString(c.Text) && isIssueOpen(c.Text) { - pass.Reportf(c.Pos(), "invalid TODO comment and issue is still open") + if !todoRE.MatchString(c.Text) { + pass.Reportf(c.Pos(), "invalid TODO: incorrect format") + continue + } + if !isIssueOpen(c.Text) { + pass.Reportf(c.Pos(), "invalid TODO: linked issue is closed") + continue } } } @@ -82,7 +87,7 @@ func isIssueOpen(todoText string) bool { client := github.NewClient(httpClient) owner := "owner" - repo := "https://github.com/FerretDB/FerretDB" + repo := "repos" issueNumber, err := getIssueNumber(issueURL) if err != nil { log.Fatalf("error in getting issue number: %s", err.Error()) From ba7f89e055af757b5bbdf79ba6f7cbbeefa49a16 Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Wed, 4 Oct 2023 17:04:04 +0530 Subject: [PATCH 16/27] remove: redundant code --- tools/checkcomments/checkcomments.go | 29 +++------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index 35527f038bd3..38836224b31a 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -73,11 +73,6 @@ func run(pass *analysis.Pass) (any, error) { // isIssueopen check the issue open or closed. func isIssueOpen(todoText string) bool { - issueURL := getURL(todoText) - if issueURL == "" { - return false - } - token := "" ctx := context.Background() httpClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource( @@ -86,9 +81,9 @@ func isIssueOpen(todoText string) bool { client := github.NewClient(httpClient) - owner := "owner" - repo := "repos" - issueNumber, err := getIssueNumber(issueURL) + owner := "FerretDB" + repo := "FerretDB" + issueNumber, err := getIssueNumber(todoText) if err != nil { log.Fatalf("error in getting issue number: %s", err.Error()) return false @@ -102,24 +97,6 @@ func isIssueOpen(todoText string) bool { return issue.GetState() == "open" } -// extracting url from TODO comment if present. -func getURL(todoText string) string { - arrText := strings.Split(todoText, " ") - for _, text := range arrText { - if strings.Contains(text, "https://") { - parts := strings.Split(text, "/") - if len(parts) >= 5 { - issueNumber := parts[6] - apiURL := fmt.Sprintf("https://api.github.com/repos/FerretDB/FerretDB/issues/%s", issueNumber) - - return apiURL - } - } - } - - return "" -} - // get the issue number from issue url. func getIssueNumber(todoText string) (int, error) { pattern := `\/issues\/(\d+)` From 210b5508d30cde93317aca667b7e94d001144503 Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Wed, 4 Oct 2023 17:08:37 +0530 Subject: [PATCH 17/27] fix: lint issues --- tools/checkcomments/checkcomments.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index 38836224b31a..64fb5b6e53d1 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -59,6 +59,7 @@ func run(pass *analysis.Pass) (any, error) { pass.Reportf(c.Pos(), "invalid TODO: incorrect format") continue } + if !isIssueOpen(c.Text) { pass.Reportf(c.Pos(), "invalid TODO: linked issue is closed") continue @@ -78,7 +79,6 @@ func isIssueOpen(todoText string) bool { httpClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource( &oauth2.Token{AccessToken: token}, )) - client := github.NewClient(httpClient) owner := "FerretDB" @@ -88,9 +88,10 @@ func isIssueOpen(todoText string) bool { log.Fatalf("error in getting issue number: %s", err.Error()) return false } + issue, _, err := client.Issues.Get(ctx, owner, repo, issueNumber) if err != nil { - log.Fatalf("error in getting status of issue: %s for issue: %s", err.Error(), issueURL) + log.Fatalf("error in getting status of issue: %s for issue number: %d", err.Error(), issueNumber) return false } From 9b0eb8fd9dec0738fb8bbdbc3250dcb4602f4fcb Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Fri, 6 Oct 2023 09:00:07 +0400 Subject: [PATCH 18/27] Use `GITHUB_TOKEN` only if available --- tools/checkcomments/checkcomments.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index 64fb5b6e53d1..650aa816809b 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -19,6 +19,7 @@ import ( "context" "fmt" "log" + "os" "regexp" "strconv" "strings" @@ -74,12 +75,15 @@ func run(pass *analysis.Pass) (any, error) { // isIssueopen check the issue open or closed. func isIssueOpen(todoText string) bool { - token := "" + var src oauth2.TokenSource + if token := os.Getenv("GITHUB_TOKEN"); token != "" { + src = oauth2.StaticTokenSource( + &oauth2.Token{AccessToken: token}, + ) + } + ctx := context.Background() - httpClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource( - &oauth2.Token{AccessToken: token}, - )) - client := github.NewClient(httpClient) + client := github.NewClient(oauth2.NewClient(ctx, src)) owner := "FerretDB" repo := "FerretDB" From aebcd95f02108bb7f42e3b7eabd527ad7fd6ced4 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Fri, 6 Oct 2023 09:06:59 +0400 Subject: [PATCH 19/27] Fix token permissions --- .github/workflows/go.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7d70272697db..adc93e406c88 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -266,6 +266,9 @@ jobs: if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready') + permissions: + issues: read + steps: - name: Setup permissions monitoring uses: GitHubSecurityLab/actions-permissions/monitor@v1 From 3eee57efe2485c32ad8041b1961f3613f071a841 Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Fri, 6 Oct 2023 17:17:01 +0530 Subject: [PATCH 20/27] removed: redundant code --- tools/checkcomments/checkcomments.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index 650aa816809b..db439e7a6a6d 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -104,9 +104,7 @@ func isIssueOpen(todoText string) bool { // get the issue number from issue url. func getIssueNumber(todoText string) (int, error) { - pattern := `\/issues\/(\d+)` - re := regexp.MustCompile(pattern) - match := re.FindStringSubmatch(todoText) + match := todoRE.FindStringSubmatch(todoText) if len(match) >= 2 { issueNumberStr := match[1] From 240a938d3e569d0abb5fd5a096426badcc0199ee Mon Sep 17 00:00:00 2001 From: KrishnaSindhur Date: Sat, 7 Oct 2023 16:10:26 +0530 Subject: [PATCH 21/27] removed: removed continue --- tools/checkcomments/checkcomments.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index db439e7a6a6d..79ead63d5bb0 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -58,12 +58,8 @@ func run(pass *analysis.Pass) (any, error) { if !todoRE.MatchString(c.Text) { pass.Reportf(c.Pos(), "invalid TODO: incorrect format") - continue - } - - if !isIssueOpen(c.Text) { + } else if !isIssueOpen(c.Text) { pass.Reportf(c.Pos(), "invalid TODO: linked issue is closed") - continue } } } From 06cad22db49acdb3927690a168a04f8cebb444c9 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Tue, 17 Oct 2023 09:15:59 +0400 Subject: [PATCH 22/27] Use shared package for GH client --- tools/checkcomments/checkcomments.go | 20 +++++++------------- tools/go.mod | 2 ++ tools/go.sum | 4 ++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index 79ead63d5bb0..0f6b40e0bcc3 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -24,8 +24,7 @@ import ( "strconv" "strings" - "github.com/google/go-github/v41/github" - "golang.org/x/oauth2" + "github.com/FerretDB/gh" "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis/singlechecker" ) @@ -45,6 +44,11 @@ func main() { // run analyses TODO comments. func run(pass *analysis.Pass) (any, error) { + client, err := gh.NewRESTClient(os.Getenv("GITHUB_TOKEN"), nil) + if err != nil { + log.Fatal(err) + } + for _, f := range pass.Files { for _, cg := range f.Comments { for _, c := range cg.List { @@ -71,16 +75,6 @@ func run(pass *analysis.Pass) (any, error) { // isIssueopen check the issue open or closed. func isIssueOpen(todoText string) bool { - var src oauth2.TokenSource - if token := os.Getenv("GITHUB_TOKEN"); token != "" { - src = oauth2.StaticTokenSource( - &oauth2.Token{AccessToken: token}, - ) - } - - ctx := context.Background() - client := github.NewClient(oauth2.NewClient(ctx, src)) - owner := "FerretDB" repo := "FerretDB" issueNumber, err := getIssueNumber(todoText) @@ -89,7 +83,7 @@ func isIssueOpen(todoText string) bool { return false } - issue, _, err := client.Issues.Get(ctx, owner, repo, issueNumber) + issue, _, err := client.Issues.Get(context.TODO(), owner, repo, issueNumber) if err != nil { log.Fatalf("error in getting status of issue: %s for issue number: %d", err.Error(), issueNumber) return false diff --git a/tools/go.mod b/tools/go.mod index 354763a86c7e..89a84867cb49 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -8,6 +8,7 @@ replace github.com/goreleaser/nfpm/v2 => github.com/AlekSi/nfpm/v2 v2.33.2-0.202 require ( github.com/BurntSushi/go-sumtype v0.0.0-20221020234012-480526a59796 + github.com/FerretDB/gh v0.0.0-20231017052058-110a65393a76 github.com/go-task/task/v3 v3.31.0 github.com/google/go-github/v41 v41.0.0 github.com/goreleaser/nfpm/v2 v2.33.1 @@ -55,6 +56,7 @@ require ( github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.5.9 // indirect + github.com/google/go-github/v56 v56.0.0 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/licensecheck v0.3.1 // indirect github.com/google/rpmpack v0.5.0 // indirect diff --git a/tools/go.sum b/tools/go.sum index 08afcc823c4d..b63df970b7ed 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -8,6 +8,8 @@ github.com/BurntSushi/go-sumtype v0.0.0-20221020234012-480526a59796 h1:LkyKOzdmN github.com/BurntSushi/go-sumtype v0.0.0-20221020234012-480526a59796/go.mod h1:V4gPjiBeLsr++PoZh39o+6fZ++EbypxSUmMplhmBNRY= github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= +github.com/FerretDB/gh v0.0.0-20231017052058-110a65393a76 h1:Zc+NaElj5N+2sJ+QonY1HD3aX6pwGX41klDZXhbCmkM= +github.com/FerretDB/gh v0.0.0-20231017052058-110a65393a76/go.mod h1:IZaVgs+IhUzLBYd2lfJjS5U2OnwuuvvLvypP1zHftSY= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= @@ -112,6 +114,8 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github/v41 v41.0.0 h1:HseJrM2JFf2vfiZJ8anY2hqBjdfY1Vlj/K27ueww4gg= github.com/google/go-github/v41 v41.0.0/go.mod h1:XgmCA5H323A9rtgExdTcnDkcqp6S30AVACCBDOonIxg= +github.com/google/go-github/v56 v56.0.0 h1:TysL7dMa/r7wsQi44BjqlwaHvwlFlqkK8CtBWCX3gb4= +github.com/google/go-github/v56 v56.0.0/go.mod h1:D8cdcX98YWJvi7TLo7zM4/h8ZTx6u6fwGEkCdisopo0= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/go-replayers/httpreplay v1.0.0 h1:8SmT8fUYM4nueF+UnXIX8LJxNTb1vpPuknXz+yTWzL4= From 093411a05925080cf1d7ec72d655546ffa09f02a Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Tue, 17 Oct 2023 10:20:53 +0400 Subject: [PATCH 23/27] Update docs --- CONTRIBUTING.md | 59 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4c94a278f1ee..c7cbc3e0a691 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -78,6 +78,45 @@ you can reset the environment with `task env-reset`. To build a production release binaries, run `task build-production`. The results will be saved `tmp/bin`. +### Setting a GITHUB_TOKEN + +Some of our development tools require access to public information on GitHub +at a rate higher than allowed for unauthenticated requests. +Those tools will report a problem in this case. +It could be solved by creating a new classic or fine-graned personal access token +[there](https://github.com/settings/tokens). +No scopes are needed for classic tokens, not even `public_repo`. +For fine-graned tokens, only read-only access to public repositories is needed without any additional permissions. +After generating a token, set the `GITHUB_TOKEN` environment variable: + +```sh +export GITHUB_TOKEN=ghp_XXX +``` + +or + +```sh +export GITHUB_TOKEN=github_pat_XXX +``` + +## Reporting a bug + +We appreciate reporting a bug to us. +To help us accurately identify the cause, we encourage you to include a pull request with test script. +Please write the test script in [build/legacy-mongo-shell/test.js](build/legacy-mongo-shell/test.js). +You can find an overview of the available assertions [here](build/legacy-mongo-shell/README.md). +Use these assertions to validate your test's assumptions and invariants. +You can also find an example of how to prepare a test script in +[build/legacy-mongo-shell/test.example.js](build/legacy-mongo-shell/test.example.js). + +With `task` installed (see above), you may test your script using following steps: + +1. Start the development environment with `task env-up`. +2. Start FerretDB with `task run`. +3. Run the test script with `task testjs`. + +Please create a pull request and include the link of the pull request in the bug issue. + ## Contributing code ### Commands for contributing code @@ -334,26 +373,6 @@ Before submitting a pull request, please make sure that: If you have interest in becoming or are a long-term contributor, please read [PROCESS.md](.github/PROCESS.md) for more details. -## Reporting a bug - -We appreciate reporting a bug to us. -To help us accurately identify the cause, we encourage -you to include a pull request with test script. -Please write the test script in -[build/legacy-mongo-shell/test.js](build/legacy-mongo-shell/test.js). -You can find an overview of the available assertions [here](build/legacy-mongo-shell/README.md). -Use these assertions to validate your test's assumptions and invariants. -You can also find an example of how to prepare a test script in -[build/legacy-mongo-shell/test.example.js](build/legacy-mongo-shell/test.example.js). - -Test your script using following steps: - -1. Start the development environment with `task env-up`. -2. Start FerretDB with `task run`. -3. Run the test script with `task testjs`. - -Please create a pull request and include the link of the pull request in the bug issue. - ## Contributing documentation ### Commands for contributing documentation From dea56c5ff26211fd0fd49f656e28f2d0175c23f7 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Tue, 17 Oct 2023 10:32:18 +0400 Subject: [PATCH 24/27] Simplify --- tools/checkcomments/checkcomments.go | 81 ++++++++++++++-------------- tools/cleantool/cleantool.go | 2 +- tools/go.mod | 3 +- tools/go.sum | 6 --- 4 files changed, 43 insertions(+), 49 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index 0f6b40e0bcc3..d7408a512df0 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -17,7 +17,7 @@ package main import ( "context" - "fmt" + "errors" "log" "os" "regexp" @@ -25,6 +25,7 @@ import ( "strings" "github.com/FerretDB/gh" + "github.com/google/go-github/v56/github" "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis/singlechecker" ) @@ -44,11 +45,15 @@ func main() { // run analyses TODO comments. func run(pass *analysis.Pass) (any, error) { - client, err := gh.NewRESTClient(os.Getenv("GITHUB_TOKEN"), nil) + token := os.Getenv("GITHUB_TOKEN") + + client, err := gh.NewRESTClient(token, nil) if err != nil { log.Fatal(err) } + issues := make(map[int]bool) + for _, f := range pass.Files { for _, cg := range f.Comments { for _, c := range cg.List { @@ -60,9 +65,41 @@ func run(pass *analysis.Pass) (any, error) { continue } - if !todoRE.MatchString(c.Text) { + match := todoRE.FindStringSubmatch(c.Text) + + if match == nil { pass.Reportf(c.Pos(), "invalid TODO: incorrect format") - } else if !isIssueOpen(c.Text) { + continue + } + + n, err := strconv.Atoi(match[1]) + if err != nil { + log.Fatal(err) + } + + open, ok := issues[n] + if !ok { + issue, _, err := client.Issues.Get(context.TODO(), "FerretDB", "FerretDB", n) + if err != nil { + if errors.As(err, new(*github.RateLimitError)) && token == "" { + log.Printf( + "%[1]T %[1]s\n%[2]s %[3]s", + err, + "Please set a GITHUB_TOKEN as described at", + "https://github.com/FerretDB/FerretDB/blob/main/CONTRIBUTING.md#setting-a-github_token", + ) + + return nil, nil + } + + log.Fatalf("%[1]T %[1]s", err) + } + + open = issue.GetState() == "open" + issues[n] = open + } + + if !open { pass.Reportf(c.Pos(), "invalid TODO: linked issue is closed") } } @@ -72,39 +109,3 @@ func run(pass *analysis.Pass) (any, error) { return nil, nil } - -// isIssueopen check the issue open or closed. -func isIssueOpen(todoText string) bool { - owner := "FerretDB" - repo := "FerretDB" - issueNumber, err := getIssueNumber(todoText) - if err != nil { - log.Fatalf("error in getting issue number: %s", err.Error()) - return false - } - - issue, _, err := client.Issues.Get(context.TODO(), owner, repo, issueNumber) - if err != nil { - log.Fatalf("error in getting status of issue: %s for issue number: %d", err.Error(), issueNumber) - return false - } - - return issue.GetState() == "open" -} - -// get the issue number from issue url. -func getIssueNumber(todoText string) (int, error) { - match := todoRE.FindStringSubmatch(todoText) - - if len(match) >= 2 { - issueNumberStr := match[1] - issueNumber, err := strconv.Atoi(issueNumberStr) - if err != nil { - return 0, err - } - - return issueNumber, nil - } - - return 0, fmt.Errorf("invalid issue url: %s", todoText) -} diff --git a/tools/cleantool/cleantool.go b/tools/cleantool/cleantool.go index 7242c8b14e8b..0c79031d1142 100644 --- a/tools/cleantool/cleantool.go +++ b/tools/cleantool/cleantool.go @@ -22,7 +22,7 @@ import ( "strings" "time" - "github.com/google/go-github/v41/github" + "github.com/google/go-github/v56/github" "golang.org/x/oauth2" ) diff --git a/tools/go.mod b/tools/go.mod index 89a84867cb49..53cb1ed7050e 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -10,7 +10,7 @@ require ( github.com/BurntSushi/go-sumtype v0.0.0-20221020234012-480526a59796 github.com/FerretDB/gh v0.0.0-20231017052058-110a65393a76 github.com/go-task/task/v3 v3.31.0 - github.com/google/go-github/v41 v41.0.0 + github.com/google/go-github/v56 v56.0.0 github.com/goreleaser/nfpm/v2 v2.33.1 github.com/quasilyte/go-consistent v0.6.0 github.com/stretchr/testify v1.8.4 @@ -56,7 +56,6 @@ require ( github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.5.9 // indirect - github.com/google/go-github/v56 v56.0.0 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/licensecheck v0.3.1 // indirect github.com/google/rpmpack v0.5.0 // indirect diff --git a/tools/go.sum b/tools/go.sum index b63df970b7ed..4a935fd89b43 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -101,7 +101,6 @@ github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJA github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= @@ -109,11 +108,8 @@ github.com/google/go-cmdtest v0.4.1-0.20220921163831-55ab3332a786 h1:rcv+Ippz6RA github.com/google/go-cmdtest v0.4.1-0.20220921163831-55ab3332a786/go.mod h1:apVn/GCasLZUVpAJ6oWAuyP7Ne7CEsQbTnc0plM3m+o= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-github/v41 v41.0.0 h1:HseJrM2JFf2vfiZJ8anY2hqBjdfY1Vlj/K27ueww4gg= -github.com/google/go-github/v41 v41.0.0/go.mod h1:XgmCA5H323A9rtgExdTcnDkcqp6S30AVACCBDOonIxg= github.com/google/go-github/v56 v56.0.0 h1:TysL7dMa/r7wsQi44BjqlwaHvwlFlqkK8CtBWCX3gb4= github.com/google/go-github/v56 v56.0.0/go.mod h1:D8cdcX98YWJvi7TLo7zM4/h8ZTx6u6fwGEkCdisopo0= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= @@ -272,7 +268,6 @@ gitlab.com/digitalxero/go-conventional-commit v1.0.7/go.mod h1:05Xc2BFsSyC5tKhK0 go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= @@ -297,7 +292,6 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY= golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0= golang.org/x/perf v0.0.0-20231006134539-cd219cffda85 h1:TTE4QVbOEiTwey734kAI878uRc0RyeTaJ87R8N/fMvw= From c13a4ceed85c4bc38d1b1e728f75f35fa1952626 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Tue, 17 Oct 2023 10:47:32 +0400 Subject: [PATCH 25/27] Make tests pass --- tools/checkcomments/checkcomments.go | 80 +++++++++++++++------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/tools/checkcomments/checkcomments.go b/tools/checkcomments/checkcomments.go index d7408a512df0..da26c7bc38d1 100644 --- a/tools/checkcomments/checkcomments.go +++ b/tools/checkcomments/checkcomments.go @@ -57,51 +57,59 @@ func run(pass *analysis.Pass) (any, error) { for _, f := range pass.Files { for _, cg := range f.Comments { for _, c := range cg.List { + line := c.Text + // the space between `//` and `TODO` is always added by `task fmt` - if strings.HasPrefix(c.Text, "// TODO") { - // skip comments without URLs for now - // TODO https://github.com/FerretDB/FerretDB/issues/2733 - if !strings.Contains(c.Text, "https://") { - continue - } + if !strings.HasPrefix(line, "// TODO") { + continue + } - match := todoRE.FindStringSubmatch(c.Text) + if f.Name.Name == "testdata" { + line, _, _ = strings.Cut(line, ` // want "`) + } - if match == nil { - pass.Reportf(c.Pos(), "invalid TODO: incorrect format") - continue - } + // skip comments without URLs for now + // TODO https://github.com/FerretDB/FerretDB/issues/2733 + if !strings.Contains(line, "https://") { + continue + } - n, err := strconv.Atoi(match[1]) - if err != nil { - log.Fatal(err) - } + match := todoRE.FindStringSubmatch(line) - open, ok := issues[n] - if !ok { - issue, _, err := client.Issues.Get(context.TODO(), "FerretDB", "FerretDB", n) - if err != nil { - if errors.As(err, new(*github.RateLimitError)) && token == "" { - log.Printf( - "%[1]T %[1]s\n%[2]s %[3]s", - err, - "Please set a GITHUB_TOKEN as described at", - "https://github.com/FerretDB/FerretDB/blob/main/CONTRIBUTING.md#setting-a-github_token", - ) - - return nil, nil - } - - log.Fatalf("%[1]T %[1]s", err) + if match == nil { + pass.Reportf(c.Pos(), "invalid TODO: incorrect format") + continue + } + + n, err := strconv.Atoi(match[1]) + if err != nil { + log.Fatal(err) + } + + open, ok := issues[n] + if !ok { + issue, _, err := client.Issues.Get(context.TODO(), "FerretDB", "FerretDB", n) + if err != nil { + if errors.As(err, new(*github.RateLimitError)) && token == "" { + log.Printf( + "%[1]T %[1]s\n%[2]s %[3]s", + err, + "Please set a GITHUB_TOKEN as described at", + "https://github.com/FerretDB/FerretDB/blob/main/CONTRIBUTING.md#setting-a-github_token", + ) + + return nil, nil } - open = issue.GetState() == "open" - issues[n] = open + log.Fatalf("%[1]T %[1]s", err) } - if !open { - pass.Reportf(c.Pos(), "invalid TODO: linked issue is closed") - } + open = issue.GetState() == "open" + issues[n] = open + } + + if !open { + pass.Reportf(c.Pos(), "invalid TODO: linked issue is closed") } } } From 0dc44451b0864d38569e804db39bc8909da66f59 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Tue, 17 Oct 2023 11:56:33 +0400 Subject: [PATCH 26/27] Debug token --- .github/workflows/go.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3b9f3eca6009..b2d62eaa49e2 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -266,8 +266,8 @@ jobs: if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready') - permissions: - issues: read + # permissions: + # issues: read steps: - name: Setup permissions monitoring @@ -288,6 +288,8 @@ jobs: - name: Run linters uses: FerretDB/github-actions/linters@main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} fuzz-short: name: Fuzz short From f35022e0de8f04b67b3f69b680dcb1e5e23939d1 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Tue, 17 Oct 2023 12:13:39 +0400 Subject: [PATCH 27/27] Simplify --- .github/workflows/go.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b2d62eaa49e2..7371468d0389 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -266,9 +266,6 @@ jobs: if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready') - # permissions: - # issues: read - steps: - name: Setup permissions monitoring uses: GitHubSecurityLab/actions-permissions/monitor@v1