From 26af15f0e6bf76efa2ec3fa000b263f3217d3292 Mon Sep 17 00:00:00 2001 From: Tom Anderson Date: Thu, 1 Aug 2019 14:15:31 -0700 Subject: [PATCH] Adding support for event integration_installation_repositories --- github/github.go | 79 ++++++++++--------- github/github_test.go | 10 +++ ...integration-installation-repositories.json | 75 ++++++++++++++++++ 3 files changed, 125 insertions(+), 39 deletions(-) create mode 100644 testdata/github/integration-installation-repositories.json diff --git a/github/github.go b/github/github.go index be825a6..08e72d1 100644 --- a/github/github.go +++ b/github/github.go @@ -28,44 +28,45 @@ type Event string // GitHub hook types const ( - CheckRunEvent Event = "check_run" - CheckSuiteEvent Event = "check_suite" - CommitCommentEvent Event = "commit_comment" - CreateEvent Event = "create" - DeleteEvent Event = "delete" - DeploymentEvent Event = "deployment" - DeploymentStatusEvent Event = "deployment_status" - ForkEvent Event = "fork" - GollumEvent Event = "gollum" - InstallationEvent Event = "installation" - InstallationRepositoriesEvent Event = "installation_repositories" - IntegrationInstallationEvent Event = "integration_installation" - IssueCommentEvent Event = "issue_comment" - IssuesEvent Event = "issues" - LabelEvent Event = "label" - MemberEvent Event = "member" - MembershipEvent Event = "membership" - MilestoneEvent Event = "milestone" - OrganizationEvent Event = "organization" - OrgBlockEvent Event = "org_block" - PageBuildEvent Event = "page_build" - PingEvent Event = "ping" - ProjectCardEvent Event = "project_card" - ProjectColumnEvent Event = "project_column" - ProjectEvent Event = "project" - PublicEvent Event = "public" - PullRequestEvent Event = "pull_request" - PullRequestReviewEvent Event = "pull_request_review" - PullRequestReviewCommentEvent Event = "pull_request_review_comment" - PushEvent Event = "push" - ReleaseEvent Event = "release" - RepositoryEvent Event = "repository" - RepositoryVulnerabilityAlertEvent Event = "repository_vulnerability_alert" - SecurityAdvisoryEvent Event = "security_advisory" - StatusEvent Event = "status" - TeamEvent Event = "team" - TeamAddEvent Event = "team_add" - WatchEvent Event = "watch" + CheckRunEvent Event = "check_run" + CheckSuiteEvent Event = "check_suite" + CommitCommentEvent Event = "commit_comment" + CreateEvent Event = "create" + DeleteEvent Event = "delete" + DeploymentEvent Event = "deployment" + DeploymentStatusEvent Event = "deployment_status" + ForkEvent Event = "fork" + GollumEvent Event = "gollum" + InstallationEvent Event = "installation" + InstallationRepositoriesEvent Event = "installation_repositories" + IntegrationInstallationEvent Event = "integration_installation" + IntegrationInstallationRepositoriesEvent Event = "integration_installation_repositories" + IssueCommentEvent Event = "issue_comment" + IssuesEvent Event = "issues" + LabelEvent Event = "label" + MemberEvent Event = "member" + MembershipEvent Event = "membership" + MilestoneEvent Event = "milestone" + OrganizationEvent Event = "organization" + OrgBlockEvent Event = "org_block" + PageBuildEvent Event = "page_build" + PingEvent Event = "ping" + ProjectCardEvent Event = "project_card" + ProjectColumnEvent Event = "project_column" + ProjectEvent Event = "project" + PublicEvent Event = "public" + PullRequestEvent Event = "pull_request" + PullRequestReviewEvent Event = "pull_request_review" + PullRequestReviewCommentEvent Event = "pull_request_review_comment" + PushEvent Event = "push" + ReleaseEvent Event = "release" + RepositoryEvent Event = "repository" + RepositoryVulnerabilityAlertEvent Event = "repository_vulnerability_alert" + SecurityAdvisoryEvent Event = "security_advisory" + StatusEvent Event = "status" + TeamEvent Event = "team" + TeamAddEvent Event = "team_add" + WatchEvent Event = "watch" ) // EventSubtype defines a GitHub Hook Event subtype @@ -206,7 +207,7 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) var pl InstallationPayload err = json.Unmarshal([]byte(payload), &pl) return pl, err - case InstallationRepositoriesEvent: + case InstallationRepositoriesEvent, IntegrationInstallationRepositoriesEvent: var pl InstallationRepositoriesPayload err = json.Unmarshal([]byte(payload), &pl) return pl, err diff --git a/github/github_test.go b/github/github_test.go index 6fbb716..7e52335 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -253,6 +253,16 @@ func TestWebhooks(t *testing.T) { "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", event: IssueCommentEvent, diff --git a/testdata/github/integration-installation-repositories.json b/testdata/github/integration-installation-repositories.json new file mode 100644 index 0000000..5a3113e --- /dev/null +++ b/testdata/github/integration-installation-repositories.json @@ -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 + } +} \ No newline at end of file