From aa10fb4f18e4a565d1cd5be58b92b42d22701520 Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Mon, 21 Aug 2017 22:25:37 -0400 Subject: [PATCH 01/35] Added my name to AUTHORS list. --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index f521b6df24..b31fb2ab70 100644 --- a/AUTHORS +++ b/AUTHORS @@ -69,6 +69,7 @@ i2bskn Isao Jonas isqua Jameel Haffejee +Jeremy Morris Jihoon Chung Joe Tsai John Engelman From 7772ba0c5a8f9c84400c25d9f4c42f1974d62136 Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Mon, 21 Aug 2017 23:04:00 -0400 Subject: [PATCH 02/35] Added API route for adding a repo to an installation. --- github/apps.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/github/apps.go b/github/apps.go index ff3389382e..044ab8c39e 100644 --- a/github/apps.go +++ b/github/apps.go @@ -38,3 +38,26 @@ func (s *AppsService) ListInstallations(ctx context.Context, opt *ListOptions) ( return i, resp, nil } + +// AddRepository adds a single repository to an installation. +// +// GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation +func (s *AppService) AddRepository(ctx context.Context, installationID int, repoID int) (*Installation, *Response, error) { + u := fmt.Sprintf("app/installations/%v/repositories/%v", installationID, repoID) + + req, err := s.client.NewRequest("PUT", u, nil) { + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeIntegrationPreview) + + i := new(Installation) + resp, err := s.client.Do(ctx, req, i) + if err != nil { + return nil, resp, err + } + + return i, resp, nil +} \ No newline at end of file From 5d99cdf1d1e46c3ccbfbfa8e8318539f23df37a3 Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Mon, 21 Aug 2017 23:08:01 -0400 Subject: [PATCH 03/35] Added api route for removing repo from installation. --- github/apps.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/github/apps.go b/github/apps.go index 044ab8c39e..167ec55186 100644 --- a/github/apps.go +++ b/github/apps.go @@ -59,5 +59,28 @@ func (s *AppService) AddRepository(ctx context.Context, installationID int, repo return nil, resp, err } + return i, resp, nil +} + +// RemoveRepository removes a single repository from an installation. +// +// GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation +func (s *AppService) RemoveRepository(ctx context.Context, installationID int, repoID int) (*Installation, *Response, error) { + u := fmt.Sprintf("app/installations/%v/repositories/%v", installationID, repoID) + + req, err := s.client.NewRequest("DELETE", u, nil) { + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeIntegrationPreview) + + i := new(Installation) + resp, err := s.client.Do(ctx, req, i) + if err != nil { + return nil, resp, err + } + return i, resp, nil } \ No newline at end of file From 2eab2b3a63b656f3e10fabb8496bcd037f0bd096 Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Mon, 21 Aug 2017 23:16:15 -0400 Subject: [PATCH 04/35] Moved Add/Remove Repository functions to app_installation. --- github/apps.go | 46 -------------------------------- github/apps_installation.go | 46 ++++++++++++++++++++++++++++++++ github/apps_installation_test.go | 11 ++++++++ github/apps_test.go | 2 +- 4 files changed, 58 insertions(+), 47 deletions(-) diff --git a/github/apps.go b/github/apps.go index 167ec55186..4c3e7c648a 100644 --- a/github/apps.go +++ b/github/apps.go @@ -36,51 +36,5 @@ func (s *AppsService) ListInstallations(ctx context.Context, opt *ListOptions) ( return nil, resp, err } - return i, resp, nil -} - -// AddRepository adds a single repository to an installation. -// -// GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppService) AddRepository(ctx context.Context, installationID int, repoID int) (*Installation, *Response, error) { - u := fmt.Sprintf("app/installations/%v/repositories/%v", installationID, repoID) - - req, err := s.client.NewRequest("PUT", u, nil) { - if err != nil { - return nil, nil, err - } - - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeIntegrationPreview) - - i := new(Installation) - resp, err := s.client.Do(ctx, req, i) - if err != nil { - return nil, resp, err - } - - return i, resp, nil -} - -// RemoveRepository removes a single repository from an installation. -// -// GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppService) RemoveRepository(ctx context.Context, installationID int, repoID int) (*Installation, *Response, error) { - u := fmt.Sprintf("app/installations/%v/repositories/%v", installationID, repoID) - - req, err := s.client.NewRequest("DELETE", u, nil) { - if err != nil { - return nil, nil, err - } - - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeIntegrationPreview) - - i := new(Installation) - resp, err := s.client.Do(ctx, req, i) - if err != nil { - return nil, resp, err - } - return i, resp, nil } \ No newline at end of file diff --git a/github/apps_installation.go b/github/apps_installation.go index 6a27799531..5aab26a7e9 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -47,3 +47,49 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos return r.Repositories, resp, nil } + +// AddRepository adds a single repository to an installation. +// +// GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation +func (s *AppService) AddRepository(ctx context.Context, installationID int, repoID int) (*Installation, *Response, error) { + u := fmt.Sprintf("app/installations/%v/repositories/%v", installationID, repoID) + + req, err := s.client.NewRequest("PUT", u, nil) { + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeIntegrationPreview) + + i := new(Installation) + resp, err := s.client.Do(ctx, req, i) + if err != nil { + return nil, resp, err + } + + return i, resp, nil +} + +// RemoveRepository removes a single repository from an installation. +// +// GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation +func (s *AppService) RemoveRepository(ctx context.Context, installationID int, repoID int) (*Installation, *Response, error) { + u := fmt.Sprintf("app/installations/%v/repositories/%v", installationID, repoID) + + req, err := s.client.NewRequest("DELETE", u, nil) { + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeIntegrationPreview) + + i := new(Installation) + resp, err := s.client.Do(ctx, req, i) + if err != nil { + return nil, resp, err + } + + return i, resp, nil +} \ No newline at end of file diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index 462d15a3f2..b343ab2b33 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -38,3 +38,14 @@ func TestAppsService_ListRepos(t *testing.T) { t.Errorf("Apps.ListRepos returned %+v, want %+v", repositories, want) } } + +func TestAppsService_AddRepository(t *testing.T) { + setup() + defer teardown() + + input := & +} + +func TestAppsService_RemoveRepository(t *testing.T) { + +} \ No newline at end of file diff --git a/github/apps_test.go b/github/apps_test.go index f847b84271..e314c81868 100644 --- a/github/apps_test.go +++ b/github/apps_test.go @@ -37,4 +37,4 @@ func TestAppsService_ListInstallations(t *testing.T) { if !reflect.DeepEqual(installations, want) { t.Errorf("Apps.ListInstallations returned %+v, want %+v", installations, want) } -} +} \ No newline at end of file From a35a5666ba111f939f60aa8b04c4ef0f72d48af3 Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Mon, 21 Aug 2017 23:20:10 -0400 Subject: [PATCH 05/35] Simplified logic in remove repository. --- github/apps_installation.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index 5aab26a7e9..15172c07cb 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -74,7 +74,7 @@ func (s *AppService) AddRepository(ctx context.Context, installationID int, repo // RemoveRepository removes a single repository from an installation. // // GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppService) RemoveRepository(ctx context.Context, installationID int, repoID int) (*Installation, *Response, error) { +func (s *AppService) RemoveRepository(ctx context.Context, installationID int, repoID int) (*Response, error) { u := fmt.Sprintf("app/installations/%v/repositories/%v", installationID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) { @@ -82,14 +82,5 @@ func (s *AppService) RemoveRepository(ctx context.Context, installationID int, r return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeIntegrationPreview) - - i := new(Installation) - resp, err := s.client.Do(ctx, req, i) - if err != nil { - return nil, resp, err - } - - return i, resp, nil + return s.client.Do(ctx, req, nil) } \ No newline at end of file From 3e141430dfb9e7594077cfa92a791e4b9e8e8438 Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Mon, 21 Aug 2017 23:21:21 -0400 Subject: [PATCH 06/35] Style fix. --- github/apps_installation.go | 1 - 1 file changed, 1 deletion(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index 15172c07cb..4f4f09c6b3 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -76,7 +76,6 @@ func (s *AppService) AddRepository(ctx context.Context, installationID int, repo // GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation func (s *AppService) RemoveRepository(ctx context.Context, installationID int, repoID int) (*Response, error) { u := fmt.Sprintf("app/installations/%v/repositories/%v", installationID, repoID) - req, err := s.client.NewRequest("DELETE", u, nil) { if err != nil { return nil, nil, err From 44e0f5155cf0a09e53743662760c2c3a45c5331f Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Mon, 21 Aug 2017 23:29:19 -0400 Subject: [PATCH 07/35] Refactored function names. --- github/apps_installation.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index 4f4f09c6b3..9489ee9cd3 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -48,12 +48,11 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos return r.Repositories, resp, nil } -// AddRepository adds a single repository to an installation. +// Add a single repository to an installation. // // GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppService) AddRepository(ctx context.Context, installationID int, repoID int) (*Installation, *Response, error) { - u := fmt.Sprintf("app/installations/%v/repositories/%v", installationID, repoID) - +func (s *AppService) Add(ctx context.Context, instID int, repoID int) (*Installation, *Response, error) { + u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("PUT", u, nil) { if err != nil { return nil, nil, err @@ -71,11 +70,11 @@ func (s *AppService) AddRepository(ctx context.Context, installationID int, repo return i, resp, nil } -// RemoveRepository removes a single repository from an installation. +// Remove a single repository from an installation. // // GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppService) RemoveRepository(ctx context.Context, installationID int, repoID int) (*Response, error) { - u := fmt.Sprintf("app/installations/%v/repositories/%v", installationID, repoID) +func (s *AppService) Remove(ctx context.Context, instID int, repoID int) (*Response, error) { + u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) { if err != nil { return nil, nil, err From defe8b87ece8f050b001c9b68c5837f2c0486617 Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Mon, 21 Aug 2017 23:31:26 -0400 Subject: [PATCH 08/35] Renamed functions back to having Repository suffix. --- github/apps_installation.go | 4 ++-- github/apps_installation_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index 9489ee9cd3..dcffe71256 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -51,7 +51,7 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos // Add a single repository to an installation. // // GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppService) Add(ctx context.Context, instID int, repoID int) (*Installation, *Response, error) { +func (s *AppService) AddRepository(ctx context.Context, instID int, repoID int) (*Installation, *Response, error) { u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("PUT", u, nil) { if err != nil { @@ -73,7 +73,7 @@ func (s *AppService) Add(ctx context.Context, instID int, repoID int) (*Installa // Remove a single repository from an installation. // // GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppService) Remove(ctx context.Context, instID int, repoID int) (*Response, error) { +func (s *AppService) RemoveRepository(ctx context.Context, instID int, repoID int) (*Response, error) { u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) { if err != nil { diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index b343ab2b33..e1b8a41b86 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -39,13 +39,13 @@ func TestAppsService_ListRepos(t *testing.T) { } } -func TestAppsService_AddRepository(t *testing.T) { +func TestAppsService_Add_Repository(t *testing.T) { setup() defer teardown() input := & } -func TestAppsService_RemoveRepository(t *testing.T) { +func TestAppsService_Remove_Repository(t *testing.T) { } \ No newline at end of file From f31595aecc0d9015ee80602d4bfc995658b9cb75 Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Mon, 21 Aug 2017 23:43:44 -0400 Subject: [PATCH 09/35] Change argument from Installation to Repository. --- github/apps_installation.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index dcffe71256..cd660e4052 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -51,7 +51,7 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos // Add a single repository to an installation. // // GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppService) AddRepository(ctx context.Context, instID int, repoID int) (*Installation, *Response, error) { +func (s *AppService) AddRepository(ctx context.Context, instID int, repoID int) (*Repository, *Response, error) { u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("PUT", u, nil) { if err != nil { @@ -61,7 +61,7 @@ func (s *AppService) AddRepository(ctx context.Context, instID int, repoID int) // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeIntegrationPreview) - i := new(Installation) + i := new(Repository) resp, err := s.client.Do(ctx, req, i) if err != nil { return nil, resp, err From 5934515934c67a210f507c3b516121bcc03709df Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Mon, 21 Aug 2017 23:59:01 -0400 Subject: [PATCH 10/35] Changed variable name for Repository. --- github/apps_installation.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index cd660e4052..2c8b054c7a 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -61,13 +61,13 @@ func (s *AppService) AddRepository(ctx context.Context, instID int, repoID int) // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeIntegrationPreview) - i := new(Repository) - resp, err := s.client.Do(ctx, req, i) + r := new(Repository) + resp, err := s.client.Do(ctx, req, r) if err != nil { return nil, resp, err } - return i, resp, nil + return r, resp, nil } // Remove a single repository from an installation. From e20f019bc19a8b5998d0663ce11a64acdfba0674 Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Tue, 22 Aug 2017 00:24:39 -0400 Subject: [PATCH 11/35] Shortened function name. --- github/apps_installation.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index 2c8b054c7a..9c4d191da3 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -51,7 +51,7 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos // Add a single repository to an installation. // // GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppService) AddRepository(ctx context.Context, instID int, repoID int) (*Repository, *Response, error) { +func (s *AppService) AddRepo(ctx context.Context, instID int, repoID int) (*Repository, *Response, error) { u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("PUT", u, nil) { if err != nil { @@ -73,7 +73,7 @@ func (s *AppService) AddRepository(ctx context.Context, instID int, repoID int) // Remove a single repository from an installation. // // GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppService) RemoveRepository(ctx context.Context, instID int, repoID int) (*Response, error) { +func (s *AppService) RemoveRepo(ctx context.Context, instID int, repoID int) (*Response, error) { u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) { if err != nil { From 16bcc33d5748afbae85e9c449daa12ca801b4c4a Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Tue, 22 Aug 2017 00:42:22 -0400 Subject: [PATCH 12/35] Added tests for Add and Remove repo. --- github/apps_installation_test.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index e1b8a41b86..aba33eb6bf 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -39,13 +39,34 @@ func TestAppsService_ListRepos(t *testing.T) { } } -func TestAppsService_Add_Repository(t *testing.T) { +func TestAppsService_AddRepo(t *testing.T) { setup() defer teardown() - input := & + input := "/app/installations/1/repositories/1" + + mux.HandleFunc("/app/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + }) + + repo, _, err := client.Apps.AddRepo(context.Background(), input) + if err != nil { + t.Errorf("Apps.AddRepo returned error: %v", err) + } } -func TestAppsService_Remove_Repository(t *testing.T) { +func TestAppsService_RemoveRepo(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/app/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + }) + repositories, _, err := client.Apps.RemoveRepo(context.Background(), opt) + if err != nil { + t.Errorf("Apps.RemoveRepo returned error: %v", err) + } } \ No newline at end of file From f90fa0d9a63469e304d0f95420577e25f5d1395d Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Tue, 22 Aug 2017 00:46:18 -0400 Subject: [PATCH 13/35] Fixed golint issues. --- github/apps_installation.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index 9c4d191da3..f7bcf4dee1 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -48,12 +48,12 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos return r.Repositories, resp, nil } -// Add a single repository to an installation. +// AddRepo adds a single repository to an installation. // // GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation func (s *AppService) AddRepo(ctx context.Context, instID int, repoID int) (*Repository, *Response, error) { u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) - req, err := s.client.NewRequest("PUT", u, nil) { + req, err := s.client.NewRequest("PUT", u, nil) if err != nil { return nil, nil, err } @@ -70,12 +70,12 @@ func (s *AppService) AddRepo(ctx context.Context, instID int, repoID int) (*Repo return r, resp, nil } -// Remove a single repository from an installation. +// RemoveRepo removes a single repository from an installation. // // GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation func (s *AppService) RemoveRepo(ctx context.Context, instID int, repoID int) (*Response, error) { u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) - req, err := s.client.NewRequest("DELETE", u, nil) { + req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { return nil, nil, err } From 585efab46f55eaa8bc89df20a749ff4a17c91a6a Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Tue, 22 Aug 2017 21:26:15 -0400 Subject: [PATCH 14/35] Removed merge conflict from adding my name to list. --- AUTHORS | 3 --- 1 file changed, 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index 1362f95822..e97e992e23 100644 --- a/AUTHORS +++ b/AUTHORS @@ -77,11 +77,8 @@ i2bskn Isao Jonas isqua Jameel Haffejee -<<<<<<< HEAD Jeremy Morris -======= Jan Kosecki ->>>>>>> origin/master Jihoon Chung Jimmi Dyson Joe Tsai From 030ae5532c319f0fc38d6d7106d6e9ca37790b80 Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Tue, 22 Aug 2017 21:35:22 -0400 Subject: [PATCH 15/35] Ran `go fmt` on file. --- github/apps_installation.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index f7bcf4dee1..6be06240e9 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -66,7 +66,7 @@ func (s *AppService) AddRepo(ctx context.Context, instID int, repoID int) (*Repo if err != nil { return nil, resp, err } - + return r, resp, nil } @@ -81,4 +81,4 @@ func (s *AppService) RemoveRepo(ctx context.Context, instID int, repoID int) (*R } return s.client.Do(ctx, req, nil) -} \ No newline at end of file +} From 11aefc3b3089501ce252413a9322bc6ca290e1c4 Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Tue, 22 Aug 2017 21:38:46 -0400 Subject: [PATCH 16/35] Ran `go fmt` on file. --- github/apps_installation_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index aba33eb6bf..d9428bab02 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -69,4 +69,4 @@ func TestAppsService_RemoveRepo(t *testing.T) { if err != nil { t.Errorf("Apps.RemoveRepo returned error: %v", err) } -} \ No newline at end of file +} From 173da1c301eec376745a6804352b0a7b365ef668 Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Wed, 23 Aug 2017 07:54:05 -0400 Subject: [PATCH 17/35] Changed s *AppService to s *AppsService . --- github/apps_installation.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index 6be06240e9..9d5f73029e 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -51,7 +51,7 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos // AddRepo adds a single repository to an installation. // // GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppService) AddRepo(ctx context.Context, instID int, repoID int) (*Repository, *Response, error) { +func (s *AppsService) AddRepo(ctx context.Context, instID int, repoID int) (*Repository, *Response, error) { u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("PUT", u, nil) if err != nil { @@ -73,7 +73,7 @@ func (s *AppService) AddRepo(ctx context.Context, instID int, repoID int) (*Repo // RemoveRepo removes a single repository from an installation. // // GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppService) RemoveRepo(ctx context.Context, instID int, repoID int) (*Response, error) { +func (s *AppsService) RemoveRepo(ctx context.Context, instID int, repoID int) (*Response, error) { u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { From 2c3db487cd1d4dde06486988ea2f0fee653f983b Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Wed, 23 Aug 2017 07:59:20 -0400 Subject: [PATCH 18/35] Added import and removed extra value from return in removeRepo. --- github/apps_installation.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index 9d5f73029e..bcf0ffaee7 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -5,7 +5,10 @@ package github -import "context" +import ( + "context" + "fmt" +) // Installation represents a GitHub Apps installation. type Installation struct { @@ -77,7 +80,7 @@ func (s *AppsService) RemoveRepo(ctx context.Context, instID int, repoID int) (* u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { - return nil, nil, err + return nil, err } return s.client.Do(ctx, req, nil) From 158fea8106e7cd553eaac50cdc70e8b134b127fc Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Wed, 23 Aug 2017 08:09:35 -0400 Subject: [PATCH 19/35] Fixed some issues discovered by `go test` . --- github/apps_installation_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index d9428bab02..4ee035591c 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -43,29 +43,32 @@ func TestAppsService_AddRepo(t *testing.T) { setup() defer teardown() - input := "/app/installations/1/repositories/1" - - mux.HandleFunc("/app/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/app/installations/%v/repositories/%v", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") testHeader(t, r, "Accept", mediaTypeIntegrationPreview) }) - repo, _, err := client.Apps.AddRepo(context.Background(), input) + repo, _, err := client.Apps.AddRepo(context.Background(), 1, 1) if err != nil { t.Errorf("Apps.AddRepo returned error: %v", err) } + + want := []*Repository{{ID: Int(1)}} + if !reflect.DeepEqual(repo, want) { + t.Errorf("AddRepo returned %+v, want %+v", repo, want) + } } func TestAppsService_RemoveRepo(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/app/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/app/installations/%v/repositories/%v", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") testHeader(t, r, "Accept", mediaTypeIntegrationPreview) }) - repositories, _, err := client.Apps.RemoveRepo(context.Background(), opt) + _, err := client.Apps.RemoveRepo(context.Background(), 1, 1) if err != nil { t.Errorf("Apps.RemoveRepo returned error: %v", err) } From b9c5873fbe29fc380e5289a56cd8f03f652a0b65 Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Wed, 4 Oct 2017 00:30:29 -0400 Subject: [PATCH 20/35] Added colons to url path for add and remove repo. --- github/apps_installation.go | 7 +++++-- github/apps_installation_test.go | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index bcf0ffaee7..943d3c3cf4 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -55,7 +55,9 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos // // GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation func (s *AppsService) AddRepo(ctx context.Context, instID int, repoID int) (*Repository, *Response, error) { - u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) + // PUT user/installations/:installation_id/repositories/:repository_id + u := fmt.Sprintf("app/installations/:%v/repositories/:%v", instID, repoID) + req, err := s.client.NewRequest("PUT", u, nil) if err != nil { return nil, nil, err @@ -77,7 +79,8 @@ func (s *AppsService) AddRepo(ctx context.Context, instID int, repoID int) (*Rep // // GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation func (s *AppsService) RemoveRepo(ctx context.Context, instID int, repoID int) (*Response, error) { - u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) + // DELETE /user/installations/:installation_id/repositories/:repository_id + u := fmt.Sprintf("app/installations/:%v/repositories/:%v", instID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { return nil, err diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index 4ee035591c..136ae9816d 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -43,7 +43,7 @@ func TestAppsService_AddRepo(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/app/installations/%v/repositories/%v", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/app/installations/:%v/repositories/:%v", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") testHeader(t, r, "Accept", mediaTypeIntegrationPreview) }) @@ -63,7 +63,7 @@ func TestAppsService_RemoveRepo(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/app/installations/%v/repositories/%v", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/app/installations/:%v/repositories/:%v", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") testHeader(t, r, "Accept", mediaTypeIntegrationPreview) }) From e1326153cf8ce372bf8eb5a125cfa1124b7073b1 Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Wed, 4 Oct 2017 00:55:47 -0400 Subject: [PATCH 21/35] Removed colons from http put/delete paths. --- github/apps_installation.go | 6 ++---- github/apps_installation_test.go | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index 943d3c3cf4..fff5b429c0 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -55,8 +55,7 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos // // GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation func (s *AppsService) AddRepo(ctx context.Context, instID int, repoID int) (*Repository, *Response, error) { - // PUT user/installations/:installation_id/repositories/:repository_id - u := fmt.Sprintf("app/installations/:%v/repositories/:%v", instID, repoID) + u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("PUT", u, nil) if err != nil { @@ -79,8 +78,7 @@ func (s *AppsService) AddRepo(ctx context.Context, instID int, repoID int) (*Rep // // GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation func (s *AppsService) RemoveRepo(ctx context.Context, instID int, repoID int) (*Response, error) { - // DELETE /user/installations/:installation_id/repositories/:repository_id - u := fmt.Sprintf("app/installations/:%v/repositories/:%v", instID, repoID) + u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { return nil, err diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index 136ae9816d..59f73a5c7e 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -54,6 +54,7 @@ func TestAppsService_AddRepo(t *testing.T) { } want := []*Repository{{ID: Int(1)}} + // want := `{"repositories": [{"id":1}]}` if !reflect.DeepEqual(repo, want) { t.Errorf("AddRepo returned %+v, want %+v", repo, want) } @@ -63,7 +64,7 @@ func TestAppsService_RemoveRepo(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/app/installations/:%v/repositories/:%v", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/app/installations/%v/repositories/%v", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") testHeader(t, r, "Accept", mediaTypeIntegrationPreview) }) From 926a90c932f5582d9ab7c952f0c6a0a0340af1cf Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Wed, 4 Oct 2017 12:52:08 -0400 Subject: [PATCH 22/35] Debugging broken test and using example from repos_test as building block. --- github/apps_installation_test.go | 42 +++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index 59f73a5c7e..b12ca1cc6e 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -7,6 +7,7 @@ package github import ( "context" + "encoding/json" "fmt" "net/http" "reflect" @@ -43,9 +44,17 @@ func TestAppsService_AddRepo(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/app/installations/:%v/repositories/:%v", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/app/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { + // testMethod(t, r, "PUT") + // testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + v := new(Repository) + json.NewDecoder(r.Body).Decode(v) + testMethod(t, r, "PUT") - testHeader(t, r, "Accept", mediaTypeIntegrationPreview) + if !reflect.DeepEqual(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + fmt.Fprint(w, `{"id":1}`) }) repo, _, err := client.Apps.AddRepo(context.Background(), 1, 1) @@ -60,11 +69,38 @@ func TestAppsService_AddRepo(t *testing.T) { } } +// func TestRepositoriesService_Create_org(t *testing.T) { +// setup() +// defer teardown() + +// input := &Repository{Name: String("n")} + +// mux.HandleFunc("/orgs/o/repos", func(w http.ResponseWriter, r *http.Request) { +// v := new(Repository) +// json.NewDecoder(r.Body).Decode(v) + +// testMethod(t, r, "POST") +// if !reflect.DeepEqual(v, input) { +// t.Errorf("Request body = %+v, want %+v", v, input) +// } + +// fmt.Fprint(w, `{"id":1}`) +// }) + +// repo, _, err := client.Repositories.Create(context.Background(), "o", input) +// if err != nil { +// t.Errorf("Repositories.Create returned error: %v", err) +// } + +// want := &Repository{ID: Int(1)} +// if !reflect.DeepEqual(repo, want) { +// t.Errorf("Repositories.Create returned %+v, want %+v", repo, want) + func TestAppsService_RemoveRepo(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/app/installations/%v/repositories/%v", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/app/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") testHeader(t, r, "Accept", mediaTypeIntegrationPreview) }) From a612b5e8fbcd9cb012c23950b533504e0d6a17c7 Mon Sep 17 00:00:00 2001 From: "Jeremy L. Morris" Date: Mon, 9 Oct 2017 23:28:22 -0400 Subject: [PATCH 23/35] Refactored url string. --- github/apps_installation.go | 4 ++-- github/apps_installation_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index 943d3c3cf4..179360ef79 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -56,7 +56,7 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos // GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation func (s *AppsService) AddRepo(ctx context.Context, instID int, repoID int) (*Repository, *Response, error) { // PUT user/installations/:installation_id/repositories/:repository_id - u := fmt.Sprintf("app/installations/:%v/repositories/:%v", instID, repoID) + u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("PUT", u, nil) if err != nil { @@ -80,7 +80,7 @@ func (s *AppsService) AddRepo(ctx context.Context, instID int, repoID int) (*Rep // GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation func (s *AppsService) RemoveRepo(ctx context.Context, instID int, repoID int) (*Response, error) { // DELETE /user/installations/:installation_id/repositories/:repository_id - u := fmt.Sprintf("app/installations/:%v/repositories/:%v", instID, repoID) + u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { return nil, err diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index 136ae9816d..4ee035591c 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -43,7 +43,7 @@ func TestAppsService_AddRepo(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/app/installations/:%v/repositories/:%v", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/app/installations/%v/repositories/%v", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") testHeader(t, r, "Accept", mediaTypeIntegrationPreview) }) @@ -63,7 +63,7 @@ func TestAppsService_RemoveRepo(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/app/installations/:%v/repositories/:%v", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/app/installations/%v/repositories/%v", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") testHeader(t, r, "Accept", mediaTypeIntegrationPreview) }) From f35c3c9913eb06b98de72f3540b009bc45a00c35 Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Wed, 11 Oct 2017 10:43:59 -0400 Subject: [PATCH 24/35] Add repo test passes. --- github/apps_installation.go | 8 ++--- github/apps_installation_test.go | 58 ++++++-------------------------- 2 files changed, 15 insertions(+), 51 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index fff5b429c0..f8d79078f9 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -55,7 +55,7 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos // // GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation func (s *AppsService) AddRepo(ctx context.Context, instID int, repoID int) (*Repository, *Response, error) { - u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) + u := fmt.Sprintf("/apps/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("PUT", u, nil) if err != nil { @@ -63,12 +63,12 @@ func (s *AppsService) AddRepo(ctx context.Context, instID int, repoID int) (*Rep } // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeIntegrationPreview) + // req.Header.Set("Accept", mediaTypeIntegrationPreview) r := new(Repository) resp, err := s.client.Do(ctx, req, r) if err != nil { - return nil, resp, err + return nil, nil, err } return r, resp, nil @@ -78,7 +78,7 @@ func (s *AppsService) AddRepo(ctx context.Context, instID int, repoID int) (*Rep // // GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation func (s *AppsService) RemoveRepo(ctx context.Context, instID int, repoID int) (*Response, error) { - u := fmt.Sprintf("app/installations/%v/repositories/%v", instID, repoID) + u := fmt.Sprintf("/user/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { return nil, err diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index b12ca1cc6e..c97241af65 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -7,7 +7,6 @@ package github import ( "context" - "encoding/json" "fmt" "net/http" "reflect" @@ -44,17 +43,10 @@ func TestAppsService_AddRepo(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/app/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { - // testMethod(t, r, "PUT") - // testHeader(t, r, "Accept", mediaTypeIntegrationPreview) - v := new(Repository) - json.NewDecoder(r.Body).Decode(v) - + mux.HandleFunc("/apps/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") - if !reflect.DeepEqual(v, input) { - t.Errorf("Request body = %+v, want %+v", v, input) - } - fmt.Fprint(w, `{"id":1}`) + testHeader(t, r, "Accept", mediaTypeV3) + fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"}}`) }) repo, _, err := client.Apps.AddRepo(context.Background(), 1, 1) @@ -62,51 +54,23 @@ func TestAppsService_AddRepo(t *testing.T) { t.Errorf("Apps.AddRepo returned error: %v", err) } - want := []*Repository{{ID: Int(1)}} - // want := `{"repositories": [{"id":1}]}` + want := &Repository{ID: Int(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}, License: &License{Key: String("mit")}} if !reflect.DeepEqual(repo, want) { t.Errorf("AddRepo returned %+v, want %+v", repo, want) } } -// func TestRepositoriesService_Create_org(t *testing.T) { +// func TestAppsService_RemoveRepo(t *testing.T) { // setup() // defer teardown() -// input := &Repository{Name: String("n")} - -// mux.HandleFunc("/orgs/o/repos", func(w http.ResponseWriter, r *http.Request) { -// v := new(Repository) -// json.NewDecoder(r.Body).Decode(v) - -// testMethod(t, r, "POST") -// if !reflect.DeepEqual(v, input) { -// t.Errorf("Request body = %+v, want %+v", v, input) -// } - -// fmt.Fprint(w, `{"id":1}`) +// mux.HandleFunc("/apps/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { +// testMethod(t, r, "DELETE") +// testHeader(t, r, "Accept", mediaTypeV3) // }) -// repo, _, err := client.Repositories.Create(context.Background(), "o", input) +// _, err := client.Apps.RemoveRepo(context.Background(), 1, 1) // if err != nil { -// t.Errorf("Repositories.Create returned error: %v", err) +// t.Errorf("Apps.RemoveRepo returned error: %v", err) // } - -// want := &Repository{ID: Int(1)} -// if !reflect.DeepEqual(repo, want) { -// t.Errorf("Repositories.Create returned %+v, want %+v", repo, want) - -func TestAppsService_RemoveRepo(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/app/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "DELETE") - testHeader(t, r, "Accept", mediaTypeIntegrationPreview) - }) - - _, err := client.Apps.RemoveRepo(context.Background(), 1, 1) - if err != nil { - t.Errorf("Apps.RemoveRepo returned error: %v", err) - } -} +// } From d6c991ea991cf606027c04c35abeeb0491632502 Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Wed, 11 Oct 2017 11:00:58 -0400 Subject: [PATCH 25/35] Uncommented custom accept header. --- github/apps_installation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index f8d79078f9..2aa1269c6d 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -63,7 +63,7 @@ func (s *AppsService) AddRepo(ctx context.Context, instID int, repoID int) (*Rep } // TODO: remove custom Accept header when this API fully launches. - // req.Header.Set("Accept", mediaTypeIntegrationPreview) + req.Header.Set("Accept", mediaTypeV3) r := new(Repository) resp, err := s.client.Do(ctx, req, r) From 4d5820a63450dba4fd21ab627ac012d92d375d5d Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Wed, 11 Oct 2017 13:45:59 -0400 Subject: [PATCH 26/35] Refactored method signatures add and remove repo. Added response check to remove repo. --- github/apps_installation.go | 7 +++---- github/apps_installation_test.go | 29 +++++++++++++++++------------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index 2aa1269c6d..aa148742ab 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -54,9 +54,8 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos // AddRepo adds a single repository to an installation. // // GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppsService) AddRepo(ctx context.Context, instID int, repoID int) (*Repository, *Response, error) { +func (s *AppsService) AddRepo(ctx context.Context, instID, repoID int) (*Repository, *Response, error) { u := fmt.Sprintf("/apps/installations/%v/repositories/%v", instID, repoID) - req, err := s.client.NewRequest("PUT", u, nil) if err != nil { return nil, nil, err @@ -76,8 +75,8 @@ func (s *AppsService) AddRepo(ctx context.Context, instID int, repoID int) (*Rep // RemoveRepo removes a single repository from an installation. // -// GitHub docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppsService) RemoveRepo(ctx context.Context, instID int, repoID int) (*Response, error) { +// GitHub docs: https://developer.github.com/v3/apps/installations/#remove-repository-from-installation +func (s *AppsService) RemoveRepo(ctx context.Context, instID, repoID int) (*Response, error) { u := fmt.Sprintf("/user/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index c97241af65..628028b48e 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -11,6 +11,8 @@ import ( "net/http" "reflect" "testing" + + "github.com/google/go-github/github" ) func TestAppsService_ListRepos(t *testing.T) { @@ -60,17 +62,20 @@ func TestAppsService_AddRepo(t *testing.T) { } } -// func TestAppsService_RemoveRepo(t *testing.T) { -// setup() -// defer teardown() +func TestAppsService_RemoveRepo(t *testing.T) { + setup() + defer teardown() -// mux.HandleFunc("/apps/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { -// testMethod(t, r, "DELETE") -// testHeader(t, r, "Accept", mediaTypeV3) -// }) + mux.HandleFunc("/apps/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") -// _, err := client.Apps.RemoveRepo(context.Background(), 1, 1) -// if err != nil { -// t.Errorf("Apps.RemoveRepo returned error: %v", err) -// } -// } + w.WriteHeader(http.StatusNoContent) + }) + + _, err := client.Apps.RemoveRepo(context.Background(), 1, 1) + + _, res := err.(*github.ErrorResponse) + if res == true && err != nil { + t.Errorf("Apps.RemoveRepo returned error: %v", err) + } +} From 60af6e66872d1cb74b9218a0b3379061525a769a Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Wed, 11 Oct 2017 13:54:09 -0400 Subject: [PATCH 27/35] Ran go fmt on codebase. --- github/apps.go | 2 +- github/apps_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/github/apps.go b/github/apps.go index 4c3e7c648a..ff3389382e 100644 --- a/github/apps.go +++ b/github/apps.go @@ -37,4 +37,4 @@ func (s *AppsService) ListInstallations(ctx context.Context, opt *ListOptions) ( } return i, resp, nil -} \ No newline at end of file +} diff --git a/github/apps_test.go b/github/apps_test.go index e314c81868..f847b84271 100644 --- a/github/apps_test.go +++ b/github/apps_test.go @@ -37,4 +37,4 @@ func TestAppsService_ListInstallations(t *testing.T) { if !reflect.DeepEqual(installations, want) { t.Errorf("Apps.ListInstallations returned %+v, want %+v", installations, want) } -} \ No newline at end of file +} From 8e876e4910cfea9e2fc8b159d00c0fb18b2022d7 Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Thu, 12 Oct 2017 21:57:17 -0400 Subject: [PATCH 28/35] Removed unnecessary import and changed *github.ErrorResponse to *ErrorResponse. --- github/apps_installation_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index 628028b48e..254a7d89be 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -11,8 +11,6 @@ import ( "net/http" "reflect" "testing" - - "github.com/google/go-github/github" ) func TestAppsService_ListRepos(t *testing.T) { @@ -74,7 +72,7 @@ func TestAppsService_RemoveRepo(t *testing.T) { _, err := client.Apps.RemoveRepo(context.Background(), 1, 1) - _, res := err.(*github.ErrorResponse) + _, res := err.(*ErrorResponse) if res == true && err != nil { t.Errorf("Apps.RemoveRepo returned error: %v", err) } From 42faa4d89e76da17b0c08bcbfb88747016885740 Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Thu, 12 Oct 2017 22:28:10 -0400 Subject: [PATCH 29/35] Fixed url path for RemoveRepo and removed extra conditional in RemoveRepo test. --- github/apps_installation.go | 2 +- github/apps_installation_test.go | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index aa148742ab..46f142a24a 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -77,7 +77,7 @@ func (s *AppsService) AddRepo(ctx context.Context, instID, repoID int) (*Reposit // // GitHub docs: https://developer.github.com/v3/apps/installations/#remove-repository-from-installation func (s *AppsService) RemoveRepo(ctx context.Context, instID, repoID int) (*Response, error) { - u := fmt.Sprintf("/user/installations/%v/repositories/%v", instID, repoID) + u := fmt.Sprintf("/apps/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { return nil, err diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index 254a7d89be..47816967a9 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -66,14 +66,11 @@ func TestAppsService_RemoveRepo(t *testing.T) { mux.HandleFunc("/apps/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") - w.WriteHeader(http.StatusNoContent) }) _, err := client.Apps.RemoveRepo(context.Background(), 1, 1) - - _, res := err.(*ErrorResponse) - if res == true && err != nil { + if err != nil { t.Errorf("Apps.RemoveRepo returned error: %v", err) } } From 326457be85fc06ddda4b1124bd8e22668c5ec1df Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Thu, 12 Oct 2017 22:51:45 -0400 Subject: [PATCH 30/35] Added newline at eof, to restart build after CLA email fix. --- github/apps_installation_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index 47816967a9..1e0f3dd86e 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -74,3 +74,4 @@ func TestAppsService_RemoveRepo(t *testing.T) { t.Errorf("Apps.RemoveRepo returned error: %v", err) } } + From b4b56c3ff04ff9255896f7af0c872f5d5efe0401 Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Thu, 12 Oct 2017 23:03:11 -0400 Subject: [PATCH 31/35] Removed newline from test file. --- github/apps_installation_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index 1e0f3dd86e..47816967a9 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -74,4 +74,3 @@ func TestAppsService_RemoveRepo(t *testing.T) { t.Errorf("Apps.RemoveRepo returned error: %v", err) } } - From 432dab7687368aed059122d8dae14658bbc9474c Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Thu, 12 Oct 2017 23:20:35 -0400 Subject: [PATCH 32/35] Fixed suggestions for naming functions, and fixing error check. --- github/apps_installation.go | 13 +++++-------- github/apps_installation_test.go | 8 ++++---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index 46f142a24a..c2bd0e7491 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -51,32 +51,29 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos return r.Repositories, resp, nil } -// AddRepo adds a single repository to an installation. +// AddRepository adds a single repository to an installation. // // GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation -func (s *AppsService) AddRepo(ctx context.Context, instID, repoID int) (*Repository, *Response, error) { +func (s *AppsService) AddRepository(ctx context.Context, instID, repoID int) (*Repository, *Response, error) { u := fmt.Sprintf("/apps/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("PUT", u, nil) if err != nil { return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. - req.Header.Set("Accept", mediaTypeV3) - r := new(Repository) resp, err := s.client.Do(ctx, req, r) if err != nil { - return nil, nil, err + return nil, resp, err } return r, resp, nil } -// RemoveRepo removes a single repository from an installation. +// RemoveRepository removes a single repository from an installation. // // GitHub docs: https://developer.github.com/v3/apps/installations/#remove-repository-from-installation -func (s *AppsService) RemoveRepo(ctx context.Context, instID, repoID int) (*Response, error) { +func (s *AppsService) RemoveRepository(ctx context.Context, instID, repoID int) (*Response, error) { u := fmt.Sprintf("/apps/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index 47816967a9..bc912c5623 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -39,7 +39,7 @@ func TestAppsService_ListRepos(t *testing.T) { } } -func TestAppsService_AddRepo(t *testing.T) { +func TestAppsService_AddRepository(t *testing.T) { setup() defer teardown() @@ -49,7 +49,7 @@ func TestAppsService_AddRepo(t *testing.T) { fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"}}`) }) - repo, _, err := client.Apps.AddRepo(context.Background(), 1, 1) + repo, _, err := client.Apps.AddRepository(context.Background(), 1, 1) if err != nil { t.Errorf("Apps.AddRepo returned error: %v", err) } @@ -60,7 +60,7 @@ func TestAppsService_AddRepo(t *testing.T) { } } -func TestAppsService_RemoveRepo(t *testing.T) { +func TestAppsService_RemoveRepository(t *testing.T) { setup() defer teardown() @@ -69,7 +69,7 @@ func TestAppsService_RemoveRepo(t *testing.T) { w.WriteHeader(http.StatusNoContent) }) - _, err := client.Apps.RemoveRepo(context.Background(), 1, 1) + _, err := client.Apps.RemoveRepository(context.Background(), 1, 1) if err != nil { t.Errorf("Apps.RemoveRepo returned error: %v", err) } From c01f313b8dd57d1e370cc7d1a8366a062f9e0dfc Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Fri, 13 Oct 2017 00:09:22 -0400 Subject: [PATCH 33/35] Added full function names to Errorf strings, to match referenced function names. --- github/apps_installation_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index bc912c5623..1434e51c5f 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -51,12 +51,12 @@ func TestAppsService_AddRepository(t *testing.T) { repo, _, err := client.Apps.AddRepository(context.Background(), 1, 1) if err != nil { - t.Errorf("Apps.AddRepo returned error: %v", err) + t.Errorf("Apps.AddRepository returned error: %v", err) } want := &Repository{ID: Int(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}, License: &License{Key: String("mit")}} if !reflect.DeepEqual(repo, want) { - t.Errorf("AddRepo returned %+v, want %+v", repo, want) + t.Errorf("AddRepository returned %+v, want %+v", repo, want) } } @@ -71,6 +71,6 @@ func TestAppsService_RemoveRepository(t *testing.T) { _, err := client.Apps.RemoveRepository(context.Background(), 1, 1) if err != nil { - t.Errorf("Apps.RemoveRepo returned error: %v", err) + t.Errorf("Apps.RemoveRepository returned error: %v", err) } } From 41d02d7465aaaee64fac928b63ce4f142256951f Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Fri, 13 Oct 2017 11:12:39 -0400 Subject: [PATCH 34/35] Removed mediatypev3. --- github/apps_installation_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go index 1434e51c5f..69598cfe5f 100644 --- a/github/apps_installation_test.go +++ b/github/apps_installation_test.go @@ -45,7 +45,6 @@ func TestAppsService_AddRepository(t *testing.T) { mux.HandleFunc("/apps/installations/1/repositories/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") - testHeader(t, r, "Accept", mediaTypeV3) fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"}}`) }) From b5f3a3bdf914e134b4d216dabb5f399dda186dd2 Mon Sep 17 00:00:00 2001 From: Jeremy Morris Date: Fri, 13 Oct 2017 14:05:57 -0400 Subject: [PATCH 35/35] Removed starting slash in URLs. --- github/apps_installation.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/apps_installation.go b/github/apps_installation.go index c2bd0e7491..5c932919ff 100644 --- a/github/apps_installation.go +++ b/github/apps_installation.go @@ -55,7 +55,7 @@ func (s *AppsService) ListRepos(ctx context.Context, opt *ListOptions) ([]*Repos // // GitHub API docs: https://developer.github.com/v3/apps/installations/#add-repository-to-installation func (s *AppsService) AddRepository(ctx context.Context, instID, repoID int) (*Repository, *Response, error) { - u := fmt.Sprintf("/apps/installations/%v/repositories/%v", instID, repoID) + u := fmt.Sprintf("apps/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("PUT", u, nil) if err != nil { return nil, nil, err @@ -74,7 +74,7 @@ func (s *AppsService) AddRepository(ctx context.Context, instID, repoID int) (*R // // GitHub docs: https://developer.github.com/v3/apps/installations/#remove-repository-from-installation func (s *AppsService) RemoveRepository(ctx context.Context, instID, repoID int) (*Response, error) { - u := fmt.Sprintf("/apps/installations/%v/repositories/%v", instID, repoID) + u := fmt.Sprintf("apps/installations/%v/repositories/%v", instID, repoID) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { return nil, err