-
Notifications
You must be signed in to change notification settings - Fork 1.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
feat: add http webhook #5233
feat: add http webhook #5233
Conversation
bbb3a44
to
d6774bf
Compare
Signed-off-by: Piotr Pawluk <[email protected]>
24cf799
to
9bd4c5d
Compare
Rebased |
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.
Nice! I left a few small comments but overall nice addition!
server/events/webhooks/http.go
Outdated
} | ||
|
||
// RoundTrip handles each http request. | ||
func (t *AuthedTransport) RoundTrip(req *http.Request) (*http.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.
https://pkg.go.dev/net/http#RoundTripper says
RoundTrip should not modify the request, except for consuming and closing the Request's Body
I'm not very familiar with the http package, so I'm not sure what the implications are if the request is modified (or if adding headers qualifies as "modifying"), any thoughts here?
As an alternative you could always pass the headers into the webhook itself then set them on doSend()
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'm not very familiar with the http package, so I'm not sure what the implications are if the request is modified (or if adding headers qualifies as "modifying"), any thoughts here?
The oauth package does the same pattern for authorization and I initially planned to follow (even forgot to change name) but maybe it's an overkill; adding headers explicitly will be less confusing.
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.
Yeah, as long as it doesn't complicate doSend() too much it might be worth it.
Also looking at that example, it looks like it actually makes a clone of the request, I assume to comply w the part of the doc I quoted above?
req2 := cloneRequest(req) // per RoundTripper contract
If it ends up being better to do this via a RoundTripper, I wonder if this might be a better approach?
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.
Yeah I just went with adding headers explicitly in 5939aad
server/events/webhooks/http.go
Outdated
return nil | ||
} | ||
|
||
func (h *HttpWebhook) doSend(_ logging.SimpleLogging, applyResult ApplyResult) 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.
Since doSend()
is a non-exported method (i.e. unlike Send()
) you should be able to omit logging.SimpleLogging
altogether instead of passing it in and not using it.
(Though this does mean you'll have to make logging.SimpleLogging _
in Send()
)
Signed-off-by: Piotr Pawluk <[email protected]>
Signed-off-by: Piotr Pawluk <[email protected]>
Looks good to me! |
thanks @zendesk-piotrpawluk for the contribution |
what
Adding HTTP webhook implementation to send notifications to any HTTP(S) endpoint.
http
webhook kind--webhook-http-headers
optional parameter to pass any extra headers with the requestProjectName
to webhook payloadwhy
To send notifications to other systems than just Slack. Feature request: #810
tests
references