Reviewed-on: #11 Co-authored-by: Jan Klattenhoff <jan@kjan.email> Co-committed-by: Jan Klattenhoff <jan@kjan.email>
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
// Package main is the main package
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.kjan.de/actions/pull-request-lint/internal/validation"
|
|
)
|
|
|
|
// GithubEvent represents a github actions event
|
|
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 func() {
|
|
closeFileErr := eventFile.Close()
|
|
if closeFileErr != nil {
|
|
fmt.Println("Error closing eventFile")
|
|
os.Exit(1)
|
|
}
|
|
}()
|
|
|
|
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)
|
|
}
|