Repository navigation
Add support for integration service #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this line, could you please add: |
||
|
|
||
| i := new([]*Installation) | ||
| resp, err := s.client.Do(req, &i) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return *i, resp, err | ||
| } | ||
| 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) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this line, could you please add: |
||
|
|
||
| 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 | ||
| } | ||
| 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) | ||
| } | ||
| } |
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
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/.
There was a problem hiding this comment.
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.