Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd hooks support for PubSubHubBub API. #1540
Conversation
codecov
bot
commented
May 27, 2020
•
Codecov Report
@@ Coverage Diff @@
## master #1540 +/- ##
==========================================
+ Coverage 68.01% 68.04% +0.02%
==========================================
Files 94 94
Lines 8560 8577 +17
==========================================
+ Hits 5822 5836 +14
- Misses 1852 1854 +2
- Partials 886 887 +1
Continue to review full report at Codecov.
|
|
A few comment nits. Some of the other structs for requests have a comment mentioning fields that are required and a list of possible choices (e.g. modes). |
| // CreatePubSubHubBubrequest lets servers register receive updates when a topic is updated | ||
| // using publish/subscribe protocol with GitHub as the hub for the repositories. |
This comment has been minimized.
This comment has been minimized.
nightlark
May 28, 2020
•
Contributor
| // CreatePubSubHubBubrequest lets servers register receive updates when a topic is updated | |
| // using publish/subscribe protocol with GitHub as the hub for the repositories. | |
| // CreatePubSubHubbubRequest lets servers register to receive updates when a topic is updated | |
| // using a publish/subscribe protocol with GitHub as the hub for the repositories. |
| // PubSubHubBubRequest represents the request to be send | ||
| // for the GitHub's publish/subscribe hub protocol. |
This comment has been minimized.
This comment has been minimized.
nightlark
May 28, 2020
•
Contributor
| // PubSubHubBubRequest represents the request to be send | |
| // for the GitHub's publish/subscribe hub protocol. | |
| // PubSubHubbubRequest represents the request to be sent | |
| // for GitHub's publish/subscribe hub protocol. |
|
Not sure if this is a change you'd want to make, but it looks like the name in the docs and github repo on the protocol is |
| // for the GitHub's publish/subscribe hub protocol. | ||
| // | ||
| // GitHub API docs: https://developer.github.com/v3/repos/hooks/#subscribing | ||
| type PubSubHubBubRequest struct { |
This comment has been minimized.
This comment has been minimized.
nightlark
May 28, 2020
Contributor
| type PubSubHubBubRequest struct { | |
| type PubSubHubbubRequest struct { |
| Event string `json:"events,omitempty"` | ||
| } | ||
|
|
||
| type pubSubHubBubPayload struct { |
This comment has been minimized.
This comment has been minimized.
nightlark
May 28, 2020
Contributor
| type pubSubHubBubPayload struct { | |
| type pubSubHubbubPayload struct { |
| // using publish/subscribe protocol with GitHub as the hub for the repositories. | ||
| // | ||
| // GitHub API docs: https://developer.github.com/v3/repos/hooks/#pubsubhubbub | ||
| func (s *RepositoriesService) CreatePubSubHubBubRequest(ctx context.Context, request *PubSubHubBubRequest) (*Response, error) { |
This comment has been minimized.
This comment has been minimized.
nightlark
May 28, 2020
Contributor
| func (s *RepositoriesService) CreatePubSubHubBubRequest(ctx context.Context, request *PubSubHubBubRequest) (*Response, error) { | |
| func (s *RepositoriesService) CreatePubSubHubbubRequest(ctx context.Context, request *PubSubHubbubRequest) (*Response, error) { |
|
|
||
| hubTopic := fmt.Sprintf("/%v/%v/events/%v", request.HubTopic.Owner, request.HubTopic.Repo, request.HubTopic.Event) | ||
|
|
||
| pubSubHubBubReq := &pubSubHubBubPayload{ |
This comment has been minimized.
This comment has been minimized.
nightlark
May 28, 2020
Contributor
| pubSubHubBubReq := &pubSubHubBubPayload{ | |
| pubSubHubbubReq := &pubSubHubbubPayload{ |
| HubSecret: request.HubSecret, | ||
| } | ||
|
|
||
| req, err := s.client.NewRequest("POST", u, pubSubHubBubReq) |
This comment has been minimized.
This comment has been minimized.
nightlark
May 28, 2020
Contributor
| req, err := s.client.NewRequest("POST", u, pubSubHubBubReq) | |
| req, err := s.client.NewRequest("POST", u, pubSubHubbubReq) |
| @@ -197,3 +197,27 @@ func TestRepositoriesService_TestHook_invalidOwner(t *testing.T) { | |||
| _, err := client.Repositories.TestHook(context.Background(), "%", "%", 1) | |||
| testURLParseError(t, err) | |||
| } | |||
|
|
|||
| func TestRepositoriesService_TestPubSubHubBub(t *testing.T) { | |||
This comment has been minimized.
This comment has been minimized.
nightlark
May 28, 2020
Contributor
| func TestRepositoriesService_TestPubSubHubBub(t *testing.T) { | |
| func TestRepositoriesService_TestPubSubHubbub(t *testing.T) { |
| testMethod(t, r, "POST") | ||
| }) | ||
|
|
||
| pubSubHubBubreq := &PubSubHubBubRequest{ |
This comment has been minimized.
This comment has been minimized.
nightlark
May 28, 2020
Contributor
| pubSubHubBubreq := &PubSubHubBubRequest{ | |
| pubSubHubbubreq := &PubSubHubbubRequest{ |
| HubCallback: "http://postbin.org/123", | ||
| } | ||
|
|
||
| _, err := client.Repositories.CreatePubSubHubBubRequest(context.Background(), pubSubHubBubreq) |
This comment has been minimized.
This comment has been minimized.
nightlark
May 28, 2020
Contributor
| _, err := client.Repositories.CreatePubSubHubBubRequest(context.Background(), pubSubHubBubreq) | |
| _, err := client.Repositories.CreatePubSubHubbubRequest(context.Background(), pubSubHubbubreq) |
|
|
||
| _, err := client.Repositories.CreatePubSubHubBubRequest(context.Background(), pubSubHubBubreq) | ||
| if err != nil { | ||
| t.Errorf("Repositories.CreatePubSubHubBubrequest returned error: %v", err) |
This comment has been minimized.
This comment has been minimized.
nightlark
May 28, 2020
Contributor
| t.Errorf("Repositories.CreatePubSubHubBubrequest returned error: %v", err) | |
| t.Errorf("Repositories.CreatePubSubHubbubRequest returned error: %v", err) |
| HubCallback: "http://postbin.org/123", | ||
| } | ||
|
|
||
| _, err := client.Repositories.CreatePubSubHubBubRequest(context.Background(), pubSubHubBubreq) |
This comment has been minimized.
This comment has been minimized.
nightlark
May 28, 2020
Contributor
| _, err := client.Repositories.CreatePubSubHubBubRequest(context.Background(), pubSubHubBubreq) | |
| _, err := client.Repositories.CreatePubSubHubbubRequest(context.Background(), pubSubHubbubreq) |
|
Thank you, @joshuabezaleel - you are off to a good start. I'm not sure that it will, however, because the examples given show In other words, to get this working you will probably at the very least need to add this "Content-Type" to the request headers. Check around this repo, as there are other places where we do this kind of thing. So please try to get it working after you've addressed my feedback before we continue. If you run into problems, you can give details here and we can try to work through them. Thank you! |
| @@ -224,3 +249,27 @@ func (s *RepositoriesService) TestHook(ctx context.Context, owner, repo string, | |||
| } | |||
| return s.client.Do(ctx, req, nil) | |||
| } | |||
|
|
|||
| // CreatePubSubHubBubrequest lets servers register receive updates when a topic is updated | |||
This comment has been minimized.
This comment has been minimized.
gmlewis
May 28, 2020
Collaborator
How about this (note the spelling - the GitHub docs don't capitalize "Bub"):
// SubscribePubSubHubbub lets servers register to receive updates when a topic is updated
// using the publish/subscribe protocol with GitHub as the hub for the repositories.
| // using publish/subscribe protocol with GitHub as the hub for the repositories. | ||
| // | ||
| // GitHub API docs: https://developer.github.com/v3/repos/hooks/#pubsubhubbub | ||
| func (s *RepositoriesService) CreatePubSubHubBubRequest(ctx context.Context, request *PubSubHubBubRequest) (*Response, error) { |
This comment has been minimized.
This comment has been minimized.
gmlewis
May 28, 2020
Collaborator
Let's change request *PubSubHubBubRequest to:
opts *SubscribePubSubHubbubOpts.
| @@ -98,6 +98,31 @@ type createHookRequest struct { | |||
| Active *bool `json:"active,omitempty"` | |||
| } | |||
|
|
|||
| // PubSubHubBubRequest represents the request to be send | |||
This comment has been minimized.
This comment has been minimized.
gmlewis
May 28, 2020
Collaborator
Let's please change this to SubscribePubSubHubbubOpts (Note the lower-case "bub").
SubscribePubSubHubbubOpts represents the options to be sent for the SubscribePubSubHubbub endpoint.
| // GitHub API docs: https://developer.github.com/v3/repos/hooks/#subscribing | ||
| type PubSubHubBubRequest struct { | ||
| HubMode string `json:"hub_mode,omitempty"` | ||
| HubTopic Topic `json:"hub_topic,omitempty"` |
This comment has been minimized.
This comment has been minimized.
| HubSecret string `json:"hub_secret,omitempty"` | ||
| } | ||
|
|
||
| // Topic represents GitHub repository and its particular event. |
This comment has been minimized.
This comment has been minimized.
| Event string `json:"events,omitempty"` | ||
| } | ||
|
|
||
| type pubSubHubBubPayload struct { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nightlark
May 28, 2020
•
Contributor
@gmlewis can decide if this is a change that makes sense.
If the CreatePubSubHubBubRequest request/opts parameter gets replaced with owner, repo, event string, opts PubSubHububOpts (matching the way owner/repo args are used by other functions in go-github) then pubSubHubBubPayload could get turned into PubSubHubbubOpts as was suggested elsewhere by gmlewis, and PubSubHubbubRequest could be removed entirely.
| // | ||
| // GitHub API docs: https://developer.github.com/v3/repos/hooks/#subscribing | ||
| type PubSubHubBubRequest struct { | ||
| HubMode string `json:"hub_mode,omitempty"` |
This comment has been minimized.
This comment has been minimized.
|
Hi @gmlewis @nightlark , thank you very much for the really thorough and thoughtful review! Truly appreciate it Truly sorry that I missed the I searched that the way we can construct a Thank you very much in advance |
|
I don't have time now to dig into this, but if |
joshuabezaleel commentedMay 27, 2020
Add support for repository webhooks via GitHub's PubSubHubBub API.
Fixes: #1265