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 ability to send webhooks to external tools #367

Merged
merged 1 commit into from
Jun 29, 2023

Conversation

alessandro-sorint
Copy link
Contributor

No description provided.

internal/services/config/config.go Outdated Show resolved Hide resolved
internal/services/notification/runstatus.go Outdated Show resolved Hide resolved
services/runservice/types/runevent.go Outdated Show resolved Hide resolved
services/runservice/types/runevent.go Outdated Show resolved Hide resolved
services/runservice/types/runevent.go Outdated Show resolved Hide resolved
internal/services/notification/runevents.go Outdated Show resolved Hide resolved
internal/services/notification/runevents.go Outdated Show resolved Hide resolved
tests/setup_test.go Outdated Show resolved Hide resolved
tests/setup_test.go Outdated Show resolved Hide resolved
internal/services/config/config.go Outdated Show resolved Hide resolved
internal/services/config/config.go Outdated Show resolved Hide resolved
@alessandro-sorint alessandro-sorint force-pushed the webhook-notification branch 2 times, most recently from 210e39f to c517311 Compare February 2, 2023 15:56
internal/services/notification/runstatus.go Outdated Show resolved Hide resolved
internal/services/notification/runstatus.go Outdated Show resolved Hide resolved
@alessandro-sorint alessandro-sorint force-pushed the webhook-notification branch 3 times, most recently from c050e03 to 6997687 Compare February 3, 2023 11:24
internal/services/notification/runevents.go Outdated Show resolved Hide resolved
tests/webhooks_receiver.go Outdated Show resolved Hide resolved
tests/webhooks_receiver.go Outdated Show resolved Hide resolved
tests/webhooks_receiver.go Outdated Show resolved Hide resolved
tests/webhooks_receiver.go Outdated Show resolved Hide resolved
tests/webhooks_receiver.go Outdated Show resolved Hide resolved
Comment on lines 154 to 162
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()
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This isn't needed

tests/webhooks_receiver.go Outdated Show resolved Hide resolved
tests/webhooks_receiver.go Outdated Show resolved Hide resolved
tests/webhooks_receiver.go Outdated Show resolved Hide resolved
internal/services/notification/runstatus.go Outdated Show resolved Hide resolved
tests/webhooksreceiver.go Outdated Show resolved Hide resolved
tests/webhooksreceiver.go Outdated Show resolved Hide resolved
@alessandro-sorint alessandro-sorint force-pushed the webhook-notification branch 3 times, most recently from 586a6f3 to fb1e4bb Compare February 6, 2023 15:26
internal/services/notification/runevents.go Outdated Show resolved Hide resolved
tests/webhooksreceiver.go Outdated Show resolved Hide resolved
@alessandro-sorint alessandro-sorint force-pushed the webhook-notification branch 2 times, most recently from d7d8274 to b47ebeb Compare February 8, 2023 10:21
@alessandro-sorint alessandro-sorint force-pushed the webhook-notification branch 4 times, most recently from 19de66a to 3985e48 Compare June 22, 2023 09:54
Copy link
Member

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.

@@ -92,7 +92,7 @@ func (n *NotificationService) runEventsHandler(ctx context.Context) error {
data := buf.Bytes()
buf.Reset()

var ev *rstypes.RunEvent
Copy link
Member

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 {
Copy link
Member

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"`
Copy link
Member

Choose a reason for hiding this comment

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

RunEventDataRunTaskDepend

internal/services/notification/webhooks.go Show resolved Hide resolved
@alessandro-sorint
Copy link
Contributor Author

@sgotti can you do the review please?

}
}
default:
n.log.Info().Msgf("run event %q is not valid", ev.RunEventType)
Copy link
Member

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")
Copy link
Member

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")
Copy link
Member

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"`
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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"`
Copy link
Member

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")
Copy link
Member

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

services/runservice/types/runevent.go Outdated Show resolved Hide resolved
services/runservice/types/runevent.go Outdated Show resolved Hide resolved
@alessandro-sorint alessandro-sorint force-pushed the webhook-notification branch 2 times, most recently from 00a0571 to 8ef7eb7 Compare June 28, 2023 13:36
@alessandro-sorint
Copy link
Contributor Author

@sgotti can you do the review please?


func (e *RunEvent) PreJSON() error {
switch e.DataVersion {

Copy link
Member

Choose a reason for hiding this comment

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

not needed empty line

internal/services/notification/webhooks.go Outdated Show resolved Hide resolved
internal/services/notification/webhooks.go Outdated Show resolved Hide resolved
internal/services/notification/webhooks.go Outdated Show resolved Hide resolved
notification: add ability to send webhook on run events
config: add configuration for webhooks
Copy link
Member

@sgotti sgotti left a 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.

@sgotti sgotti merged commit a61634a into agola-io:master Jun 29, 2023
1 check passed
@alessandro-sorint alessandro-sorint deleted the webhook-notification branch June 30, 2023 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants