Skip to content
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

Add APIs for pre-receive hooks #945

Merged
merged 1 commit into from Aug 2, 2018
Merged

Conversation

nmiyake
Copy link
Contributor

@nmiyake nmiyake commented Jul 11, 2018

Fixes #944

@googlebot googlebot added the cla: yes Indication that the PR author has signed a Google Contributor License Agreement. label Jul 11, 2018
Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

This is looking great, @nmiyake!
Thank you for doing this!
Just a few minor things to address before merging if you don't mind.

@@ -0,0 +1,102 @@
// Copyright 2013 The go-github AUTHORS. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/2013/2018/ as that is the year this particular file is created.

ConfigURL *string `json:"configuration_url,omitempty"`
}

func (h PreReceiveHook) String() string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Go style nit: func (p PreReceiveHook)...
s/h/p/ to match the receiver variable with the start of the name of its type...
although I see that this Go style recommendation is not followed consistently throughout this repo, so you can ignore this comment safely. I'll leave it anyway in case someone wants to clean up all receivers in this repo. 😄


hook := new(PreReceiveHook)
resp, err := s.client.Do(ctx, req, hook)
return hook, resp, err
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we would like the error checking to remain consistent, like your function above:

if err != nil {
	return nil, resp, err
}

return hook, resp, nil

We think this is easier to read and reason about.

If you copied this pattern from somewhere else in this repo, we should probably change that one too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this file was a copy-modify of repos_hooks.go, so these issues are also copied from there. Will make the changes in this PR and open a separate PR to fix the occurrences in repos_hooks.go.


h := new(PreReceiveHook)
resp, err := s.client.Do(ctx, req, h)
return h, resp, err
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here with the error handling

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

return s.client.Do(ctx, req, nil)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is fine to leave as-is since we are not returning any "interesting" struct pointers here.

@@ -0,0 +1,133 @@
// Copyright 2013 The go-github AUTHORS. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/2013/2018/

defer teardown()

mux.HandleFunc("/repos/o/r/pre-receive-hooks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here and below, please add testHeader to check for the custom media type specified in the header.
That helps us to keep this repo cleaner by explicitly calling out when custom media headers are being used.

@nmiyake
Copy link
Contributor Author

nmiyake commented Jul 13, 2018

Thanks for the review! Updated PR to address feedback.

@gmlewis
Copy link
Collaborator

gmlewis commented Jul 13, 2018

Thanks for the changes, @nmiyake.

Just FYI... it makes reviewing easier if you add additional commits (instead of force-pushing over top of an earlier commit). That way, reviewers can see just the changes that were made after the last review.

In the end, we squash and merge the final commit anyway, so feel free to add as many commits as you want. 😄

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @nmiyake!
LGTM.
Awaiting second LGTM before merging.

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Jul 13, 2018
@nmiyake
Copy link
Contributor Author

nmiyake commented Aug 1, 2018

Update PR to resolve merge conflict.

Ping for another reviewer (@juliaferraioli or anyone else actively doing reviews) to unblock.

Copy link
Contributor

@juliaferraioli juliaferraioli left a comment

Choose a reason for hiding this comment

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

LGTM. Very nice and clean, @nmiyake!

@gmlewis
Copy link
Collaborator

gmlewis commented Aug 2, 2018

Thank you, @nmiyake and @juliaferraioli!
Merging.

@gmlewis gmlewis merged commit 7161710 into google:master Aug 2, 2018
gmlewis pushed a commit to gmlewis/go-github that referenced this pull request Aug 10, 2018
n1lesh pushed a commit to n1lesh/go-github that referenced this pull request Oct 2, 2020
@gmlewis gmlewis removed the NeedsReview PR is awaiting a review before merging. label Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indication that the PR author has signed a Google Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for pre-receive hooks API
4 participants