diff --git a/.gitea/workflows/CI.yml b/.gitea/workflows/CI.yml deleted file mode 100644 index 23d4be6..0000000 --- a/.gitea/workflows/CI.yml +++ /dev/null @@ -1,29 +0,0 @@ -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 - - 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 ./... diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 0eea3b6..e1a90fb 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -52,25 +52,23 @@ 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: ${{ !(env.SKIP_MERGE == true) }} + if: ${{ steps.semantic.outputs.new_release_published && !(env.SKIP_MERGE == true) }} run: git reset --hard && git checkout ${{ env.TARGET_BRANCH }} && git pull - name: Merge release - if: ${{ !(env.SKIP_MERGE == true) }} + if: ${{ steps.semantic.outputs.new_release_published && !(env.SKIP_MERGE == true) }} run: git merge ${{ env.RELEASE_BRANCH }} - name: Push changes to target branch - if: ${{ !(env.SKIP_MERGE == true) }} + if: ${{ steps.semantic.outputs.new_release_published && !(env.SKIP_MERGE == true) }} run: | git remote set-url origin git@${{ env.GITEA_DOMAIN }}:${{ github.repository }}.git git push origin HEAD:${{ env.TARGET_BRANCH }} diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index d5ac850..0000000 --- a/.golangci.yml +++ /dev/null @@ -1,4 +0,0 @@ -version: "2" -linters: - enable: - - revive diff --git a/README.md b/README.md index 7c7a6db..a198e3f 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,3 @@ # pull-request-lint -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. +Lints the title of a pull request \ No newline at end of file diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 15dad97..62b4ea5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,22 +1,3 @@ -# [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) - - -### 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) diff --git a/internal/validation/validation.go b/internal/validation/validation.go index 0a4ada9..4d48e4a 100644 --- a/internal/validation/validation.go +++ b/internal/validation/validation.go @@ -1,4 +1,3 @@ -// Package validation General validation tasks package validation import ( @@ -7,7 +6,6 @@ import ( "strings" ) -// ValidateConventionalCommit validates if string follows conventional commit func ValidateConventionalCommit(commit string) error { // Regex to match the commit format // type(scope)!: description @@ -15,26 +13,33 @@ func ValidateConventionalCommit(commit string) error { // type!: description // or // type: description - re := regexp.MustCompile(`^(?P[a-z]+)(?P\([a-z]+\))?(?P!)?: (?P.+)$`) + re := regexp.MustCompile(`^(?P[a-z]+)(?P\([a-z]+\))?(?P!)?: (?P[a-z].+)$`) match := re.FindStringSubmatch(commit) if len(match) == 0 { - return fmt.Errorf("invalid commit format") + return fmt.Errorf("Invalid PR title") } 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") diff --git a/main.go b/main.go index 507692b..3a70316 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,3 @@ -// Package main is the main package package main import ( @@ -9,7 +8,6 @@ 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"` @@ -28,13 +26,7 @@ func main() { fmt.Printf("Error opening %s: %v\n", eventPath, err) os.Exit(1) } - defer func() { - closeFileErr := eventFile.Close() - if closeFileErr != nil { - fmt.Println("Error closing eventFile") - os.Exit(1) - } - }() + defer eventFile.Close() var event GithubEvent decoder := json.NewDecoder(eventFile) diff --git a/renovate.json b/renovate.json deleted file mode 100644 index c183f9d..0000000 --- a/renovate.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "local>Renovate/renovate-config" - ] -}