Compare commits

...

23 commits

Author SHA1 Message Date
e26143661c
Merge pull request 'feat: initial implementation' (#5) from main into release
All checks were successful
Release / Release (push) Successful in 56s
Reviewed-on: #5
2025-04-09 16:25:18 +00:00
64260f301a
ci: add condition to skip linting on release branches
All checks were successful
Lint Pull Request / Lint Pr Title (pull_request) Has been skipped
2025-04-09 18:24:53 +02:00
9b1a6a928e
fix(validation): update error message for invalid commit format
All checks were successful
Lint Pull Request / Lint Pr Title (pull_request) Successful in 9s
2025-04-09 18:22:37 +02:00
c84b1ecd26
fix(main): improve error message for invalid PR title
All checks were successful
Lint Pull Request / Lint Pr Title (pull_request) Successful in 9s
2025-04-09 18:20:59 +02:00
8981c8367e
fix(main): improve error message for invalid PR title
Some checks failed
Lint Pull Request / Lint Pr Title (pull_request) Failing after 9s
2025-04-09 18:20:34 +02:00
19b376ac40
refactor: clean up unused dependencies and functions
Some checks failed
Lint Pull Request / Lint Pr Title (pull_request) Failing after 9s
2025-04-09 18:19:21 +02:00
044823552b
feat: add GitHub event handling and pull request title display
All checks were successful
Lint Pull Request / Lint Pr Title (pull_request) Successful in 9s
2025-04-09 18:17:12 +02:00
2c943b845f
ci: add step to read event.json in PR workflow
All checks were successful
Lint Pull Request / Lint Pr Title (pull_request) Successful in 9s
2025-04-09 18:15:52 +02:00
ce06de60eb
ci: update pull request types for linting workflow
All checks were successful
Lint Pull Request / Lint Pr Title (pull_request) Successful in 9s
2025-04-09 18:13:59 +02:00
80ab70da04
chore: remove invoke-binary.js and update main.go logic
All checks were successful
Lint Pull Request / Lint Pr Title (pull_request) Successful in 9s
2025-04-09 18:11:23 +02:00
6d9c48078c
feat(action): update to use Go for pull request linting
All checks were successful
Lint Pull Request / Lint Pr Title (pull_request) Successful in 9s
2025-04-09 18:10:18 +02:00
da4a8b3030
feat(invoke-binary): add ls command execution in runGo function
Some checks failed
Lint Pull Request / Lint Pr Title (pull_request) Failing after 4s
2025-04-09 18:08:58 +02:00
72b5dd18f3
build(workflows): update CI configuration and remove test file
Some checks failed
Lint Pull Request / Lint Pr Title (pull_request) Failing after 4s
2025-04-09 18:07:13 +02:00
7ded9bab13
ci: update container configuration in PR workflow
Some checks failed
Test Go Action / use-go-action (push) Failing after 10s
Lint Pull Request / Lint Pr Title (pull_request) Failing after 24s
2025-04-09 18:02:26 +02:00
3253d5ac63
ci: update PR workflow to use golang image
Some checks failed
Test Go Action / use-go-action (push) Failing after 7s
Lint Pull Request / Lint Pr Title (pull_request) Failing after 13s
2025-04-09 18:01:43 +02:00
142ef2e8f8
ci: add always condition to lint action steps
Some checks failed
Test Go Action / use-go-action (push) Failing after 4s
Lint Pull Request / Lint Pr Title (pull_request) Failing after 9s
2025-04-09 17:53:47 +02:00
50c451f69e
ci: update action directory path in workflow config
Some checks failed
Test Go Action / use-go-action (push) Failing after 4s
Lint Pull Request / Lint Pr Title (pull_request) Failing after 4s
2025-04-09 17:51:05 +02:00
c9fd83e531
ci: add debugging steps and permission settings to CI
Some checks failed
Test Go Action / use-go-action (push) Failing after 4s
Lint Pull Request / Lint Pr Title (pull_request) Failing after 4s
2025-04-09 17:47:32 +02:00
5fd5b36be7
ci: add test workflow for Go Action
Some checks failed
Test Go Action / use-go-action (push) Failing after 16s
Lint Pull Request / Lint Pr Title (pull_request) Failing after 19s
2025-04-09 17:39:19 +02:00
6c118fb9ff
build: add Go installation step in PR workflow
Some checks failed
Lint Pull Request / Lint Pr Title (pull_request) Failing after 8s
2025-04-09 17:20:20 +02:00
aa1601e751
ci: add pull request linting workflow configuration
Some checks failed
Lint Pull Request / Lint Pr Title (pull_request) Failing after 28s
2025-04-09 17:17:55 +02:00
09380fb8d0
feat: add pull request linting action and validation logic 2025-04-09 17:16:18 +02:00
Gitea Actions
d0e7c0bec7 chore(release): [skip ci] 2025-04-09 14:59:03 +00:00
7 changed files with 165 additions and 0 deletions

21
.gitea/workflows/pr.yml Normal file
View file

@ -0,0 +1,21 @@
name: "Lint Pull Request"
on:
pull_request:
types: [opened, edited, reopened, synchronize]
jobs:
lint:
name: Lint Pr Title
runs-on: ubuntu-latest
if: github.base_ref != 'release'
steps:
- name: Install go
uses: actions/setup-go@v5
with:
go-version: 1.24.2
- name: Run Pull Request Lint Action
uses: https://git.kjan.de/actions/pull-request-lint@main

5
action.yml Normal file
View file

@ -0,0 +1,5 @@
name: 'Pull Request Lint'
description: 'A simple Gitea action written in go'
runs:
using: 'go'
main: 'main.go'

View file

@ -1,3 +1,10 @@
## [0.2.1](https://git.kjan.de/actions/pull-request-lint/compare/v0.2.0...v0.2.1) (2025-04-09)
### Bug Fixes
* Fix release pipeline ([bc0bf00](https://git.kjan.de/actions/pull-request-lint/commit/bc0bf00947c563652b674cab947f863c5c477dd2))
# [0.2.0](https://git.kjan.de/actions/pull-request-lint/compare/v0.1.0...v0.2.0) (2025-04-09)

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module git.kjan.de/actions/pull-request-lint
go 1.24.2

0
go.sum Normal file
View file

View file

@ -0,0 +1,83 @@
package validation
import (
"fmt"
"regexp"
"strings"
)
func ValidateConventionalCommit(commit string) error {
// Regex to match the commit format
// type(scope)!: description
// or
// type!: description
// or
// type: description
re := regexp.MustCompile(`^(?P<type>[a-z]+)(?P<scope>\([a-z]+\))?(?P<breaking>!)?: (?P<description>[a-z].+)$`)
match := re.FindStringSubmatch(commit)
if len(match) == 0 {
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")
}
// Check for breaking change indicator
hasBreakingChangeFooter := strings.Contains(commit, "BREAKING CHANGE:")
if breaking == "!" && hasBreakingChangeFooter {
return fmt.Errorf("breaking change indicator and footer are mutually exclusive")
}
lines := strings.Split(commit, "\n")
if len(lines) > 1 {
body := strings.Join(lines[1:], "\n")
// Check if body is separated from description by a blank line
if !strings.HasPrefix(body, "\n") {
return fmt.Errorf("body must be separated from description by a blank line")
}
}
// Check for footers
footerRegex := regexp.MustCompile(`(?m)^(?P<token>[A-Za-z-]+|BREAKING CHANGE): (?P<value>.*)$`)
footerMatches := footerRegex.FindAllStringSubmatch(commit, -1)
for _, footerMatch := range footerMatches {
tokenIndex := footerRegex.SubexpIndex("token")
token := footerMatch[tokenIndex]
// BREAKING-CHANGE MUST be synonymous with BREAKING CHANGE
if token == "BREAKING-CHANGE" {
continue
}
// Token MUST use - in place of whitespace characters, except for BREAKING CHANGE
if token != "BREAKING CHANGE" && strings.Contains(token, " ") {
return fmt.Errorf("footer token must use - in place of whitespace characters")
}
}
return nil
}

46
main.go Normal file
View file

@ -0,0 +1,46 @@
package main
import (
"encoding/json"
"fmt"
"os"
"git.kjan.de/actions/pull-request-lint/internal/validation"
)
type GithubEvent struct {
PullRequest struct {
Title string `json:"title"`
} `json:"pull_request"`
}
func main() {
eventPath := os.Getenv("GITHUB_EVENT_PATH")
if eventPath == "" {
fmt.Println("GITHUB_EVENT_PATH not set")
os.Exit(1)
}
eventFile, err := os.Open(eventPath)
if err != nil {
fmt.Printf("Error opening %s: %v\n", eventPath, err)
os.Exit(1)
}
defer eventFile.Close()
var event GithubEvent
decoder := json.NewDecoder(eventFile)
err = decoder.Decode(&event)
if err != nil {
fmt.Printf("Error decoding event.json: %v\n", err)
os.Exit(1)
}
prTitle := event.PullRequest.Title
semanticValidationErr := validation.ValidateConventionalCommit(prTitle)
if semanticValidationErr != nil {
fmt.Println(semanticValidationErr)
os.Exit(1)
}
os.Exit(0)
}