added issue action support

This commit is contained in:
A_D 2018-11-17 16:10:01 +02:00
parent a260c3311c
commit 931fb26dbc
No known key found for this signature in database
GPG Key ID: C242F3DD220FA945

View File

@ -10,80 +10,6 @@ import (
const INDENT = " " const INDENT = " "
type BaseWebHook struct {
Secret string `json:"secret"`
}
type Push struct {
BaseWebHook
Ref string `json:"ref"`
Before string `json:"before"`
After string `json:"after"`
CompareUrl string `json:"compare_url"`
Commits []Commit `json:"commits"`
Repository Repository `json:"repository"`
Pusher RepoUser `json:"pusher"`
Sender RepoUser `json:"sender"`
}
type RepoUser struct {
ID float64 `json:"id"`
Login string `json:"login"`
FullName string `json:"full_name"`
Email string `json:"email"`
AvatarUrl string `json:"avatar_url"`
Language string `json:"language"`
Username string `json:"username"`
}
type Repository struct {
ID float64 `json:"id"`
Owner RepoUser `json:"owner"`
Name string `json:"name"`
FullName string `json:"full_name"`
Description string `json:"description"`
Empty bool `json:"empty"`
Private bool `json:"private"`
Fork bool `json:"fork"`
Parent string `json:"parent"`
Mirror bool `json:"mirror"`
Size float64 `json:"size"`
HtmlUrl string `json:"html_url"`
SshUrl string `json:"ssh_url"`
CloneUrl string `json:"clone_url"`
Website string `json:"website"`
StarsCount float64 `json:"stars_count"`
ForksCount float64 `json:"forks_count"`
WatchersCount float64 `json:"watchers_count"`
OpenIssuesCount float64 `json:"open_issues_count"`
DefaultBranch string `json:"default_branch"`
Archived bool `json:"archived"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Permissions RepoPermissions `json:"permissions"`
}
type RepoPermissions struct {
Admin bool
Push bool
Pull bool
}
type Commit struct {
Hash string `json:"id"`
Message string `json:"message"`
Author Person `json:"author"`
Committer Person `json:"committer"`
Verification interface{} `json:"verification"`
Timestamp string `json:"timestamp"`
}
type Person struct {
Name string `json:"name"`
Email string `json:"email"`
Username string `json:"username"`
}
func ListenForWebHook(config Config) { func ListenForWebHook(config Config) {
http.HandleFunc("/", handleWebHook) http.HandleFunc("/", handleWebHook)
@ -102,18 +28,20 @@ func handleWebHook(writer http.ResponseWriter, request *http.Request) {
} }
switch eventType := request.Header.Get("X-Gitea-Event"); eventType { switch eventType := request.Header.Get("X-Gitea-Event"); eventType {
case "push": default:
handlePush(data) fmt.Printf("Unknown event type: %q\n", eventType)
handleUnknown(data)
case "": case "":
// Not a gitea event. // Not a gitea event.
fmt.Printf("Got a non-event HTTP request %+v\n", request) fmt.Printf("Got a non-event HTTP request %+v\n", request)
return
default: case "push":
fmt.Printf("Unknown event type: %q\n", eventType) handlePush(data)
handleUnknown(data)
return case "issues":
handleIssueAction(data)
} }
} }
@ -154,3 +82,17 @@ func handlePush(data []byte) {
} }
} }
func handleIssueAction(data []byte) {
action := IssueAction{}
json.Unmarshal(data, &action)
printSep()
fmt.Printf(
"%q (%q) performed the action %q on repo %q and issue %q\n",
action.Sender.Login,
action.Sender.Email,
action.Action,
action.Repository.FullName,
action.Issue.Title,
)
}