added handling for create hooks

This commit is contained in:
A_D 2018-11-17 17:13:47 +02:00
parent 76a0254a1d
commit 538c0d79b5
No known key found for this signature in database
GPG Key ID: C242F3DD220FA945
2 changed files with 39 additions and 3 deletions

View File

@ -46,13 +46,13 @@ type RepoPermissions struct {
type Commit struct {
Hash string `json:"id"`
Message string `json:"message"`
Author Person `json:"author"`
Committer Person `json:"committer"`
Author GitUser `json:"author"`
Committer GitUser `json:"committer"`
Verification interface{} `json:"verification"`
Timestamp string `json:"timestamp"`
}
type Person struct {
type GitUser struct {
Name string `json:"name"`
Email string `json:"email"`
Username string `json:"username"`
@ -114,3 +114,12 @@ type IssueAction struct {
Sender RepoUser `json:"sender"`
Comment IssueComment `json:"comment"`
}
type CreateAction struct {
BaseWebHook
Sha string `json:"sha"`
Ref string `json:"ref"`
RefType string `json:"ref_type"`
Repository Repository `json:"repository"`
Sender RepoUser `json:"sender"`
}

View File

@ -45,6 +45,9 @@ func handleWebHook(writer http.ResponseWriter, request *http.Request) {
case "issue_comment":
handleIssueComment(data)
case "create":
handleCreate(data)
}
}
@ -118,3 +121,27 @@ func handleIssueComment(data []byte) {
msg := strings.Replace(stripped, "\n", strings.Repeat(INDENT, 2) + "\n", -1)
fmt.Printf(strings.Repeat(INDENT, 2) + msg)
}
func handleCreate(data []byte) {
created := CreateAction{}
json.Unmarshal(data, &created)
switch created.RefType {
case "branch":
handleBranchCreate(created)
default:
fmt.Printf("Unknown create reftype %q:\n", created.RefType)
fmt.Println(string(data))
}
}
func handleBranchCreate(branchAction CreateAction) {
printSep()
fmt.Printf(
"%q (%q) created branch %q on repo %q (owned by %q)\n",
branchAction.Sender.Login,
branchAction.Sender.Email,
branchAction.Ref,
branchAction.Repository.FullName,
branchAction.Repository.Owner.Login,
)
}