Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions github/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,6 @@ type IntegrationInstallationRepositoriesEvent struct {
Sender *User `json:"sender,omitempty"`
}

// Installation represents a GitHub integration installation.
type Installation struct {
ID *int `json:"id,omitempty"`
Account *User `json:"account,omitempty"`
AccessTokensURL *string `json:"access_tokens_url,omitempty"`
RepositoriesURL *string `json:"repositories_url,omitempty"`
}

// IssueCommentEvent is triggered when an issue comment is created on an issue
// or pull request.
// The Webhook event name is "issue_comment".
Expand Down
5 changes: 5 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ const (

// https://developer.github.com/changes/2016-09-14-projects-api/
mediaTypeProjectsPreview = "application/vnd.github.inertia-preview+json"

// https://developer.github.com/v3/integrations/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extremely minor, but most other comments above link to the changes page corresponding to the accept header value. So this could be https://developer.github.com/changes/2016-09-14-Integrations-Early-Access/.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @shurcooL - I can address this one in my merge.

mediaTypeIntegrationPreview = "application/vnd.github.machine-man-preview+json"
)

// A Client manages communication with the GitHub API.
Expand Down Expand Up @@ -120,6 +123,7 @@ type Client struct {
Gists *GistsService
Git *GitService
Gitignores *GitignoresService
Integrations *IntegrationsService
Issues *IssuesService
Organizations *OrganizationsService
PullRequests *PullRequestsService
Expand Down Expand Up @@ -190,6 +194,7 @@ func NewClient(httpClient *http.Client) *Client {
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)
Expand Down
38 changes: 38 additions & 0 deletions github/integration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2016 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

// IntegrationsService provides access to the installation related functions
// in the GitHub API.
//
// GitHub API docs: https://developer.github.com/v3/integrations/
type IntegrationsService service

// ListInstallations lists the installations that the current integration has.
//
// GitHub API docs: https://developer.github.com/v3/integrations/#find-installations
func (s *IntegrationsService) ListInstallations(opt *ListOptions) ([]*Installation, *Response, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a test function for this one?

u, err := addOptions("integration/installations", opt)
if err != nil {
return nil, nil, err
}

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeIntegrationPreview)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this line, could you please add:
// TODO: remove custom Accept header when this API fully launches.


i := new([]*Installation)
resp, err := s.client.Do(req, &i)
if err != nil {
return nil, resp, err
}

return *i, resp, err
}
46 changes: 46 additions & 0 deletions github/integration_installation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2016 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

// Installation represents a GitHub integration installation.
type Installation struct {
ID *int `json:"id,omitempty"`
Account *User `json:"account,omitempty"`
AccessTokensURL *string `json:"access_tokens_url,omitempty"`
RepositoriesURL *string `json:"repositories_url,omitempty"`
}

func (i Installation) String() string {
return Stringify(i)
}

// ListRepos lists the repositories that the current installation has access to.
//
// GitHub API docs: https://developer.github.com/v3/integrations/installations/#list-repositories
func (s *IntegrationsService) ListRepos(opt *ListOptions) ([]*Repository, *Response, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a test function for this one?

u, err := addOptions("installation/repositories", opt)
if err != nil {
return nil, nil, err
}

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeIntegrationPreview)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this line, could you please add:
// TODO: remove custom Accept header when this API fully launches.


var r struct {
Repositories []*Repository `json:"repositories"`
}
resp, err := s.client.Do(req, &r)
if err != nil {
return nil, resp, err
}

return r.Repositories, resp, err
}
39 changes: 39 additions & 0 deletions github/integration_installation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2016 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
"fmt"
"net/http"
"reflect"
"testing"
)

func TestIntegrationService_ListRepos(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/installation/repositories", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeIntegrationPreview)
testFormValues(t, r, values{
"page": "1",
"per_page": "2",
})
fmt.Fprint(w, `{"repositories": [{"id":1}]}`)
})

opt := &ListOptions{Page: 1, PerPage: 2}
repositories, _, err := client.Integrations.ListRepos(opt)
if err != nil {
t.Errorf("Integration.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)
}
}
39 changes: 39 additions & 0 deletions github/integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2016 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
"fmt"
"net/http"
"reflect"
"testing"
)

func TestIntegrationService_ListInstallations(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/integration/installations", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeIntegrationPreview)
testFormValues(t, r, values{
"page": "1",
"per_page": "2",
})
fmt.Fprint(w, `[{"id":1}]`)
})

opt := &ListOptions{Page: 1, PerPage: 2}
installations, _, err := client.Integrations.ListInstallations(opt)
if err != nil {
t.Errorf("Integration.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)
}
}