Skip to content

Commit c1bdf18

Browse files
alindemandmitshur
authored andcommitted
Change repository invitation methods to take :owner/:repo. (#586)
All repository routes on the GitHub API can accessed via /repositories/:id and /repos/:owner/:repo. For some reason, the documentation for the invitation routes only references the former. Contacting GitHub support has confirmed that the inconsistent documentation was unintentional and will likely be corrected to use :owner/:repo soon. Repository invitations are the only functions in google/go-github to use the :id style routes, so this changes them to use :owner/:repo for consistency, and as that will likely be much more convenient for users of this library. Bump version because this is a breaking API change. It affects endpoints that are part of preview API only.
1 parent 553fda4 commit c1bdf18

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

github/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
const (
30-
libraryVersion = "3"
30+
libraryVersion = "4"
3131
defaultBaseURL = "https://github.com/api/"
3232
uploadBaseURL = "https://uploads.github.com/"
3333
userAgent = "go-github/" + libraryVersion

github/repos_invitations.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ type RepositoryInvitation struct {
2828
// ListInvitations lists all currently-open repository invitations.
2929
//
3030
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#list-invitations-for-a-repository
31-
func (s *RepositoriesService) ListInvitations(ctx context.Context, repoID int, opt *ListOptions) ([]*RepositoryInvitation, *Response, error) {
32-
u := fmt.Sprintf("repositories/%v/invitations", repoID)
31+
func (s *RepositoriesService) ListInvitations(ctx context.Context, owner, repo string, opt *ListOptions) ([]*RepositoryInvitation, *Response, error) {
32+
u := fmt.Sprintf("repos/%v/%v/invitations", owner, repo)
3333
u, err := addOptions(u, opt)
3434
if err != nil {
3535
return nil, nil, err
@@ -55,8 +55,8 @@ func (s *RepositoriesService) ListInvitations(ctx context.Context, repoID int, o
5555
// DeleteInvitation deletes a repository invitation.
5656
//
5757
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#delete-a-repository-invitation
58-
func (s *RepositoriesService) DeleteInvitation(ctx context.Context, repoID, invitationID int) (*Response, error) {
59-
u := fmt.Sprintf("repositories/%v/invitations/%v", repoID, invitationID)
58+
func (s *RepositoriesService) DeleteInvitation(ctx context.Context, owner, repo string, invitationID int) (*Response, error) {
59+
u := fmt.Sprintf("repos/%v/%v/invitations/%v", owner, repo, invitationID)
6060
req, err := s.client.NewRequest("DELETE", u, nil)
6161
if err != nil {
6262
return nil, err
@@ -75,11 +75,11 @@ func (s *RepositoriesService) DeleteInvitation(ctx context.Context, repoID, invi
7575
// on the repository. Possible values are: "read", "write", "admin".
7676
//
7777
// GitHub API docs: https://developer.github.com/v3/repos/invitations/#update-a-repository-invitation
78-
func (s *RepositoriesService) UpdateInvitation(ctx context.Context, repoID, invitationID int, permissions string) (*RepositoryInvitation, *Response, error) {
78+
func (s *RepositoriesService) UpdateInvitation(ctx context.Context, owner, repo string, invitationID int, permissions string) (*RepositoryInvitation, *Response, error) {
7979
opts := &struct {
8080
Permissions string `json:"permissions"`
8181
}{Permissions: permissions}
82-
u := fmt.Sprintf("repositories/%v/invitations/%v", repoID, invitationID)
82+
u := fmt.Sprintf("repos/%v/%v/invitations/%v", owner, repo, invitationID)
8383
req, err := s.client.NewRequest("PATCH", u, opts)
8484
if err != nil {
8585
return nil, nil, err

github/repos_invitations_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ func TestRepositoriesService_ListInvitations(t *testing.T) {
1717
setup()
1818
defer teardown()
1919

20-
mux.HandleFunc("/repositories/1/invitations", func(w http.ResponseWriter, r *http.Request) {
20+
mux.HandleFunc("/repos/o/r/invitations", func(w http.ResponseWriter, r *http.Request) {
2121
testMethod(t, r, "GET")
2222
testHeader(t, r, "Accept", mediaTypeRepositoryInvitationsPreview)
2323
testFormValues(t, r, values{"page": "2"})
2424
fmt.Fprintf(w, `[{"id":1}, {"id":2}]`)
2525
})
2626

2727
opt := &ListOptions{Page: 2}
28-
got, _, err := client.Repositories.ListInvitations(context.Background(), 1, opt)
28+
got, _, err := client.Repositories.ListInvitations(context.Background(), "o", "r", opt)
2929
if err != nil {
3030
t.Errorf("Repositories.ListInvitations returned error: %v", err)
3131
}
@@ -40,13 +40,13 @@ func TestRepositoriesService_DeleteInvitation(t *testing.T) {
4040
setup()
4141
defer teardown()
4242

43-
mux.HandleFunc("/repositories/1/invitations/2", func(w http.ResponseWriter, r *http.Request) {
43+
mux.HandleFunc("/repos/o/r/invitations/2", func(w http.ResponseWriter, r *http.Request) {
4444
testMethod(t, r, "DELETE")
4545
testHeader(t, r, "Accept", mediaTypeRepositoryInvitationsPreview)
4646
w.WriteHeader(http.StatusNoContent)
4747
})
4848

49-
_, err := client.Repositories.DeleteInvitation(context.Background(), 1, 2)
49+
_, err := client.Repositories.DeleteInvitation(context.Background(), "o", "r", 2)
5050
if err != nil {
5151
t.Errorf("Repositories.DeleteInvitation returned error: %v", err)
5252
}
@@ -56,13 +56,13 @@ func TestRepositoriesService_UpdateInvitation(t *testing.T) {
5656
setup()
5757
defer teardown()
5858

59-
mux.HandleFunc("/repositories/1/invitations/2", func(w http.ResponseWriter, r *http.Request) {
59+
mux.HandleFunc("/repos/o/r/invitations/2", func(w http.ResponseWriter, r *http.Request) {
6060
testMethod(t, r, "PATCH")
6161
testHeader(t, r, "Accept", mediaTypeRepositoryInvitationsPreview)
6262
fmt.Fprintf(w, `{"id":1}`)
6363
})
6464

65-
got, _, err := client.Repositories.UpdateInvitation(context.Background(), 1, 2, "write")
65+
got, _, err := client.Repositories.UpdateInvitation(context.Background(), "o", "r", 2, "write")
6666
if err != nil {
6767
t.Errorf("Repositories.UpdateInvitation returned error: %v", err)
6868
}

0 commit comments

Comments
 (0)