Skip to content

Commit

Permalink
fix: rename Pending to PendingApproval on playbook run status
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored and moshloop committed Oct 15, 2024
1 parent 6c87259 commit 8a433be
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion db/playbooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func UpdatePlaybookRunStatusIfApproved(ctx context.Context, playbookID string, a
SELECT run_id FROM run_approvals WHERE approvers %s (SELECT array_agg(id) FROM allowed_approvers)
)`, operator)

tx := ctx.DB().Exec(query, approval.Approvers.Teams, approval.Approvers.People, models.PlaybookRunStatusScheduled, models.PlaybookRunStatusPending, playbookID)
tx := ctx.DB().Exec(query, approval.Approvers.Teams, approval.Approvers.People, models.PlaybookRunStatusScheduled, models.PlaybookRunStatusPendingApproval, playbookID)
if tx.RowsAffected > 0 {
ctx.Tracef("[%s] %d playbook runs approved", playbookID, tx.RowsAffected)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/containrrr/shoutrrr v0.8.0
github.com/fergusstrange/embedded-postgres v1.25.0 // indirect
github.com/flanksource/commons v1.29.10
github.com/flanksource/duty v1.0.707
github.com/flanksource/duty v1.0.708
github.com/flanksource/gomplate/v3 v3.24.35
github.com/flanksource/kopper v1.0.10
github.com/gomarkdown/markdown v0.0.0-20240419095408-642f0ee99ae2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,8 @@ github.com/flanksource/artifacts v1.0.14 h1:Vv70bccsae0MwGaf/uSPp34J5V1/PyKfct9z
github.com/flanksource/artifacts v1.0.14/go.mod h1:qHVCnQu5k50aWNJ5UhpcAKEl7pAzqUrFFKGSm147G70=
github.com/flanksource/commons v1.29.10 h1:T/S95Pl8kASEFvQjQ7fJjTUqeVdhxQXg1vfkULTYFJQ=
github.com/flanksource/commons v1.29.10/go.mod h1:iTbrXOSp3Spv570Nly97D/U9cQjLZoVlmWCXqWzsvRU=
github.com/flanksource/duty v1.0.707 h1:cFhPHVVEaFdy7/+U3u7QY9LUaK6FEuqQ7pa1HHyL9AU=
github.com/flanksource/duty v1.0.707/go.mod h1:4ZNkZ3n0Vtx+wqQoto36Z139U9TBWlCYEpAwuqZiCQk=
github.com/flanksource/duty v1.0.708 h1:TukO3jOk7z1m5+Wu1jf9k60f9yOwxzPGCjPFl3sZHk8=
github.com/flanksource/duty v1.0.708/go.mod h1:4ZNkZ3n0Vtx+wqQoto36Z139U9TBWlCYEpAwuqZiCQk=
github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc=
github.com/flanksource/gomplate/v3 v3.24.35 h1:6grps46JjAQI7haaGbiJXDQb6qxat0Ra9EN99iaBHVQ=
github.com/flanksource/gomplate/v3 v3.24.35/go.mod h1:W/jhtuxSmCVFZibf11qJOSceEq++DEL0eCj/F0Y+zVY=
Expand Down
13 changes: 6 additions & 7 deletions playbook/events.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package playbook

import (
"fmt"
"time"

"encoding/json"
"fmt"
"strconv"
"strings"
"time"

"github.com/flanksource/commons/collections"
"github.com/flanksource/commons/logger"
Expand Down Expand Up @@ -174,12 +173,12 @@ func (t *playbookScheduler) Handle(ctx context.Context, event models.Event) erro

run := models.PlaybookRun{
PlaybookID: p.ID,
Status: models.PlaybookRunStatusPending,
Status: models.PlaybookRunStatusScheduled,
Spec: p.Spec,
}

if playbook.Spec.Approval == nil || playbook.Spec.Approval.Approvers.Empty() {
run.Status = models.PlaybookRunStatusScheduled
if playbook.Spec.Approval != nil && !playbook.Spec.Approval.Approvers.Empty() {
run.Status = models.PlaybookRunStatusPendingApproval
}

switch specEvent.Class {
Expand Down Expand Up @@ -294,7 +293,7 @@ func onPlaybookRunNewApproval(ctx context.Context, event models.Event) error {
return err
}

if run.Status != models.PlaybookRunStatusPending {
if run.Status != models.PlaybookRunStatusPendingApproval {
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions playbook/playbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type PlaybookSummary struct {
}

func GetPlaybookStatus(ctx context.Context, runId uuid.UUID) (PlaybookSummary, error) {
var summary = PlaybookSummary{}
summary := PlaybookSummary{}
run, err := models.PlaybookRun{ID: runId}.Load(ctx.DB())
if err != nil {
return summary, err
Expand Down Expand Up @@ -88,7 +88,7 @@ func Run(ctx context.Context, playbook *models.Playbook, req RunParams) (*models

run := models.PlaybookRun{
PlaybookID: playbook.ID,
Status: models.PlaybookRunStatusPending,
Status: models.PlaybookRunStatusScheduled,
Parameters: req.Params,
AgentID: req.AgentID,
}
Expand All @@ -101,8 +101,8 @@ func Run(ctx context.Context, playbook *models.Playbook, req RunParams) (*models
run.CreatedBy = &ctx.User().ID
}

if spec.Approval == nil || spec.Approval.Approvers.Empty() {
run.Status = models.PlaybookRunStatusScheduled
if spec.Approval != nil && !spec.Approval.Approvers.Empty() {
run.Status = models.PlaybookRunStatusPendingApproval
}

if req.ComponentID != nil {
Expand Down

0 comments on commit 8a433be

Please sign in to comment.