From 91872dfe742edad8b655181f5592d34a192f4bb0 Mon Sep 17 00:00:00 2001 From: levivannoort Date: Tue, 9 Jul 2024 18:06:14 +0200 Subject: [PATCH 1/4] feat: add option to pass list of allowed commit types --- .github/workflows/continuous-integration.yaml | 2 ++ main.go | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 4581459..878edec 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -29,3 +29,5 @@ jobs: - name: pull request title validator uses: ./ # kontrolplane/pull-request-title-validator@latest + with: + types: "fix,feat,chore" \ No newline at end of file diff --git a/main.go b/main.go index 921344b..996dfd9 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( ) var desiredFormat string = "(optional: ): " +var defaultConventionTypes []string = []string{"fix", "feat", "chore", "docs", "build", "ci", "refactor", "perf", "test"} type PullRequest struct { Title string `json:"title"` @@ -23,7 +24,7 @@ type Event struct { func main() { githubEventName := os.Getenv("GITHUB_EVENT_NAME") githubEventPath := os.Getenv("GITHUB_EVENT_PATH") - conventionTypes := []string{"fix", "feat", "chore", "docs", "build", "ci", "refactor", "perf", "test"} + conventionTypes := parseTypes(os.Getenv("INPUT_TYPES"), defaultConventionTypes) if githubEventName != "pull_request" && githubEventName != "pull_request_target" { fmt.Printf("Error: the 'pull_request' trigger type should be used, received '%s'\n", githubEventName) @@ -104,3 +105,17 @@ func checkAgainstConventionTypes(titleType string, conventionTypes []string) err return fmt.Errorf("the type passed '%s' is not present in the types allowed by the convention: %s", titleType, conventionTypes) } + +func parseTypes(input string, fallback []string) []string { + if input == "" { + return fallback + } + types := strings.Split(input, ",") + for i := range types { + types[i] = strings.TrimSpace(types[i]) + } + if len(types) == 0 { + return fallback + } + return types +} From 5d4d2dc3e8537cfc907aa00d28c79891a9047740 Mon Sep 17 00:00:00 2001 From: levivannoort Date: Tue, 9 Jul 2024 18:10:45 +0200 Subject: [PATCH 2/4] chore: log whether a custom types list is passed --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 996dfd9..9f9063f 100644 --- a/main.go +++ b/main.go @@ -88,7 +88,7 @@ func splitTitle(title string) (titleType string, titleScope string, titleMessage titleMessage = strings.SplitAfter(title, ":")[1] titleMessage = strings.TrimSpace(titleMessage) } else { - fmt.Println("No message was included in the pull request title.") + fmt.Println("no message was included in the pull request title.") fmt.Println(desiredFormat) os.Exit(1) } @@ -108,6 +108,7 @@ func checkAgainstConventionTypes(titleType string, conventionTypes []string) err func parseTypes(input string, fallback []string) []string { if input == "" { + fmt.Println("no custom list of commit types was passed using fallback.") return fallback } types := strings.Split(input, ",") From 41df49958ba72b61eaaed190fced471d5c021077 Mon Sep 17 00:00:00 2001 From: levivannoort Date: Tue, 9 Jul 2024 18:13:34 +0200 Subject: [PATCH 3/4] chore: remove feat from list to see whether continuous integration fails --- .github/workflows/continuous-integration.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 878edec..b873f38 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -30,4 +30,4 @@ jobs: - name: pull request title validator uses: ./ # kontrolplane/pull-request-title-validator@latest with: - types: "fix,feat,chore" \ No newline at end of file + types: "fix,chore" \ No newline at end of file From 89d07df0b5b20875efde6c80567221fb462c8440 Mon Sep 17 00:00:00 2001 From: levivannoort Date: Tue, 9 Jul 2024 18:17:18 +0200 Subject: [PATCH 4/4] chore: remove with custom types list from continuous integration and update documentation --- .github/workflows/continuous-integration.yaml | 2 -- README.md | 28 ++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index b873f38..4581459 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -29,5 +29,3 @@ jobs: - name: pull request title validator uses: ./ # kontrolplane/pull-request-title-validator@latest - with: - types: "fix,chore" \ No newline at end of file diff --git a/README.md b/README.md index 675a927..8bd79e1 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ feat(client): add component The action can be used with both the `pull_request` and `pull_request_target` trigger. +`default` ```yaml name: validate-pull-request-title @@ -36,5 +37,30 @@ jobs: runs-on: ubuntu-latest steps: - name: validate pull request title - uses: kontrolplane/pull-request-title-validator@v1.1.0 + uses: kontrolplane/pull-request-title-validator@v1.2.0 +``` + +`custom types` +```yaml +name: validate-pull-request-title + +on: + pull_request: + types: + - opened + - edited + - synchronize + +permissions: + pull-requests: read + +jobs: + validator: + name: validate-pull-request-title + runs-on: ubuntu-latest + steps: + - name: validate pull request title + uses: kontrolplane/pull-request-title-validator@v1.2.0 + with: + types: "fix,feat,chore" ```