|
|
@@ -80,6 +80,37 @@ func (repo *PorterAppEventRepository) ListEventsByPorterAppIDAndDeploymentTarget
|
|
|
return apps, paginatedResult, nil
|
|
|
}
|
|
|
|
|
|
+// ListEventsByPorterAppIDAndDeploymentTargetID returns a list of events for a given porter app id and deployment target id
|
|
|
+func (repo *PorterAppEventRepository) ListBuildDeployEventsByPorterAppIDAndDeploymentTargetID(ctx context.Context, porterAppID uint, deploymentTargetID uuid.UUID, opts ...helpers.QueryOption) ([]*models.PorterAppEvent, helpers.PaginatedResult, error) {
|
|
|
+ ctx, span := telemetry.NewSpan(ctx, "list-events-by-porter-app-id-and-deployment-target-id")
|
|
|
+ defer span.End()
|
|
|
+
|
|
|
+ telemetry.WithAttributes(span,
|
|
|
+ telemetry.AttributeKV{Key: "porter-app-id", Value: porterAppID},
|
|
|
+ telemetry.AttributeKV{Key: "deployment-target-id", Value: deploymentTargetID},
|
|
|
+ )
|
|
|
+
|
|
|
+ apps := []*models.PorterAppEvent{}
|
|
|
+ paginatedResult := helpers.PaginatedResult{}
|
|
|
+
|
|
|
+ id := strconv.Itoa(int(porterAppID))
|
|
|
+ if id == "" {
|
|
|
+ return nil, paginatedResult, telemetry.Error(ctx, span, nil, "invalid porter app id supplied")
|
|
|
+ }
|
|
|
+
|
|
|
+ db := repo.db.Model(&models.PorterAppEvent{})
|
|
|
+ resultDB := db.Where("porter_app_id = ? AND deployment_target_id = ? AND type != 'APP_EVENT' AND type != 'NOTIFICATION'", id, deploymentTargetID).Order("created_at DESC")
|
|
|
+ resultDB = resultDB.Scopes(helpers.Paginate(db, &paginatedResult, opts...))
|
|
|
+
|
|
|
+ if err := resultDB.Find(&apps).Error; err != nil {
|
|
|
+ if !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
+ return nil, paginatedResult, telemetry.Error(ctx, span, err, "error finding events by porter app id and deployment target id")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return apps, paginatedResult, nil
|
|
|
+}
|
|
|
+
|
|
|
func (repo *PorterAppEventRepository) CreateEvent(ctx context.Context, appEvent *models.PorterAppEvent) error {
|
|
|
if appEvent.ID == uuid.Nil {
|
|
|
appEvent.ID = uuid.New()
|