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

[WaitApproval Plugin] Add NotifyEvent methods #5613

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

t-kikuc
Copy link
Member

@t-kikuc t-kikuc commented Feb 28, 2025

What this PR does:

I implemented NotifyEvent methods in both piped and plugin side.

Why we need it:

The WaitApproval plugin needs to:

  • notify approvers when the stage starts (NotificationEventDeploymentWaitApproval)
  • notify when approval is completed (NotificationEventDeploymentApproved)

cf.

func (e *Executor) reportApproved(approver string) {
users, groups, err := e.getApplicationNotificationMentions(model.NotificationEventType_EVENT_DEPLOYMENT_APPROVED)
if err != nil {
e.Logger.Error("failed to get the list of users or groups", zap.Error(err))
}
e.Notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_APPROVED,
Metadata: &model.NotificationEventDeploymentApproved{
Deployment: e.Deployment,
Approver: approver,
MentionedAccounts: users,
MentionedGroups: groups,
},
})
}
func (e *Executor) reportRequiringApproval() {
users, groups, err := e.getApplicationNotificationMentions(model.NotificationEventType_EVENT_DEPLOYMENT_WAIT_APPROVAL)
if err != nil {
e.Logger.Error("failed to get the list of users or groups", zap.Error(err))
}
e.Notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_WAIT_APPROVAL,
Metadata: &model.NotificationEventDeploymentWaitApproval{
Deployment: e.Deployment,
MentionedAccounts: users,
MentionedGroups: groups,
},
})
}

Which issue(s) this PR fixes:

Part of #5367

Does this PR introduce a user-facing change?:

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

Comment on lines +198 to +215
func getMentionTargets(ctx context.Context, e model.NotificationEventType, deploymentID string, msr *metadatastore.MetadataStoreRegistry) (users []string, groups []string, err error) {
n, err := msr.GetDeploymentSharedMetadata(ctx, &service.GetDeploymentSharedMetadataRequest{
DeploymentId: deploymentID,
Key: model.MetadataKeyDeploymentNotification,
})
if err != nil {
return []string{}, []string{}, err
}
if !n.Found {
return []string{}, []string{}, nil
}

var notif config.DeploymentNotification
if err := json.Unmarshal([]byte(n.Value), &notif); err != nil {
return nil, nil, fmt.Errorf("could not extract mentions users and groups config: %w", err)
}

return notif.FindSlackUsers(e), notif.FindSlackGroups(e), nil
Copy link
Member Author

Choose a reason for hiding this comment

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

I referred to here:

// getMentionedUsers returns the list of users groups who should be mentioned in the notification.
func (e *Executor) getApplicationNotificationMentions(event model.NotificationEventType) ([]string, []string, error) {
n, ok := e.MetadataStore.Shared().Get(model.MetadataKeyDeploymentNotification)
if !ok {
return []string{}, []string{}, nil
}
var notification config.DeploymentNotification
if err := json.Unmarshal([]byte(n), &notification); err != nil {
return nil, nil, fmt.Errorf("could not extract mentions users and groups config: %w", err)
}
return notification.FindSlackUsers(event), notification.FindSlackGroups(event), nil
}

Copy link

codecov bot commented Feb 28, 2025

Codecov Report

Attention: Patch coverage is 2.85714% with 68 lines in your changes missing coverage. Please review.

Project coverage is 26.55%. Comparing base (93e9a27) to head (964ddaf).

Files with missing lines Patch % Lines
pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go 0.00% 47 Missing ⚠️
pkg/plugin/sdk/client.go 0.00% 11 Missing ⚠️
pkg/plugin/sdk/deployment.go 18.18% 9 Missing ⚠️
pkg/app/pipedv1/cmd/piped/piped.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5613      +/-   ##
==========================================
- Coverage   26.58%   26.55%   -0.04%     
==========================================
  Files         474      474              
  Lines       50546    50614      +68     
==========================================
+ Hits        13438    13439       +1     
- Misses      36045    36112      +67     
  Partials     1063     1063              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant