From 372ed39a62d82d515805d88a38220128726f9363 Mon Sep 17 00:00:00 2001 From: Gitea Actions Date: Wed, 9 Apr 2025 16:32:02 +0000 Subject: [PATCH 1/9] chore(release): [skip ci] --- docs/CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 62b4ea5..4addfa4 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,15 @@ +# [1.0.0](https://git.kjan.de/actions/pull-request-lint/compare/v0.3.0...v1.0.0) (2025-04-09) + + +### Code Refactoring + +* some polishing ([86febd9](https://git.kjan.de/actions/pull-request-lint/commit/86febd99e507d250adb18fdfede0a01f6e6f8d46)) + + +### BREAKING CHANGES + +* Version 1 + # [0.3.0](https://git.kjan.de/actions/pull-request-lint/compare/v0.2.1...v0.3.0) (2025-04-09) From 08b43cc51b2f8975144fb61afddb5cb222890e09 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:37:58 +0200 Subject: [PATCH 2/9] refactor(validation): simplify regex and error messages --- internal/validation/validation.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/internal/validation/validation.go b/internal/validation/validation.go index 4d48e4a..8c3123e 100644 --- a/internal/validation/validation.go +++ b/internal/validation/validation.go @@ -13,33 +13,26 @@ func ValidateConventionalCommit(commit string) error { // type!: description // or // type: description - re := regexp.MustCompile(`^(?P[a-z]+)(?P\([a-z]+\))?(?P!)?: (?P[a-z].+)$`) + re := regexp.MustCompile(`^(?P[a-z]+)(?P\([a-z]+\))?(?P!)?: (?P.+)$`) match := re.FindStringSubmatch(commit) if len(match) == 0 { - return fmt.Errorf("Invalid PR title") + return fmt.Errorf("invalid commit format") } typeIndex := re.SubexpIndex("type") scopeIndex := re.SubexpIndex("scope") breakingIndex := re.SubexpIndex("breaking") - descriptionIndex := re.SubexpIndex("description") commitType := match[typeIndex] scope := match[scopeIndex] breaking := match[breakingIndex] - description := match[descriptionIndex] // Type MUST be lowercase if commitType != strings.ToLower(commitType) { return fmt.Errorf("type must be lowercase") } - // Description MUST start with lowercase - if description != strings.ToLower(description) { - return fmt.Errorf("description must start with lowercase") - } - // Scope MUST be lowercase if scope != "" && scope != strings.ToLower(scope) { return fmt.Errorf("scope must be lowercase") From 7e2de542b6f4439dab9c112b0999e4d329732d19 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 16:43:32 +0000 Subject: [PATCH 3/9] docs: update README with usage and validation rules (#7) Reviewed-on: https://git.kjan.de/actions/pull-request-lint/pulls/7 Co-authored-by: Jan Klattenhoff Co-committed-by: Jan Klattenhoff --- README.md | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a198e3f..7c7a6db 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,41 @@ # pull-request-lint -Lints the title of a pull request \ No newline at end of file +A GitHub/Gitea Action that lints pull request titles to ensure they follow the [Conventional Commits](https://www.conventionalcommits.org/) format. + +## Usage + +Add the following to your GitHub/Gitea workflow: + +```yaml +name: Pull Request Lint + +on: + pull_request: + types: [opened, edited, reopened, synchronize] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install go + uses: actions/setup-go@v5 + with: + go-version: 1.24.2 + - uses: https://git.kjan.de/actions/pull-request-lint@release +``` + +## Validation Rules + +The action enforces the following Conventional Commits rules for PR titles: + +- Format must be: `type(scope)!: description` (scope and breaking change marker `!` are optional) +- Type and scope must be lowercase +- Description must start with lowercase +- Breaking change indicator and footer are mutually exclusive +- Body must be separated from description by a blank line +- Footer tokens must use hyphens instead of spaces (except for "BREAKING CHANGE") + +## License + +See [LICENSE](LICENSE) file for details. From c420551cdb4cdc191a149849abefd2ca2764f0ec Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 9 Apr 2025 16:44:40 +0000 Subject: [PATCH 4/9] chore: Configure Renovate (#4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Welcome to [Renovate](https://github.com/renovatebot/renovate)! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin. 🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged. --- ### Detected Package Files * `.gitea/workflows/pr.yml` (github-actions) * `.gitea/workflows/release.yml` (github-actions) * `.gitea/workflows/test.yml` (github-actions) * `go.mod` (gomod) ### Configuration Summary Based on the default config's presets, Renovate will: - Start dependency updates only once this onboarding PR is merged - Enable Renovate Dependency Dashboard creation. - Use semantic commit type `fix` for dependencies and `chore` for all others if semantic commits are in use. - Ignore `node_modules`, `bower_components`, `vendor` and various test/tests (except for nuget) directories. - Group known monorepo packages together. - Use curated list of recommended non-monorepo package groupings. - Apply crowd-sourced package replacement rules. - Apply crowd-sourced workarounds for known problems with packages. - Preserve (but continue to upgrade) any existing SemVer ranges. - Enable Renovate Dependency Dashboard creation. - Rebase existing PRs any time the base branch has been updated. - Use semantic prefixes for commit messages and PR titles. - Raise PR when vulnerability alerts are detected with label `'security'`. - Group all `minor` and `patch` updates together. - Keep existing branches updated even when not scheduled. - Show all Merge Confidence badges for pull requests. 🔡 Do you want to change how Renovate upgrades your dependencies? Add your custom config to `renovate.json` in this branch. Renovate will update the Pull Request description the next time it runs. --- ### What to Expect With your current configuration, Renovate will create 2 Pull Requests:
chore(deps): update dependency go to 1.24 - Schedule: ["at any time"] - Branch name: `renovate/all-minor-patch` - Merge into: `main` - Upgrade [go](https://github.com/actions/go-versions) to `1.24`
chore(deps): update actions/setup-go action to v5 - Schedule: ["at any time"] - Branch name: `renovate/actions-setup-go-5.x` - Merge into: `main` - Upgrade [actions/setup-go](https://github.com/actions/setup-go) to `v5`
--- ❓ Got questions? Check out Renovate's [Docs](https://docs.renovatebot.com/), particularly the Getting Started section. If you need any further assistance then you can also [request help here](https://github.com/renovatebot/renovate/discussions). --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). Co-authored-by: Jan K9f Reviewed-on: https://git.kjan.de/actions/pull-request-lint/pulls/4 Co-authored-by: Renovate Bot Co-committed-by: Renovate Bot --- renovate.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 renovate.json diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..c183f9d --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "local>Renovate/renovate-config" + ] +} From 66f0f05e55ff5e4a2d103a97230d71179c46d3be Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 18:51:21 +0200 Subject: [PATCH 5/9] ci: update release workflow for error handling --- .gitea/workflows/release.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index e1a90fb..0eea3b6 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -52,23 +52,25 @@ jobs: run: | git add docs/ git commit -m "chore(release): [skip ci]" + continue-on-error: true - name: Push changes to release branch if: ${{ steps.semantic.outputs.new_release_published }} run: | git remote set-url origin git@${{ env.GITEA_DOMAIN }}:${{ github.repository }}.git git push origin HEAD:${{ env.RELEASE_BRANCH }} + continue-on-error: true - name: Checkout target branch - if: ${{ steps.semantic.outputs.new_release_published && !(env.SKIP_MERGE == true) }} + if: ${{ !(env.SKIP_MERGE == true) }} run: git reset --hard && git checkout ${{ env.TARGET_BRANCH }} && git pull - name: Merge release - if: ${{ steps.semantic.outputs.new_release_published && !(env.SKIP_MERGE == true) }} + if: ${{ !(env.SKIP_MERGE == true) }} run: git merge ${{ env.RELEASE_BRANCH }} - name: Push changes to target branch - if: ${{ steps.semantic.outputs.new_release_published && !(env.SKIP_MERGE == true) }} + if: ${{ !(env.SKIP_MERGE == true) }} run: | git remote set-url origin git@${{ env.GITEA_DOMAIN }}:${{ github.repository }}.git git push origin HEAD:${{ env.TARGET_BRANCH }} From 1b86948c602d130039b1e480b0f4c02a955cf732 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 19:28:15 +0200 Subject: [PATCH 6/9] ci: add Go CI workflow configuration file --- .gitea/workflows/CI.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .gitea/workflows/CI.yml diff --git a/.gitea/workflows/CI.yml b/.gitea/workflows/CI.yml new file mode 100644 index 0000000..e962467 --- /dev/null +++ b/.gitea/workflows/CI.yml @@ -0,0 +1,18 @@ +name: "Go CI" + +on: + pull_request: + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: 1.24.2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v7 + with: + version: v2.0 From e332ef87cbab6a7e0ebde5bd17a37b50c9aea967 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 17:40:45 +0000 Subject: [PATCH 7/9] feat: add linters (#11) Reviewed-on: https://git.kjan.de/actions/pull-request-lint/pulls/11 Co-authored-by: Jan Klattenhoff Co-committed-by: Jan Klattenhoff --- .golangci.yml | 4 ++++ internal/validation/validation.go | 2 ++ main.go | 10 +++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..d5ac850 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,4 @@ +version: "2" +linters: + enable: + - revive diff --git a/internal/validation/validation.go b/internal/validation/validation.go index 8c3123e..0a4ada9 100644 --- a/internal/validation/validation.go +++ b/internal/validation/validation.go @@ -1,3 +1,4 @@ +// Package validation General validation tasks package validation import ( @@ -6,6 +7,7 @@ import ( "strings" ) +// ValidateConventionalCommit validates if string follows conventional commit func ValidateConventionalCommit(commit string) error { // Regex to match the commit format // type(scope)!: description diff --git a/main.go b/main.go index 3a70316..507692b 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,4 @@ +// Package main is the main package package main import ( @@ -8,6 +9,7 @@ import ( "git.kjan.de/actions/pull-request-lint/internal/validation" ) +// GithubEvent represents a github actions event type GithubEvent struct { PullRequest struct { Title string `json:"title"` @@ -26,7 +28,13 @@ func main() { fmt.Printf("Error opening %s: %v\n", eventPath, err) os.Exit(1) } - defer eventFile.Close() + defer func() { + closeFileErr := eventFile.Close() + if closeFileErr != nil { + fmt.Println("Error closing eventFile") + os.Exit(1) + } + }() var event GithubEvent decoder := json.NewDecoder(eventFile) From 653e80ee737e01e12f335a4b0ab4f71ad506825b Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 9 Apr 2025 17:46:26 +0000 Subject: [PATCH 8/9] ci: add test job to CI configuration (#12) Reviewed-on: https://git.kjan.de/actions/pull-request-lint/pulls/12 Co-authored-by: Jan Klattenhoff Co-committed-by: Jan Klattenhoff --- .gitea/workflows/CI.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.gitea/workflows/CI.yml b/.gitea/workflows/CI.yml index e962467..23d4be6 100644 --- a/.gitea/workflows/CI.yml +++ b/.gitea/workflows/CI.yml @@ -16,3 +16,14 @@ jobs: uses: golangci/golangci-lint-action@v7 with: version: v2.0 + + test: + name: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: 1.24.2 + - name: Test + run: go test ./... From a992d1cfd99449e4ffa507f4f74abae2c97f834c Mon Sep 17 00:00:00 2001 From: Gitea Actions Date: Wed, 9 Apr 2025 17:49:25 +0000 Subject: [PATCH 9/9] chore(release): [skip ci] --- docs/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4addfa4..15dad97 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +# [1.1.0](https://git.kjan.de/actions/pull-request-lint/compare/v1.0.0...v1.1.0) (2025-04-09) + + +### Features + +* add linters ([#11](https://git.kjan.de/actions/pull-request-lint/issues/11)) ([e332ef8](https://git.kjan.de/actions/pull-request-lint/commit/e332ef87cbab6a7e0ebde5bd17a37b50c9aea967)) + # [1.0.0](https://git.kjan.de/actions/pull-request-lint/compare/v0.3.0...v1.0.0) (2025-04-09)