Skip to content

Commit

Permalink
Add support for github hook config pings
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrin committed Mar 8, 2022
1 parent a5be275 commit 4b9bd20
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion bot/hook_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type GithubPayload struct {
} `json:"pusher"`
Repository struct {
FullName string `json:"full_name"`
HtmlUrl string `json:"html_url"`
} `json:"repository"`
Commits []struct {
ID string `json:"id"`
Expand All @@ -41,13 +42,18 @@ type GithubPayload struct {
HtmlUrl string `json:"html_url"`
Title string `json:"title"`
} `json:"pull_request"`
Hook struct {
Type string `json:"type"`
} `json:"hook"`
Sender struct {
Login string `json:"login"`
} `json:"sender"`
}

func sendGithubMsg(payload GithubPayload, roomID string) {
if payload.Pusher.Name != "" {
if payload.Hook.Type == "Repository" {
sendGithubHookConfig(payload, roomID)
} else if payload.Pusher.Name != "" {
sendGithubPush(payload, roomID)
} else if payload.PullRequest.HtmlUrl != "" {
sendGithubPullrequest(payload, roomID)
Expand All @@ -56,6 +62,11 @@ func sendGithubMsg(payload GithubPayload, roomID string) {
}
}

func sendGithubHookConfig(payload GithubPayload, roomID string) {
client.SendFormattedNotice(roomID, "[<font color=\"#0000FC\">"+payload.Repository.FullName+"</font>] "+
"<font color=\"#9C009C\">"+payload.Sender.Login+"</font> configured a webhook: "+payload.Repository.HtmlUrl)
}

func sendGithubPullrequest(payload GithubPayload, roomID string) {
client.SendFormattedNotice(roomID, "[<font color=\"#0000FC\">"+payload.Repository.FullName+"</font>] "+
"<font color=\"#9C009C\">"+payload.Sender.Login+"</font> <a href=\""+payload.PullRequest.HtmlUrl+"\">"+payload.Action+" a pull request:</a> "+
Expand Down

0 comments on commit 4b9bd20

Please sign in to comment.