diff --git a/github/activity_events.go b/github/activity_events.go index ea5a498cfa1..6b35056f404 100644 --- a/github/activity_events.go +++ b/github/activity_events.go @@ -46,10 +46,10 @@ func (e *Event) ParsePayload() (payload interface{}, err error) { payload = &ForkEvent{} case "GollumEvent": payload = &GollumEvent{} - case "IntegrationInstallationEvent": - payload = &IntegrationInstallationEvent{} - case "IntegrationInstallationRepositoriesEvent": - payload = &IntegrationInstallationRepositoriesEvent{} + case "InstallationEvent": + payload = &InstallationEvent{} + case "InstallationRepositoriesEvent": + payload = &InstallationRepositoriesEvent{} case "IssueCommentEvent": payload = &IssueCommentEvent{} case "IssuesEvent": diff --git a/github/integration.go b/github/apps.go similarity index 54% rename from github/integration.go rename to github/apps.go index 6d74e44f007..ff3389382ee 100644 --- a/github/integration.go +++ b/github/apps.go @@ -7,17 +7,17 @@ package github import "context" -// IntegrationsService provides access to the installation related functions +// AppsService provides access to the installation related functions // in the GitHub API. // -// GitHub API docs: https://developer.github.com/v3/integrations/ -type IntegrationsService service +// GitHub API docs: https://developer.github.com/v3/apps/ +type AppsService service -// ListInstallations lists the installations that the current integration has. +// ListInstallations lists the installations that the current GitHub App has. // -// GitHub API docs: https://developer.github.com/v3/integrations/#find-installations -func (s *IntegrationsService) ListInstallations(ctx context.Context, opt *ListOptions) ([]*Installation, *Response, error) { - u, err := addOptions("integration/installations", opt) +// GitHub API docs: https://developer.github.com/v3/apps/#find-installations +func (s *AppsService) ListInstallations(ctx context.Context, opt *ListOptions) ([]*Installation, *Response, error) { + u, err := addOptions("app/installations", opt) if err != nil { return nil, nil, err } diff --git a/github/integration_installation.go b/github/apps_installation.go similarity index 75% rename from github/integration_installation.go rename to github/apps_installation.go index 0836d86d1d4..6a277995315 100644 --- a/github/integration_installation.go +++ b/github/apps_installation.go @@ -7,7 +7,7 @@ package github import "context" -// Installation represents a GitHub integration installation. +// Installation represents a GitHub Apps installation. type Installation struct { ID *int `json:"id,omitempty"` Account *User `json:"account,omitempty"` @@ -20,10 +20,10 @@ func (i Installation) String() string { return Stringify(i) } -// ListRepos lists the repositories that the current installation has access to. +// ListRepos lists the repositories that are accessible to the authenticated installation. // -// GitHub API docs: https://developer.github.com/v3/integrations/installations/#list-repositories -func (s *IntegrationsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repository, *Response, error) { +// GitHub API docs: https://developer.github.com/v3/apps/installations/#list-repositories +func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repository, *Response, error) { u, err := addOptions("installation/repositories", opt) if err != nil { return nil, nil, err diff --git a/github/integration_installation_test.go b/github/apps_installation_test.go similarity index 72% rename from github/integration_installation_test.go rename to github/apps_installation_test.go index 05f101677c8..462d15a3f29 100644 --- a/github/integration_installation_test.go +++ b/github/apps_installation_test.go @@ -13,7 +13,7 @@ import ( "testing" ) -func TestIntegrationService_ListRepos(t *testing.T) { +func TestAppsService_ListRepos(t *testing.T) { setup() defer teardown() @@ -28,13 +28,13 @@ func TestIntegrationService_ListRepos(t *testing.T) { }) opt := &ListOptions{Page: 1, PerPage: 2} - repositories, _, err := client.Integrations.ListRepos(context.Background(), opt) + repositories, _, err := client.Apps.ListRepos(context.Background(), opt) if err != nil { - t.Errorf("Integration.ListRepos returned error: %v", err) + t.Errorf("Apps.ListRepos returned error: %v", err) } want := []*Repository{{ID: Int(1)}} if !reflect.DeepEqual(repositories, want) { - t.Errorf("Integration.ListRepos returned %+v, want %+v", repositories, want) + t.Errorf("Apps.ListRepos returned %+v, want %+v", repositories, want) } } diff --git a/github/integration_test.go b/github/apps_test.go similarity index 60% rename from github/integration_test.go rename to github/apps_test.go index 09ea304948a..f847b84271c 100644 --- a/github/integration_test.go +++ b/github/apps_test.go @@ -13,11 +13,11 @@ import ( "testing" ) -func TestIntegrationService_ListInstallations(t *testing.T) { +func TestAppsService_ListInstallations(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/integration/installations", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/app/installations", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testHeader(t, r, "Accept", mediaTypeIntegrationPreview) testFormValues(t, r, values{ @@ -28,13 +28,13 @@ func TestIntegrationService_ListInstallations(t *testing.T) { }) opt := &ListOptions{Page: 1, PerPage: 2} - installations, _, err := client.Integrations.ListInstallations(context.Background(), opt) + installations, _, err := client.Apps.ListInstallations(context.Background(), opt) if err != nil { - t.Errorf("Integration.ListInstallations returned error: %v", err) + t.Errorf("Apps.ListInstallations returned error: %v", err) } want := []*Installation{{ID: Int(1)}} if !reflect.DeepEqual(installations, want) { - t.Errorf("Integration.ListInstallations returned %+v, want %+v", installations, want) + t.Errorf("Apps.ListInstallations returned %+v, want %+v", installations, want) } } diff --git a/github/event_types.go b/github/event_types.go index 61f8a69aa23..c6b29b9a242 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -187,28 +187,27 @@ type TeamChange struct { } `json:"repository,omitempty"` } -// IntegrationInstallationEvent is triggered when an integration is created or deleted. -// The Webhook event name is "integration_installation". +// InstallationEvent is triggered when a GitHub App has been installed or uninstalled. +// The Webhook event name is "installation". // -// GitHub API docs: https://developer.github.com/early-access/integrations/webhooks/#integrationinstallationevent -type IntegrationInstallationEvent struct { - // The action that was performed. Possible values for an "integration_installation" - // event are: "created", "deleted". +// GitHub API docs: https://developer.github.com/v3/activity/events/types/#installationevent +type InstallationEvent struct { + // The action that was performed. Can be either "created" or "deleted". Action *string `json:"action,omitempty"` Sender *User `json:"sender,omitempty"` Installation *Installation `json:"installation,omitempty"` } -// IntegrationInstallationRepositoriesEvent is triggered when an integration repository -// is added or removed. The Webhook event name is "integration_installation_repositories". +// InstallationRepositoriesEvent is triggered when a repository is added or +// removed from an installation. The Webhook event name is "installation_repositories". // -// GitHub API docs: https://developer.github.com/early-access/integrations/webhooks/#integrationinstallationrepositoriesevent -type IntegrationInstallationRepositoriesEvent struct { - // The action that was performed. Possible values for an "integration_installation_repositories" - // event are: "added", "removed". +// GitHub API docs: https://developer.github.com/v3/activity/events/types/#installationrepositoriesevent +type InstallationRepositoriesEvent struct { + // The action that was performed. Can be either "added" or "removed". Action *string `json:"action,omitempty"` RepositoriesAdded []*Repository `json:"repositories_added,omitempty"` RepositoriesRemoved []*Repository `json:"repositories_removed,omitempty"` + RepositorySelection *string `json:"repository_selection,omitempty"` Sender *User `json:"sender,omitempty"` Installation *Installation `json:"installation,omitempty"` } diff --git a/github/github-accessors.go b/github/github-accessors.go index 145b17feccb..206d621c4d9 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -1981,7 +1981,7 @@ func (i *Installation) GetRepositoriesURL() string { } // GetAction returns the Action field if it's non-nil, zero value otherwise. -func (i *IntegrationInstallationEvent) GetAction() string { +func (i *InstallationEvent) GetAction() string { if i == nil || i.Action == nil { return "" } @@ -1989,13 +1989,21 @@ func (i *IntegrationInstallationEvent) GetAction() string { } // GetAction returns the Action field if it's non-nil, zero value otherwise. -func (i *IntegrationInstallationRepositoriesEvent) GetAction() string { +func (i *InstallationRepositoriesEvent) GetAction() string { if i == nil || i.Action == nil { return "" } return *i.Action } +// GetRepositorySelection returns the RepositorySelection field if it's non-nil, zero value otherwise. +func (i *InstallationRepositoriesEvent) GetRepositorySelection() string { + if i == nil || i.RepositorySelection == nil { + return "" + } + return *i.RepositorySelection +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (i *Invitation) GetCreatedAt() time.Time { if i == nil || i.CreatedAt == nil { diff --git a/github/github.go b/github/github.go index 315e2562845..409710da6f7 100644 --- a/github/github.go +++ b/github/github.go @@ -27,7 +27,7 @@ import ( ) const ( - libraryVersion = "7" + libraryVersion = "8" defaultBaseURL = "https://api.github.com/" uploadBaseURL = "https://uploads.github.com/" userAgent = "go-github/" + libraryVersion @@ -123,11 +123,11 @@ type Client struct { // Services used for talking to different parts of the GitHub API. Activity *ActivityService Admin *AdminService + Apps *AppsService Authorizations *AuthorizationsService Gists *GistsService Git *GitService Gitignores *GitignoresService - Integrations *IntegrationsService Issues *IssuesService Organizations *OrganizationsService Projects *ProjectsService @@ -212,11 +212,11 @@ func NewClient(httpClient *http.Client) *Client { c.common.client = c c.Activity = (*ActivityService)(&c.common) c.Admin = (*AdminService)(&c.common) + c.Apps = (*AppsService)(&c.common) c.Authorizations = (*AuthorizationsService)(&c.common) c.Gists = (*GistsService)(&c.common) c.Git = (*GitService)(&c.common) c.Gitignores = (*GitignoresService)(&c.common) - c.Integrations = (*IntegrationsService)(&c.common) c.Issues = (*IssuesService)(&c.common) c.Licenses = (*LicensesService)(&c.common) c.Migrations = (*MigrationService)(&c.common) diff --git a/github/messages.go b/github/messages.go index 9c0468ff04c..c0f315a7782 100644 --- a/github/messages.go +++ b/github/messages.go @@ -40,39 +40,39 @@ const ( var ( // eventTypeMapping maps webhooks types to their corresponding go-github struct types. eventTypeMapping = map[string]string{ - "commit_comment": "CommitCommentEvent", - "create": "CreateEvent", - "delete": "DeleteEvent", - "deployment": "DeploymentEvent", - "deployment_status": "DeploymentStatusEvent", - "fork": "ForkEvent", - "gollum": "GollumEvent", - "integration_installation": "IntegrationInstallationEvent", - "integration_installation_repositories": "IntegrationInstallationRepositoriesEvent", - "issue_comment": "IssueCommentEvent", - "issues": "IssuesEvent", - "label": "LabelEvent", - "member": "MemberEvent", - "membership": "MembershipEvent", - "milestone": "MilestoneEvent", - "organization": "OrganizationEvent", - "org_block": "OrgBlockEvent", - "page_build": "PageBuildEvent", - "ping": "PingEvent", - "project": "ProjectEvent", - "project_card": "ProjectCardEvent", - "project_column": "ProjectColumnEvent", - "public": "PublicEvent", - "pull_request_review": "PullRequestReviewEvent", - "pull_request_review_comment": "PullRequestReviewCommentEvent", - "pull_request": "PullRequestEvent", - "push": "PushEvent", - "repository": "RepositoryEvent", - "release": "ReleaseEvent", - "status": "StatusEvent", - "team": "TeamEvent", - "team_add": "TeamAddEvent", - "watch": "WatchEvent", + "commit_comment": "CommitCommentEvent", + "create": "CreateEvent", + "delete": "DeleteEvent", + "deployment": "DeploymentEvent", + "deployment_status": "DeploymentStatusEvent", + "fork": "ForkEvent", + "gollum": "GollumEvent", + "installation": "InstallationEvent", + "installation_repositories": "InstallationRepositoriesEvent", + "issue_comment": "IssueCommentEvent", + "issues": "IssuesEvent", + "label": "LabelEvent", + "member": "MemberEvent", + "membership": "MembershipEvent", + "milestone": "MilestoneEvent", + "organization": "OrganizationEvent", + "org_block": "OrgBlockEvent", + "page_build": "PageBuildEvent", + "ping": "PingEvent", + "project": "ProjectEvent", + "project_card": "ProjectCardEvent", + "project_column": "ProjectColumnEvent", + "public": "PublicEvent", + "pull_request_review": "PullRequestReviewEvent", + "pull_request_review_comment": "PullRequestReviewCommentEvent", + "pull_request": "PullRequestEvent", + "push": "PushEvent", + "repository": "RepositoryEvent", + "release": "ReleaseEvent", + "status": "StatusEvent", + "team": "TeamEvent", + "team_add": "TeamAddEvent", + "watch": "WatchEvent", } ) diff --git a/github/messages_test.go b/github/messages_test.go index 5a5b3032df0..5f348f2aa6f 100644 --- a/github/messages_test.go +++ b/github/messages_test.go @@ -116,6 +116,14 @@ func TestParseWebHook(t *testing.T) { payload: &GollumEvent{}, messageType: "gollum", }, + { + payload: &InstallationEvent{}, + messageType: "installation", + }, + { + payload: &InstallationRepositoriesEvent{}, + messageType: "installation_repositories", + }, { payload: &IssueCommentEvent{}, messageType: "issue_comment",