-
Notifications
You must be signed in to change notification settings - Fork 116
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 ability to send webhooks to external tools #367
add ability to send webhooks to external tools #367
Conversation
c3d420f
to
ca16706
Compare
ca16706
to
1bb65c9
Compare
210e39f
to
c517311
Compare
c050e03
to
6997687
Compare
tests/webhooks_receiver.go
Outdated
func NewRunEventsHandler(log zerolog.Logger, runPhases *[]rstypes.RunPhase) *runEventsHandler { | ||
return &runEventsHandler{log: log, runPhases: runPhases} | ||
} | ||
|
||
func (h *runEventsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
if err := util.HTTPResponse(w, http.StatusOK, h.runPhases); err != nil { | ||
h.log.Err(err).Send() | ||
} | ||
} |
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 isn't needed
6997687
to
91f09ea
Compare
586a6f3
to
fb1e4bb
Compare
d7d8274
to
b47ebeb
Compare
b47ebeb
to
8434abc
Compare
a780086
to
e9ba480
Compare
19de66a
to
3985e48
Compare
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.
internal/migration should not be changed.
3985e48
to
6c76360
Compare
@@ -92,7 +92,7 @@ func (n *NotificationService) runEventsHandler(ctx context.Context) error { | |||
data := buf.Bytes() | |||
buf.Reset() | |||
|
|||
var ev *rstypes.RunEvent |
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.
keep the pointer as before var ev *rstypes.RunEvent
Annotations map[string]string `json:"annotations,omitempty"` | ||
} | ||
|
||
type RunStatusTask struct { |
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.
RunEventDataRunTask
Name string `json:"name,omitempty"` | ||
Level int `json:"level,omitempty"` | ||
Skip bool `json:"skip,omitempty"` | ||
Depends map[string]*RunStatusTaskDepend `json:"depends,omitempty"` |
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.
RunEventDataRunTaskDepend
6c76360
to
0c4f1d0
Compare
@sgotti can you do the review please? |
} | ||
} | ||
default: | ||
n.log.Info().Msgf("run event %q is not valid", ev.RunEventType) |
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.
Error level ?
} | ||
if n.c.WebhookURL != "" { | ||
if err := n.sendWebhooks(ctx, ev); err != nil { | ||
n.log.Info().Msgf("failed to update run status") |
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.
Error level?
switch ev.RunEventType { | ||
case rstypes.RunPhaseChanged: | ||
if err := n.updateCommitStatus(ctx, ev); err != nil { | ||
n.log.Info().Msgf("failed to update commit status") |
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.
Error level?
|
||
// the trigger of the event | ||
// (i.e. the value run_phase_changed indicate a run phase changed event) | ||
EventType string `json:"event_type"` |
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.
What is EventType? Is it the same as github webhook action
field? If so call it action since we already have the Event header and the name are too similar and confusing.
See https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request for further info.
} | ||
|
||
type ProjectInfo struct { | ||
// id of the project |
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.
always start descriptions with the variable name:
// ProjectID is the ID of the project
But in this case I don't think it's needed.
) | ||
|
||
type RunWebhook struct { | ||
// version of the webhook struct data |
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.
always start descriptions with the variable name
|
||
// the trigger of the event | ||
// (i.e. the value run_phase_changed indicate a run phase changed event) | ||
EventType string `json:"event_type"` |
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.
Use a dedicated enum for EventType/Action and add the description there and not here
return errors.WithStack(err) | ||
} | ||
req.Header.Add("Content-Type", "application/json") | ||
req.Header.Add(agolaEventHeader, "run") |
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.
Use a dedicated enum for the event header values
00a0571
to
8ef7eb7
Compare
@sgotti can you do the review please? |
8ef7eb7
to
6e86b45
Compare
|
||
func (e *RunEvent) PreJSON() error { | ||
switch e.DataVersion { | ||
|
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.
not needed empty line
6e86b45
to
35840ca
Compare
35840ca
to
7526c64
Compare
7526c64
to
dabda70
Compare
notification: add ability to send webhook on run events config: add configuration for webhooks
dabda70
to
cdb81d6
Compare
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.
@alessandro-sorint We can go with this, given that this is just a first step and the data format won't be stable until 0.9.0. I also have different changes that I'll do in future.
No description provided.