Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2845fba51e | |||
| e1f5ba4c3a | |||
| ef903a2448 | |||
| 115b7e49a5 | |||
| 9ce6db7e53 | |||
| dc7efa3fa7 | |||
| c3faee81c0 | |||
| 26af15f0e6 |
@@ -1,6 +1,6 @@
|
|||||||
Library webhooks
|
Library webhooks
|
||||||
================
|
================
|
||||||
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v5/logo.png">
|
<img align="right" src="https://raw.githubusercontent.com/go-playground/webhooks/v5/logo.png">
|
||||||
[](https://travis-ci.org/go-playground/webhooks)
|
[](https://travis-ci.org/go-playground/webhooks)
|
||||||
[](https://coveralls.io/github/go-playground/webhooks?branch=v5)
|
[](https://coveralls.io/github/go-playground/webhooks?branch=v5)
|
||||||
[](https://goreportcard.com/report/go-playground/webhooks)
|
[](https://goreportcard.com/report/go-playground/webhooks)
|
||||||
|
|||||||
+45
-39
@@ -28,44 +28,46 @@ type Event string
|
|||||||
|
|
||||||
// GitHub hook types
|
// GitHub hook types
|
||||||
const (
|
const (
|
||||||
CheckRunEvent Event = "check_run"
|
CheckRunEvent Event = "check_run"
|
||||||
CheckSuiteEvent Event = "check_suite"
|
CheckSuiteEvent Event = "check_suite"
|
||||||
CommitCommentEvent Event = "commit_comment"
|
CommitCommentEvent Event = "commit_comment"
|
||||||
CreateEvent Event = "create"
|
CreateEvent Event = "create"
|
||||||
DeleteEvent Event = "delete"
|
DeleteEvent Event = "delete"
|
||||||
DeploymentEvent Event = "deployment"
|
DeploymentEvent Event = "deployment"
|
||||||
DeploymentStatusEvent Event = "deployment_status"
|
DeploymentStatusEvent Event = "deployment_status"
|
||||||
ForkEvent Event = "fork"
|
ForkEvent Event = "fork"
|
||||||
GollumEvent Event = "gollum"
|
GollumEvent Event = "gollum"
|
||||||
InstallationEvent Event = "installation"
|
InstallationEvent Event = "installation"
|
||||||
InstallationRepositoriesEvent Event = "installation_repositories"
|
InstallationRepositoriesEvent Event = "installation_repositories"
|
||||||
IntegrationInstallationEvent Event = "integration_installation"
|
IntegrationInstallationEvent Event = "integration_installation"
|
||||||
IssueCommentEvent Event = "issue_comment"
|
IntegrationInstallationRepositoriesEvent Event = "integration_installation_repositories"
|
||||||
IssuesEvent Event = "issues"
|
IssueCommentEvent Event = "issue_comment"
|
||||||
LabelEvent Event = "label"
|
IssuesEvent Event = "issues"
|
||||||
MemberEvent Event = "member"
|
LabelEvent Event = "label"
|
||||||
MembershipEvent Event = "membership"
|
MemberEvent Event = "member"
|
||||||
MilestoneEvent Event = "milestone"
|
MembershipEvent Event = "membership"
|
||||||
OrganizationEvent Event = "organization"
|
MilestoneEvent Event = "milestone"
|
||||||
OrgBlockEvent Event = "org_block"
|
MetaEvent Event = "meta"
|
||||||
PageBuildEvent Event = "page_build"
|
OrganizationEvent Event = "organization"
|
||||||
PingEvent Event = "ping"
|
OrgBlockEvent Event = "org_block"
|
||||||
ProjectCardEvent Event = "project_card"
|
PageBuildEvent Event = "page_build"
|
||||||
ProjectColumnEvent Event = "project_column"
|
PingEvent Event = "ping"
|
||||||
ProjectEvent Event = "project"
|
ProjectCardEvent Event = "project_card"
|
||||||
PublicEvent Event = "public"
|
ProjectColumnEvent Event = "project_column"
|
||||||
PullRequestEvent Event = "pull_request"
|
ProjectEvent Event = "project"
|
||||||
PullRequestReviewEvent Event = "pull_request_review"
|
PublicEvent Event = "public"
|
||||||
PullRequestReviewCommentEvent Event = "pull_request_review_comment"
|
PullRequestEvent Event = "pull_request"
|
||||||
PushEvent Event = "push"
|
PullRequestReviewEvent Event = "pull_request_review"
|
||||||
ReleaseEvent Event = "release"
|
PullRequestReviewCommentEvent Event = "pull_request_review_comment"
|
||||||
RepositoryEvent Event = "repository"
|
PushEvent Event = "push"
|
||||||
RepositoryVulnerabilityAlertEvent Event = "repository_vulnerability_alert"
|
ReleaseEvent Event = "release"
|
||||||
SecurityAdvisoryEvent Event = "security_advisory"
|
RepositoryEvent Event = "repository"
|
||||||
StatusEvent Event = "status"
|
RepositoryVulnerabilityAlertEvent Event = "repository_vulnerability_alert"
|
||||||
TeamEvent Event = "team"
|
SecurityAdvisoryEvent Event = "security_advisory"
|
||||||
TeamAddEvent Event = "team_add"
|
StatusEvent Event = "status"
|
||||||
WatchEvent Event = "watch"
|
TeamEvent Event = "team"
|
||||||
|
TeamAddEvent Event = "team_add"
|
||||||
|
WatchEvent Event = "watch"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EventSubtype defines a GitHub Hook Event subtype
|
// EventSubtype defines a GitHub Hook Event subtype
|
||||||
@@ -206,7 +208,7 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
|
|||||||
var pl InstallationPayload
|
var pl InstallationPayload
|
||||||
err = json.Unmarshal([]byte(payload), &pl)
|
err = json.Unmarshal([]byte(payload), &pl)
|
||||||
return pl, err
|
return pl, err
|
||||||
case InstallationRepositoriesEvent:
|
case InstallationRepositoriesEvent, IntegrationInstallationRepositoriesEvent:
|
||||||
var pl InstallationRepositoriesPayload
|
var pl InstallationRepositoriesPayload
|
||||||
err = json.Unmarshal([]byte(payload), &pl)
|
err = json.Unmarshal([]byte(payload), &pl)
|
||||||
return pl, err
|
return pl, err
|
||||||
@@ -230,6 +232,10 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
|
|||||||
var pl MembershipPayload
|
var pl MembershipPayload
|
||||||
err = json.Unmarshal([]byte(payload), &pl)
|
err = json.Unmarshal([]byte(payload), &pl)
|
||||||
return pl, err
|
return pl, err
|
||||||
|
case MetaEvent:
|
||||||
|
var pl MetaPayload
|
||||||
|
err = json.Unmarshal([]byte(payload), &pl)
|
||||||
|
return pl, err
|
||||||
case MilestoneEvent:
|
case MilestoneEvent:
|
||||||
var pl MilestonePayload
|
var pl MilestonePayload
|
||||||
err = json.Unmarshal([]byte(payload), &pl)
|
err = json.Unmarshal([]byte(payload), &pl)
|
||||||
|
|||||||
@@ -253,6 +253,16 @@ func TestWebhooks(t *testing.T) {
|
|||||||
"X-Hub-Signature": []string{"sha1=bb2769f05f1a11af3a1edf8f9fac11bae7402a1e"},
|
"X-Hub-Signature": []string{"sha1=bb2769f05f1a11af3a1edf8f9fac11bae7402a1e"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "IntegrationInstallationRepositoriesEvent",
|
||||||
|
event: IntegrationInstallationRepositoriesEvent,
|
||||||
|
typ: InstallationRepositoriesPayload{},
|
||||||
|
filename: "../testdata/github/integration-installation-repositories.json",
|
||||||
|
headers: http.Header{
|
||||||
|
"X-Github-Event": []string{"integration_installation_repositories"},
|
||||||
|
"X-Hub-Signature": []string{"sha1=2f00a982574188342c2894eb9d1b1e93434687fb"},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "IssueCommentEvent",
|
name: "IssueCommentEvent",
|
||||||
event: IssueCommentEvent,
|
event: IssueCommentEvent,
|
||||||
|
|||||||
@@ -2271,6 +2271,137 @@ type MembershipPayload struct {
|
|||||||
} `json:"organization"`
|
} `json:"organization"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MetaPayload contains the information for GitHub's meta hook event
|
||||||
|
type MetaPayload struct {
|
||||||
|
HookID int `json:"hook_id"`
|
||||||
|
Hook struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
NodeID string `json:"node_id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Active bool `json:"active"`
|
||||||
|
Events []string `json:"events"`
|
||||||
|
AppID int `json:"app_id"`
|
||||||
|
Config struct {
|
||||||
|
ContentType string `json:"content_type"`
|
||||||
|
InsecureSSL string `json:"insecure_ssl"`
|
||||||
|
Secret string `json:"secret"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
} `json:"config"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
} `json:"hook"`
|
||||||
|
Repository struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
NodeID string `json:"node_id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
Owner struct {
|
||||||
|
Login string `json:"login"`
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
NodeID string `json:"node_id"`
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
GravatarID string `json:"gravatar_id"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
HTMLURL string `json:"html_url"`
|
||||||
|
FollowersURL string `json:"followers_url"`
|
||||||
|
FollowingURL string `json:"following_url"`
|
||||||
|
GistsURL string `json:"gists_url"`
|
||||||
|
StarredURL string `json:"starred_url"`
|
||||||
|
SubscriptionsURL string `json:"subscriptions_url"`
|
||||||
|
OrganizationsURL string `json:"organizations_url"`
|
||||||
|
ReposURL string `json:"repos_url"`
|
||||||
|
EventsURL string `json:"events_url"`
|
||||||
|
ReceivedEventsURL string `json:"received_events_url"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
SiteAdmin bool `json:"site_admin"`
|
||||||
|
} `json:"owner"`
|
||||||
|
Private bool `json:"private"`
|
||||||
|
HTMLURL string `json:"html_url"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Fork bool `json:"fork"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
ForksURL string `json:"forks_url"`
|
||||||
|
KeysURL string `json:"keys_url"`
|
||||||
|
CollaboratorsURL string `json:"collaborators_url"`
|
||||||
|
TeamsURL string `json:"teams_url"`
|
||||||
|
HooksURL string `json:"hooks_url"`
|
||||||
|
IssueEventsURL string `json:"issue_events_url"`
|
||||||
|
EventsURL string `json:"events_url"`
|
||||||
|
AssigneesURL string `json:"assignees_url"`
|
||||||
|
BranchesURL string `json:"branches_url"`
|
||||||
|
TagsURL string `json:"tags_url"`
|
||||||
|
BlobsURL string `json:"blobs_url"`
|
||||||
|
GitTagsURL string `json:"git_tags_url"`
|
||||||
|
GitRefsURL string `json:"git_refs_url"`
|
||||||
|
TreesURL string `json:"trees_url"`
|
||||||
|
StatusesURL string `json:"statuses_url"`
|
||||||
|
LanguagesURL string `json:"languages_url"`
|
||||||
|
StargazersURL string `json:"stargazers_url"`
|
||||||
|
ContributorsURL string `json:"contributors_url"`
|
||||||
|
SubscribersURL string `json:"subscribers_url"`
|
||||||
|
SubscriptionURL string `json:"subscription_url"`
|
||||||
|
CommitsURL string `json:"commits_url"`
|
||||||
|
GitCommitsURL string `json:"git_commits_url"`
|
||||||
|
CommentsURL string `json:"comments_url"`
|
||||||
|
IssueCommentURL string `json:"issue_comment_url"`
|
||||||
|
ContentsURL string `json:"contents_url"`
|
||||||
|
CompareURL string `json:"compare_url"`
|
||||||
|
MergesURL string `json:"merges_url"`
|
||||||
|
ArchiveURL string `json:"archive_url"`
|
||||||
|
DownloadsURL string `json:"downloads_url"`
|
||||||
|
IssuesURL string `json:"issues_url"`
|
||||||
|
PullsURL string `json:"pulls_url"`
|
||||||
|
MilestonesURL string `json:"milestones_url"`
|
||||||
|
NotificationsURL string `json:"notifications_url"`
|
||||||
|
LabelsURL string `json:"labels_url"`
|
||||||
|
ReleasesURL string `json:"releases_url"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
PushedAt time.Time `json:"pushed_at"`
|
||||||
|
GitURL string `json:"git_url"`
|
||||||
|
SSHURL string `json:"ssh_url"`
|
||||||
|
CloneURL string `json:"clone_url"`
|
||||||
|
SvnURL string `json:"svn_url"`
|
||||||
|
Homepage *string `json:"homepage"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
StargazersCount int64 `json:"stargazers_count"`
|
||||||
|
WatchersCount int64 `json:"watchers_count"`
|
||||||
|
Language *string `json:"language"`
|
||||||
|
HasIssues bool `json:"has_issues"`
|
||||||
|
HasDownloads bool `json:"has_downloads"`
|
||||||
|
HasWiki bool `json:"has_wiki"`
|
||||||
|
HasPages bool `json:"has_pages"`
|
||||||
|
ForksCount int64 `json:"forks_count"`
|
||||||
|
MirrorURL *string `json:"mirror_url"`
|
||||||
|
OpenIssuesCount int64 `json:"open_issues_count"`
|
||||||
|
Forks int64 `json:"forks"`
|
||||||
|
OpenIssues int64 `json:"open_issues"`
|
||||||
|
Watchers int64 `json:"watchers"`
|
||||||
|
DefaultBranch string `json:"default_branch"`
|
||||||
|
} `json:"repository"`
|
||||||
|
Sender struct {
|
||||||
|
Login string `json:"login"`
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
NodeID string `json:"node_id"`
|
||||||
|
AvatarURL string `json:"avatar_url"`
|
||||||
|
GravatarID string `json:"gravatar_id"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
HTMLURL string `json:"html_url"`
|
||||||
|
FollowersURL string `json:"followers_url"`
|
||||||
|
FollowingURL string `json:"following_url"`
|
||||||
|
GistsURL string `json:"gists_url"`
|
||||||
|
StarredURL string `json:"starred_url"`
|
||||||
|
SubscriptionsURL string `json:"subscriptions_url"`
|
||||||
|
OrganizationsURL string `json:"organizations_url"`
|
||||||
|
ReposURL string `json:"repos_url"`
|
||||||
|
EventsURL string `json:"events_url"`
|
||||||
|
ReceivedEventsURL string `json:"received_events_url"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
SiteAdmin bool `json:"site_admin"`
|
||||||
|
} `json:"sender"`
|
||||||
|
}
|
||||||
|
|
||||||
// MilestonePayload contains the information for GitHub's milestone hook event
|
// MilestonePayload contains the information for GitHub's milestone hook event
|
||||||
type MilestonePayload struct {
|
type MilestonePayload struct {
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
@@ -5139,6 +5270,9 @@ type ReleasePayload struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
SiteAdmin bool `json:"site_admin"`
|
SiteAdmin bool `json:"site_admin"`
|
||||||
} `json:"sender"`
|
} `json:"sender"`
|
||||||
|
Installation struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
} `json:"installation"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepositoryPayload contains the information for GitHub's repository hook event
|
// RepositoryPayload contains the information for GitHub's repository hook event
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
{
|
||||||
|
"action": "removed",
|
||||||
|
"installation": {
|
||||||
|
"id": 2,
|
||||||
|
"account": {
|
||||||
|
"login": "octocat",
|
||||||
|
"id": 1,
|
||||||
|
"node_id": "MDQ6VXNlcjE=",
|
||||||
|
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
||||||
|
"gravatar_id": "",
|
||||||
|
"url": "https://api.github.com/users/octocat",
|
||||||
|
"html_url": "https://github.com/octocat",
|
||||||
|
"followers_url": "https://api.github.com/users/octocat/followers",
|
||||||
|
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
|
||||||
|
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
|
||||||
|
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
|
||||||
|
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
|
||||||
|
"organizations_url": "https://api.github.com/users/octocat/orgs",
|
||||||
|
"repos_url": "https://api.github.com/users/octocat/repos",
|
||||||
|
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
|
||||||
|
"received_events_url": "https://api.github.com/users/octocat/received_events",
|
||||||
|
"type": "User",
|
||||||
|
"site_admin": false
|
||||||
|
},
|
||||||
|
"repository_selection": "selected",
|
||||||
|
"access_tokens_url": "https://api.github.com/installations/2/access_tokens",
|
||||||
|
"repositories_url": "https://api.github.com/installation/repositories",
|
||||||
|
"html_url": "https://github.com/settings/installations/2",
|
||||||
|
"app_id": 5725,
|
||||||
|
"target_id": 3880403,
|
||||||
|
"target_type": "User",
|
||||||
|
"permissions": {
|
||||||
|
"metadata": "read",
|
||||||
|
"contents": "read",
|
||||||
|
"issues": "write"
|
||||||
|
},
|
||||||
|
"events": [
|
||||||
|
"push",
|
||||||
|
"pull_request"
|
||||||
|
],
|
||||||
|
"created_at": 1525109898,
|
||||||
|
"updated_at": 1525109899,
|
||||||
|
"single_file_name": "config.yml"
|
||||||
|
},
|
||||||
|
"repository_selection": "selected",
|
||||||
|
"repositories_added": [],
|
||||||
|
"repositories_removed": [
|
||||||
|
{
|
||||||
|
"id": 1296269,
|
||||||
|
"name": "Hello-World",
|
||||||
|
"full_name": "octocat/Hello-World",
|
||||||
|
"private": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"sender": {
|
||||||
|
"login": "octocat",
|
||||||
|
"id": 1,
|
||||||
|
"node_id": "MDQ6VXNlcjE=",
|
||||||
|
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
||||||
|
"gravatar_id": "",
|
||||||
|
"url": "https://api.github.com/users/octocat",
|
||||||
|
"html_url": "https://github.com/octocat",
|
||||||
|
"followers_url": "https://api.github.com/users/octocat/followers",
|
||||||
|
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
|
||||||
|
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
|
||||||
|
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
|
||||||
|
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
|
||||||
|
"organizations_url": "https://api.github.com/users/octocat/orgs",
|
||||||
|
"repos_url": "https://api.github.com/users/octocat/repos",
|
||||||
|
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
|
||||||
|
"received_events_url": "https://api.github.com/users/octocat/received_events",
|
||||||
|
"type": "User",
|
||||||
|
"site_admin": false
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user