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
All checks were successful
Lint Pull Request / Lint Pr Title (pull_request) Successful in 9s
This commit is contained in:
parent
2c943b845f
commit
044823552b
1 changed files with 31 additions and 8 deletions
39
main.go
39
main.go
|
@ -1,16 +1,39 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Get all environment variables
|
||||
environ := os.Environ()
|
||||
|
||||
// Print each environment variable
|
||||
for _, env := range environ {
|
||||
fmt.Println(env)
|
||||
}
|
||||
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
|
||||
fmt.Println("Pull Request Title:", prTitle)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue