Compare commits
11 commits
Author | SHA1 | Date | |
---|---|---|---|
c142133a34 | |||
653e80ee73 | |||
e332ef87cb | |||
1b86948c60 | |||
667ccdd9a1 | |||
66f0f05e55 | |||
9a125449d5 | |||
c420551cdb | |||
7e2de542b6 | |||
08b43cc51b | |||
|
372ed39a62 |
8 changed files with 108 additions and 14 deletions
29
.gitea/workflows/CI.yml
Normal file
29
.gitea/workflows/CI.yml
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
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 ./...
|
|
@ -52,23 +52,25 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
git add docs/
|
git add docs/
|
||||||
git commit -m "chore(release): [skip ci]"
|
git commit -m "chore(release): [skip ci]"
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Push changes to release branch
|
- name: Push changes to release branch
|
||||||
if: ${{ steps.semantic.outputs.new_release_published }}
|
if: ${{ steps.semantic.outputs.new_release_published }}
|
||||||
run: |
|
run: |
|
||||||
git remote set-url origin git@${{ env.GITEA_DOMAIN }}:${{ github.repository }}.git
|
git remote set-url origin git@${{ env.GITEA_DOMAIN }}:${{ github.repository }}.git
|
||||||
git push origin HEAD:${{ env.RELEASE_BRANCH }}
|
git push origin HEAD:${{ env.RELEASE_BRANCH }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Checkout target branch
|
- 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
|
run: git reset --hard && git checkout ${{ env.TARGET_BRANCH }} && git pull
|
||||||
|
|
||||||
- name: Merge release
|
- 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 }}
|
run: git merge ${{ env.RELEASE_BRANCH }}
|
||||||
|
|
||||||
- name: Push changes to target branch
|
- name: Push changes to target branch
|
||||||
if: ${{ steps.semantic.outputs.new_release_published && !(env.SKIP_MERGE == true) }}
|
if: ${{ !(env.SKIP_MERGE == true) }}
|
||||||
run: |
|
run: |
|
||||||
git remote set-url origin git@${{ env.GITEA_DOMAIN }}:${{ github.repository }}.git
|
git remote set-url origin git@${{ env.GITEA_DOMAIN }}:${{ github.repository }}.git
|
||||||
git push origin HEAD:${{ env.TARGET_BRANCH }}
|
git push origin HEAD:${{ env.TARGET_BRANCH }}
|
||||||
|
|
4
.golangci.yml
Normal file
4
.golangci.yml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
version: "2"
|
||||||
|
linters:
|
||||||
|
enable:
|
||||||
|
- revive
|
40
README.md
40
README.md
|
@ -1,3 +1,41 @@
|
||||||
# pull-request-lint
|
# pull-request-lint
|
||||||
|
|
||||||
Lints the title of a pull request
|
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.
|
||||||
|
|
|
@ -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)
|
# [0.3.0](https://git.kjan.de/actions/pull-request-lint/compare/v0.2.1...v0.3.0) (2025-04-09)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Package validation General validation tasks
|
||||||
package validation
|
package validation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -6,6 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ValidateConventionalCommit validates if string follows conventional commit
|
||||||
func ValidateConventionalCommit(commit string) error {
|
func ValidateConventionalCommit(commit string) error {
|
||||||
// Regex to match the commit format
|
// Regex to match the commit format
|
||||||
// type(scope)!: description
|
// type(scope)!: description
|
||||||
|
@ -13,33 +15,26 @@ func ValidateConventionalCommit(commit string) error {
|
||||||
// type!: description
|
// type!: description
|
||||||
// or
|
// or
|
||||||
// type: description
|
// type: description
|
||||||
re := regexp.MustCompile(`^(?P<type>[a-z]+)(?P<scope>\([a-z]+\))?(?P<breaking>!)?: (?P<description>[a-z].+)$`)
|
re := regexp.MustCompile(`^(?P<type>[a-z]+)(?P<scope>\([a-z]+\))?(?P<breaking>!)?: (?P<description>.+)$`)
|
||||||
match := re.FindStringSubmatch(commit)
|
match := re.FindStringSubmatch(commit)
|
||||||
|
|
||||||
if len(match) == 0 {
|
if len(match) == 0 {
|
||||||
return fmt.Errorf("Invalid PR title")
|
return fmt.Errorf("invalid commit format")
|
||||||
}
|
}
|
||||||
|
|
||||||
typeIndex := re.SubexpIndex("type")
|
typeIndex := re.SubexpIndex("type")
|
||||||
scopeIndex := re.SubexpIndex("scope")
|
scopeIndex := re.SubexpIndex("scope")
|
||||||
breakingIndex := re.SubexpIndex("breaking")
|
breakingIndex := re.SubexpIndex("breaking")
|
||||||
descriptionIndex := re.SubexpIndex("description")
|
|
||||||
|
|
||||||
commitType := match[typeIndex]
|
commitType := match[typeIndex]
|
||||||
scope := match[scopeIndex]
|
scope := match[scopeIndex]
|
||||||
breaking := match[breakingIndex]
|
breaking := match[breakingIndex]
|
||||||
description := match[descriptionIndex]
|
|
||||||
|
|
||||||
// Type MUST be lowercase
|
// Type MUST be lowercase
|
||||||
if commitType != strings.ToLower(commitType) {
|
if commitType != strings.ToLower(commitType) {
|
||||||
return fmt.Errorf("type must be lowercase")
|
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
|
// Scope MUST be lowercase
|
||||||
if scope != "" && scope != strings.ToLower(scope) {
|
if scope != "" && scope != strings.ToLower(scope) {
|
||||||
return fmt.Errorf("scope must be lowercase")
|
return fmt.Errorf("scope must be lowercase")
|
||||||
|
|
10
main.go
10
main.go
|
@ -1,3 +1,4 @@
|
||||||
|
// Package main is the main package
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -8,6 +9,7 @@ import (
|
||||||
"git.kjan.de/actions/pull-request-lint/internal/validation"
|
"git.kjan.de/actions/pull-request-lint/internal/validation"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GithubEvent represents a github actions event
|
||||||
type GithubEvent struct {
|
type GithubEvent struct {
|
||||||
PullRequest struct {
|
PullRequest struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
@ -26,7 +28,13 @@ func main() {
|
||||||
fmt.Printf("Error opening %s: %v\n", eventPath, err)
|
fmt.Printf("Error opening %s: %v\n", eventPath, err)
|
||||||
os.Exit(1)
|
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
|
var event GithubEvent
|
||||||
decoder := json.NewDecoder(eventFile)
|
decoder := json.NewDecoder(eventFile)
|
||||||
|
|
6
renovate.json
Normal file
6
renovate.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": [
|
||||||
|
"local>Renovate/renovate-config"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue