-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Enhancement/add remove repository #749
Enhancement/add remove repository #749
Conversation
…m/MorrisLaw/go-github into enhancement/add-remove-repository
@MorrisLaw, you can click on the icon here to see the CI results: It links to the CI page. There, you can see all 4 jobs failed. Pick the first one (Go 1.9.x job), and look at the log. If you scan towards the bottom, you'll see something in red, that's the first failure:
The command that failed was |
github/apps_installation_test.go
Outdated
@@ -11,6 +11,8 @@ import ( | |||
"net/http" | |||
"reflect" | |||
"testing" | |||
|
|||
"github.com/google/go-github/github" |
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.
This is an internal package test .go file. Therefore, you don't need to import that package - you're already in it.
Instead of writing github.ErrorResponse
below, you can access it with just ErrorResponse
.
That will fix the problem.
You can read more about internal/external tests at https://golang.org/cmd/go/#hdr-Test_packages.
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
github/apps_installation.go
Outdated
} | ||
|
||
// TODO: remove custom Accept header when this API fully launches. | ||
req.Header.Set("Accept", mediaTypeV3) |
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.
mediaTypeV3
is already the default set in NewRequest
method:
Line 269 in 0f6d3ce
req.Header.Set("Accept", mediaTypeV3) |
So no need to do this, you can delete the two lines above.
github/apps_installation.go
Outdated
// 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, repoID int) (*Repository, *Response, error) { |
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.
I think we should call this method AddRepository
rather than AddRepo
. We already use the full "Repository" word in many other method names, e.g.:
github/apps_installation.go
Outdated
// RemoveRepo 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) { |
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.
Similarly, this would be RemoveRepository
.
github/apps_installation.go
Outdated
r := new(Repository) | ||
resp, err := s.client.Do(ctx, req, r) | ||
if err != nil { | ||
return nil, nil, err |
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.
Even if err != nil, you should return resp
rather than nil *Response
:
resp, err := s.client.Do(ctx, req, r)
if err != nil {
return nil, resp, err
}
This is what all other methods do.
CLAs look good, thanks! |
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.
Really minor remaining things.
github/apps_installation_test.go
Outdated
|
||
repo, _, err := client.Apps.AddRepository(context.Background(), 1, 1) | ||
if err != nil { | ||
t.Errorf("Apps.AddRepo returned error: %v", err) |
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.
It'd be nice to rename the method name here too.
github/apps_installation_test.go
Outdated
|
||
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) |
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.
And here.
github/apps_installation_test.go
Outdated
|
||
_, err := client.Apps.RemoveRepository(context.Background(), 1, 1) | ||
if err != nil { | ||
t.Errorf("Apps.RemoveRepo returned error: %v", err) |
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.
As well as here.
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.
I've spotted a small but critical issue we need to fix.
After that, I don't have any other suggestions and it'll have my LGTM. Thanks @MorrisLaw!
github/apps_installation.go
Outdated
// | ||
// 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) |
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.
We need to not include the starting slash in the URLs, otherwise enterprise GH URLs will not work.
This should be:
u := fmt.Sprintf("apps/installations/%v/repositories/%v", instID, repoID)
github/apps_installation.go
Outdated
// | ||
// 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) |
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.
Same here, please remove the first slash in the URL. You'll notice all other endpoints don't include it either.
Thank you for the thorough reviewing and for providing all of the useful feedback! @shurcooL |
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.
LGTM. I'm not spotting any other issues.
Thank you @MorrisLaw!
I'll wait for another reviewer, and we can merge after that.
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.
LGTM.
Thank you, @MorrisLaw and @shurcooL!
Added support for preview installations API for the following: