From 9bffe0ca1b0f5d8db247ce434d70db5f413f35a6 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Fri, 1 Apr 2022 07:47:21 +0000 Subject: [PATCH 1/4] Remove PR check workflow --- .github/workflows/checks.yml | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 00e7a185c4..b0ef924fe7 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -28,25 +28,3 @@ jobs: - name: Lint run: make lint - - check-description: - name: Checks PR has title and body description - # Commented to avoid skipping required workflow - # See https://github.community/t/feature-request-conditional-required-checks/16761 - # if: ${{ github.actor != 'dependabot[bot]' }} - runs-on: ubuntu-latest - steps: - - uses: actions/setup-go@v2 - with: - go-version: 1.18 - stable: true - check-latest: true - - - uses: actions/checkout@v3 - - name: Checks PR has title and body description - run: | - go run .github/PULL_REQUEST/pull_request.go - - env: - RAW_TITLE: ${{ github.event.pull_request.title }} - RAW_BODY: ${{ github.event.pull_request.body }} From 15397c214d1dda1d2607a19aa5848fbd09b709c1 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Fri, 1 Apr 2022 07:47:47 +0000 Subject: [PATCH 2/4] Remove PR check code --- .github/PULL_REQUEST/pull_request.go | 21 ------ lib/utils/pull_request.go | 66 ----------------- lib/utils/pull_request_test.go | 102 --------------------------- 3 files changed, 189 deletions(-) delete mode 100644 .github/PULL_REQUEST/pull_request.go delete mode 100644 lib/utils/pull_request.go delete mode 100644 lib/utils/pull_request_test.go diff --git a/.github/PULL_REQUEST/pull_request.go b/.github/PULL_REQUEST/pull_request.go deleted file mode 100644 index 98ce0d67c8..0000000000 --- a/.github/PULL_REQUEST/pull_request.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2021 ChainSafe Systems (ON) -// SPDX-License-Identifier: LGPL-3.0-only - -package main - -import ( - "fmt" - "os" - - "github.com/ChainSafe/gossamer/lib/utils" -) - -func main() { - title := os.Getenv("RAW_TITLE") - body := os.Getenv("RAW_BODY") - err := utils.CheckPRDescription(title, body) - if err != nil { - fmt.Println(err.Error()) - os.Exit(1) - } -} diff --git a/lib/utils/pull_request.go b/lib/utils/pull_request.go deleted file mode 100644 index 8bf6cd6e5c..0000000000 --- a/lib/utils/pull_request.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2021 ChainSafe Systems (ON) -// SPDX-License-Identifier: LGPL-3.0-only - -package utils - -import ( - "errors" - "fmt" - "regexp" - "strings" -) - -var ( - // ErrTitlePatternNotValid indicates the title does not match the expected pattern. - ErrTitlePatternNotValid = errors.New("title pattern is not valid") - // ErrBodySectionNotFound indicates one of the required body section was not found. - ErrBodySectionNotFound = errors.New("body section not found") - // ErrBodySectionMisplaced indicates one of the required body section was misplaced in the body. - ErrBodySectionMisplaced = errors.New("body section misplaced") -) - -var ( - titleRegexp = regexp.MustCompile(`^[A-Za-z-_]+\([-_/A-Za-z ]+\):.+[A-Za-z]+.+$`) - commentRegexp = regexp.MustCompile(``) -) - -// CheckPRDescription verifies the PR title and body match the expected format. -func CheckPRDescription(title, body string) error { - if !titleRegexp.MatchString(title) { - return fmt.Errorf("%w: for regular expression %s: '%s'", - ErrTitlePatternNotValid, titleRegexp.String(), title) - } - - body = commentRegexp.ReplaceAllString(body, "") - body = strings.ReplaceAll(body, "\r", "") - - // Required subheading sections in order - requiredSections := []string{"Changes", "Tests", "Issues", "Primary Reviewer"} - - previousIndex := -1 - previousSection := "" - for i, requiredSection := range requiredSections { - textToFind := "## " + requiredSection - if i > 0 { - // no new line required before the first section - textToFind = "\n" + textToFind - } - if i < len(requiredSections)-1 { - // no new line required for last section - textToFind += "\n" - } - - index := strings.Index(body, textToFind) - if index == -1 { - body = strings.ReplaceAll(body, "\n", "\\n") // for error logs in one line - return fmt.Errorf("%w: %q in body: %s", ErrBodySectionNotFound, textToFind, body) - } else if i > 0 && index < previousIndex { - return fmt.Errorf("%w: section %q cannot be before section %q", - ErrBodySectionMisplaced, requiredSection, previousSection) - } - previousIndex = index - previousSection = requiredSection - } - - return nil -} diff --git a/lib/utils/pull_request_test.go b/lib/utils/pull_request_test.go deleted file mode 100644 index 631d248d10..0000000000 --- a/lib/utils/pull_request_test.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2021 ChainSafe Systems (ON) -// SPDX-License-Identifier: LGPL-3.0-only - -package utils - -import ( - "errors" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func Test_CheckPRDescription(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - title string - body string - err error - }{ - "all empty": { - err: errors.New(`title pattern is not valid: for regular expression ` + - `^[A-Za-z-_]+\([-_/A-Za-z ]+\):.+[A-Za-z]+.+$: ''`), - }, - "invalid title": { - title: "category: something", - err: errors.New(`title pattern is not valid: for regular expression ` + - `^[A-Za-z-_]+\([-_/A-Za-z ]+\):.+[A-Za-z]+.+$: 'category: something'`), - }, - "empty body only": { - title: "category(subcategory): something", - err: errors.New("body section not found: \"## Changes\\n\" in body: "), - }, - "invalid body": { - title: "category(subcategory): something", - body: "##Change\n## Tests ## Issues ## Primary Reviewer", - err: errors.New("body section not found: \"## Changes\\n\" in body: " + - "##Change\\n## Tests ## Issues ## Primary Reviewer"), - }, - "misplaced section": { - title: "category(subcategory): something", - body: "## Changes\n## Tests\n## Primary Reviewer\n## Issues\n", - err: errors.New("body section misplaced: section \"Primary Reviewer\" cannot be before section \"Issues\""), - }, - "minimal valid": { - title: "category(subcategory): something", - body: "## Changes\n## Tests\n## Issues\n## Primary Reviewer", - }, - "valid example": { - title: `feat(dot/rpc): implement chain_subscribeAllHeads RPC`, - body: `## Changes - - - -- changes for demo :123 - -## Tests - - - -- tests for demo:123{} - -## Issues - - - -- issues for demo:43434 - -## Primary Reviewer - - - -- @noot for demo:12 -`, - }, - } - - for name, testCase := range testCases { - testCase := testCase - t.Run(name, func(t *testing.T) { - t.Parallel() - - err := CheckPRDescription(testCase.title, testCase.body) - if testCase.err != nil { - require.Error(t, err) - assert.Equal(t, testCase.err.Error(), err.Error()) - } else { - assert.NoError(t, err) - } - }) - } -} From 9bfd788ad3afc3c18e1e20dc2b9f3df897dc46fc Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Fri, 1 Apr 2022 07:47:55 +0000 Subject: [PATCH 3/4] Simplify PR template --- .github/PULL_REQUEST_TEMPLATE.md | 36 +++++++------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 898685a80d..85356a3f0b 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,43 +1,21 @@ ## Changes - - -- -- -- + ## Tests - - -``` + +```sh +go test -tags integration github.com/ChainSafe/gossamer ``` ## Issues - - -- + ## Primary Reviewer - + -- +@noot From c73a658ab832df06ba65eb98642c793465cc1888 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Tue, 5 Apr 2022 13:57:32 -0400 Subject: [PATCH 4/4] Update .github/PULL_REQUEST_TEMPLATE.md Co-authored-by: Timothy Wu --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 85356a3f0b..830c83440b 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -18,4 +18,4 @@ go test -tags integration github.com/ChainSafe/gossamer -@noot +@timwu20