fix: correct the retention webhook payload (#18462)

Fix the incorrect number of total and retained in the retention webhook
payload, and completes the deleted_artifacts field.

Fixes: #18428

Signed-off-by: chlins <chenyuzh@vmware.com>
This commit is contained in:
Chlins Zhang 2023-04-03 17:51:02 +08:00 committed by GitHub
parent 1499faf67d
commit 02c51c6b70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View File

@ -119,8 +119,8 @@ func (r *RetentionHandler) constructRetentionPayload(ctx context.Context, event
Operator: execution.Trigger, Operator: execution.Trigger,
EventData: &model.EventData{ EventData: &model.EventData{
Retention: &evtModel.Retention{ Retention: &evtModel.Retention{
Total: task.Total, Total: event.Total,
Retained: task.Retained, Retained: event.Retained,
HarborHostname: hostname, HarborHostname: hostname,
ProjectName: event.Deleted[0].Target.Namespace, ProjectName: event.Deleted[0].Target.Namespace,
RetentionPolicyID: execution.PolicyID, RetentionPolicyID: execution.PolicyID,
@ -138,8 +138,11 @@ func (r *RetentionHandler) constructRetentionPayload(ctx context.Context, event
} }
if len(target.Tags) != 0 { if len(target.Tags) != 0 {
deletedArtifact.NameAndTag = target.Repository + ":" + target.Tags[0] deletedArtifact.NameAndTag = target.Repository + ":" + target.Tags[0]
} else {
// use digest if no tag
deletedArtifact.NameAndTag = target.Repository + "@" + target.Digest
} }
payload.EventData.Retention.DeletedArtifact = []*evtModel.ArtifactInfo{deletedArtifact} payload.EventData.Retention.DeletedArtifact = append(payload.EventData.Retention.DeletedArtifact, deletedArtifact)
} }
for _, v := range md.Rules { for _, v := range md.Rules {

View File

@ -25,6 +25,8 @@ func (r *RetentionMetaData) Resolve(evt *event.Event) error {
Status: r.Status, Status: r.Status,
Deleted: r.Deleted, Deleted: r.Deleted,
TaskID: r.TaskID, TaskID: r.TaskID,
Total: r.Total,
Retained: r.Retained,
} }
evt.Topic = event2.TopicTagRetention evt.Topic = event2.TopicTagRetention

View File

@ -353,6 +353,8 @@ type RetentionEvent struct {
OccurAt time.Time OccurAt time.Time
Status string Status string
Deleted []*selector.Result Deleted []*selector.Result
Total int
Retained int
} }
func (r *RetentionEvent) String() string { func (r *RetentionEvent) String() string {