diff --git a/server/neptune/workflows/internal/deploy/revision/queue/queue.go b/server/neptune/workflows/internal/deploy/revision/queue/queue.go index 306ed6b46..bbd9d2ec8 100644 --- a/server/neptune/workflows/internal/deploy/revision/queue/queue.go +++ b/server/neptune/workflows/internal/deploy/revision/queue/queue.go @@ -3,6 +3,7 @@ package queue import ( "container/list" "fmt" + "strings" activity "github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform" "github.com/runatlantis/atlantis/server/neptune/workflows/internal/deploy/terraform" @@ -85,6 +86,17 @@ func (q *Deploy) Push(msg terraform.DeploymentInfo) { q.queue.Push(msg, Low) } +func (q *Deploy) GetQueuedRevisionsSummary() string { + var revisions []string + if q.IsEmpty() { + return "No other revisions ahead In queue." + } + for _, deploy := range q.Scan() { + revisions = append(revisions, deploy.Commit.Revision) + } + return fmt.Sprintf("Revisions in queue: %s", strings.Join(revisions, ", ")) +} + // priority is a simple 2 priority queue implementation // priority is determined before an item enters a queue and does not change type priority struct { diff --git a/server/neptune/workflows/internal/deploy/revision/queue/updater.go b/server/neptune/workflows/internal/deploy/revision/queue/updater.go index 098c66d5c..e9fa950c4 100644 --- a/server/neptune/workflows/internal/deploy/revision/queue/updater.go +++ b/server/neptune/workflows/internal/deploy/revision/queue/updater.go @@ -2,6 +2,7 @@ package queue import ( "fmt" + key "github.com/runatlantis/atlantis/server/neptune/context" "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" @@ -24,12 +25,13 @@ func (u *LockStateUpdater) UpdateQueuedRevisions(ctx workflow.Context, queue *De var actions []github.CheckRunAction var summary string + var revisionsSummary string = queue.GetQueuedRevisionsSummary() state := github.CheckRunQueued if lock.Status == LockedStatus { actions = append(actions, github.CreateUnlockAction()) state = github.CheckRunActionRequired revisionLink := github.BuildRevisionURLMarkdown(repoFullName, lock.Revision) - summary = fmt.Sprintf("This deploy is locked from a manual deployment for revision %s. Unlock to proceed.", revisionLink) + summary = fmt.Sprintf("This deploy is locked from a manual deployment for revision %s. Unlock to proceed.\n%s", revisionLink, revisionsSummary) } for _, i := range infos { diff --git a/server/neptune/workflows/internal/deploy/revision/revision.go b/server/neptune/workflows/internal/deploy/revision/revision.go index 02f0d1424..48de52081 100644 --- a/server/neptune/workflows/internal/deploy/revision/revision.go +++ b/server/neptune/workflows/internal/deploy/revision/revision.go @@ -46,6 +46,7 @@ type Queue interface { GetLockState() queue.LockState SetLockForMergedItems(ctx workflow.Context, state queue.LockState) Scan() []terraform.DeploymentInfo + GetQueuedRevisionsSummary() string } type DeploymentStore interface { @@ -136,14 +137,15 @@ func (n *Receiver) Receive(c workflow.ReceiveChannel, more bool) { func (n *Receiver) createCheckRun(ctx workflow.Context, id, revision string, root activity.Root, repo github.Repo) int64 { lock := n.queue.GetLockState() var actions []github.CheckRunAction - summary := "This deploy is queued and will be processed as soon as possible." + var revisionsSummary string = n.queue.GetQueuedRevisionsSummary() + summary := "This deploy is queued and will be processed as soon as possible.\n" + revisionsSummary state := github.CheckRunQueued if lock.Status == queue.LockedStatus && (root.TriggerInfo.Type == activity.MergeTrigger) { actions = append(actions, github.CreateUnlockAction()) state = github.CheckRunActionRequired revisionLink := github.BuildRevisionURLMarkdown(repo.GetFullName(), lock.Revision) - summary = fmt.Sprintf("This deploy is locked from a manual deployment for revision %s. Unlock to proceed.", revisionLink) + summary = fmt.Sprintf("This deploy is locked from a manual deployment for revision %s. Unlock to proceed.\n%s", revisionLink, revisionsSummary) } cid, err := n.checkRunClient.CreateOrUpdate(ctx, id, notifier.GithubCheckRunRequest{ diff --git a/server/neptune/workflows/internal/deploy/revision/revision_test.go b/server/neptune/workflows/internal/deploy/revision/revision_test.go index d80d7073a..84c291a16 100644 --- a/server/neptune/workflows/internal/deploy/revision/revision_test.go +++ b/server/neptune/workflows/internal/deploy/revision/revision_test.go @@ -1,10 +1,13 @@ package revision_test import ( - "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" + "fmt" + "strings" "testing" "time" + "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" + "github.com/google/uuid" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform" @@ -13,6 +16,7 @@ import ( "github.com/runatlantis/atlantis/server/neptune/workflows/internal/deploy/revision/queue" terraformWorkflow "github.com/runatlantis/atlantis/server/neptune/workflows/internal/deploy/terraform" "github.com/stretchr/testify/assert" + "go.temporal.io/sdk/temporal" "go.temporal.io/sdk/testsuite" "go.temporal.io/sdk/workflow" ) @@ -23,8 +27,11 @@ type testCheckRunClient struct { } func (t *testCheckRunClient) CreateOrUpdate(ctx workflow.Context, deploymentID string, request notifier.GithubCheckRunRequest) (int64, error) { - assert.Equal(t.expectedT, t.expectedRequest, request) - + ok := assert.Equal(t.expectedT, t.expectedRequest, request) + if !ok { + return 1, temporal.NewApplicationError("failing workflow", "myType") + // t.expectedT.Exit("CreateOrUpdate had unexpected request") + } return 1, nil } @@ -49,6 +56,21 @@ func (q *testQueue) SetLockForMergedItems(ctx workflow.Context, state queue.Lock q.Lock = state } +func (q *testQueue) IsEmpty() bool { + return q.Queue == nil || len(q.Queue) == 0 +} + +func (q *testQueue) GetQueuedRevisionsSummary() string { + var revisions []string + if q.IsEmpty() { + return "No other revisions ahead In queue." + } + for _, deploy := range q.Scan() { + revisions = append(revisions, deploy.Commit.Revision) + } + return fmt.Sprintf("Revisions in queue: %s", strings.Join(revisions, ", ")) +} + type testWorker struct { Current queue.CurrentDeployment } @@ -137,10 +159,11 @@ func TestEnqueue(t *testing.T) { env.ExecuteWorkflow(testWorkflow, req{ ID: id, ExpectedRequest: notifier.GithubCheckRunRequest{ - Title: "atlantis/deploy: root", - Sha: rev, - Repo: github.Repo{Name: "nish"}, - State: github.CheckRunQueued, + Title: "atlantis/deploy: root", + Sha: rev, + Repo: github.Repo{Name: "nish"}, + State: github.CheckRunQueued, + Summary: "This deploy is queued and will be processed as soon as possible.\nNo other revisions ahead In queue.", }, ExpectedT: t, }) @@ -197,10 +220,11 @@ func TestEnqueue_ManualTrigger(t *testing.T) { env.ExecuteWorkflow(testWorkflow, req{ ID: id, ExpectedRequest: notifier.GithubCheckRunRequest{ - Title: "atlantis/deploy: root", - Sha: rev, - Repo: github.Repo{Name: "nish"}, - State: github.CheckRunQueued, + Title: "atlantis/deploy: root", + Sha: rev, + Repo: github.Repo{Name: "nish"}, + State: github.CheckRunQueued, + Summary: "This deploy is queued and will be processed as soon as possible.\nNo other revisions ahead In queue.", }, ExpectedT: t, }) @@ -263,10 +287,11 @@ func TestEnqueue_ManualTrigger_QueueAlreadyLocked(t *testing.T) { Revision: "123334444555", }, ExpectedRequest: notifier.GithubCheckRunRequest{ - Title: "atlantis/deploy: root", - Sha: rev, - Repo: github.Repo{Name: "nish"}, - State: github.CheckRunQueued, + Title: "atlantis/deploy: root", + Sha: rev, + Repo: github.Repo{Name: "nish"}, + State: github.CheckRunQueued, + Summary: "This deploy is queued and will be processed as soon as possible.\nNo other revisions ahead In queue.", }, ExpectedT: t, }) @@ -321,8 +346,22 @@ func TestEnqueue_MergeTrigger_QueueAlreadyLocked(t *testing.T) { id := uuid.Must(uuid.NewUUID()) + deploymentInfo := terraformWorkflow.DeploymentInfo{ + Commit: github.Commit{ + Revision: "123334444555", + Branch: "locking-branch", + }, + CheckRunID: 0, + Root: terraform.Root{Name: "root", TriggerInfo: terraform.TriggerInfo{ + Type: terraform.MergeTrigger, + }, Trigger: terraform.MergeTrigger}, + ID: id, + Repo: github.Repo{Name: "nish"}, + } + env.ExecuteWorkflow(testWorkflow, req{ - ID: id, + ID: id, + InitialElements: []terraformWorkflow.DeploymentInfo{deploymentInfo}, Lock: queue.LockState{ // ensure that the lock gets updated Status: queue.LockedStatus, @@ -332,7 +371,7 @@ func TestEnqueue_MergeTrigger_QueueAlreadyLocked(t *testing.T) { Title: "atlantis/deploy: root", Sha: rev, Repo: github.Repo{Name: "nish"}, - Summary: "This deploy is locked from a manual deployment for revision [123334444555](https://github.com//nish/commit/123334444555). Unlock to proceed.", + Summary: "This deploy is locked from a manual deployment for revision [123334444555](https://github.com//nish/commit/123334444555). Unlock to proceed.\nRevisions in queue: 12333444455", Actions: []github.CheckRunAction{github.CreateUnlockAction()}, State: github.CheckRunActionRequired, }, @@ -346,6 +385,7 @@ func TestEnqueue_MergeTrigger_QueueAlreadyLocked(t *testing.T) { assert.NoError(t, err) assert.Equal(t, []terraformWorkflow.DeploymentInfo{ + deploymentInfo, { Commit: github.Commit{ Revision: rev,