mirror of
https://git.ferricyanide.solutions/A_D/irc-webhooks.git
synced 2024-12-22 08:17:04 +00:00
added handling for create hooks
This commit is contained in:
parent
76a0254a1d
commit
538c0d79b5
@ -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"`
|
||||
}
|
||||
|
27
webhooks.go
27
webhooks.go
@ -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,
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user