Skip to content

Commit 4a5c4a0

Browse files
committed
add revisions on queue to checkrun summary
1 parent 5368355 commit 4a5c4a0

File tree

4 files changed

+76
-20
lines changed

4 files changed

+76
-20
lines changed

server/neptune/workflows/internal/deploy/revision/queue/queue.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package queue
33
import (
44
"container/list"
55
"fmt"
6+
"strings"
67

78
activity "github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform"
89
"github.com/runatlantis/atlantis/server/neptune/workflows/internal/deploy/terraform"
@@ -85,6 +86,17 @@ func (q *Deploy) Push(msg terraform.DeploymentInfo) {
8586
q.queue.Push(msg, Low)
8687
}
8788

89+
func (q *Deploy) GetQueuedRevisionsSummary() string {
90+
var revisions []string
91+
if q.IsEmpty() {
92+
return "No other revisions ahead In queue."
93+
}
94+
for _, deploy := range q.Scan() {
95+
revisions = append(revisions, deploy.Commit.Revision)
96+
}
97+
return fmt.Sprintf("Revisions in queue: %s", strings.Join(revisions, ", "))
98+
}
99+
88100
// priority is a simple 2 priority queue implementation
89101
// priority is determined before an item enters a queue and does not change
90102
type priority struct {

server/neptune/workflows/internal/deploy/revision/queue/updater.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package queue
22

33
import (
44
"fmt"
5+
56
key "github.com/runatlantis/atlantis/server/neptune/context"
67
"github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier"
78

@@ -24,12 +25,13 @@ func (u *LockStateUpdater) UpdateQueuedRevisions(ctx workflow.Context, queue *De
2425

2526
var actions []github.CheckRunAction
2627
var summary string
28+
var revisionsSummary string = queue.GetQueuedRevisionsSummary()
2729
state := github.CheckRunQueued
2830
if lock.Status == LockedStatus {
2931
actions = append(actions, github.CreateUnlockAction())
3032
state = github.CheckRunActionRequired
3133
revisionLink := github.BuildRevisionURLMarkdown(repoFullName, lock.Revision)
32-
summary = fmt.Sprintf("This deploy is locked from a manual deployment for revision %s. Unlock to proceed.", revisionLink)
34+
summary = fmt.Sprintf("This deploy is locked from a manual deployment for revision %s. Unlock to proceed.\n%s", revisionLink, revisionsSummary)
3335
}
3436

3537
for _, i := range infos {

server/neptune/workflows/internal/deploy/revision/revision.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Queue interface {
4646
GetLockState() queue.LockState
4747
SetLockForMergedItems(ctx workflow.Context, state queue.LockState)
4848
Scan() []terraform.DeploymentInfo
49+
GetQueuedRevisionsSummary() string
4950
}
5051

5152
type DeploymentStore interface {
@@ -136,14 +137,15 @@ func (n *Receiver) Receive(c workflow.ReceiveChannel, more bool) {
136137
func (n *Receiver) createCheckRun(ctx workflow.Context, id, revision string, root activity.Root, repo github.Repo) int64 {
137138
lock := n.queue.GetLockState()
138139
var actions []github.CheckRunAction
139-
summary := "This deploy is queued and will be processed as soon as possible."
140+
var revisionsSummary string = n.queue.GetQueuedRevisionsSummary()
141+
summary := "This deploy is queued and will be processed as soon as possible.\n" + revisionsSummary
140142
state := github.CheckRunQueued
141143

142144
if lock.Status == queue.LockedStatus && (root.TriggerInfo.Type == activity.MergeTrigger) {
143145
actions = append(actions, github.CreateUnlockAction())
144146
state = github.CheckRunActionRequired
145147
revisionLink := github.BuildRevisionURLMarkdown(repo.GetFullName(), lock.Revision)
146-
summary = fmt.Sprintf("This deploy is locked from a manual deployment for revision %s. Unlock to proceed.", revisionLink)
148+
summary = fmt.Sprintf("This deploy is locked from a manual deployment for revision %s. Unlock to proceed.\n%s", revisionLink, revisionsSummary)
147149
}
148150

149151
cid, err := n.checkRunClient.CreateOrUpdate(ctx, id, notifier.GithubCheckRunRequest{

server/neptune/workflows/internal/deploy/revision/revision_test.go

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package revision_test
22

33
import (
4-
"github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier"
4+
"fmt"
5+
"strings"
56
"testing"
67
"time"
78

9+
"github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier"
10+
811
"github.com/google/uuid"
912
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/github"
1013
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform"
@@ -13,6 +16,7 @@ import (
1316
"github.com/runatlantis/atlantis/server/neptune/workflows/internal/deploy/revision/queue"
1417
terraformWorkflow "github.com/runatlantis/atlantis/server/neptune/workflows/internal/deploy/terraform"
1518
"github.com/stretchr/testify/assert"
19+
"go.temporal.io/sdk/temporal"
1620
"go.temporal.io/sdk/testsuite"
1721
"go.temporal.io/sdk/workflow"
1822
)
@@ -23,8 +27,11 @@ type testCheckRunClient struct {
2327
}
2428

2529
func (t *testCheckRunClient) CreateOrUpdate(ctx workflow.Context, deploymentID string, request notifier.GithubCheckRunRequest) (int64, error) {
26-
assert.Equal(t.expectedT, t.expectedRequest, request)
27-
30+
ok := assert.Equal(t.expectedT, t.expectedRequest, request)
31+
if !ok {
32+
return 1, temporal.NewApplicationError("failing workflow", "myType")
33+
// t.expectedT.Exit("CreateOrUpdate had unexpected request")
34+
}
2835
return 1, nil
2936
}
3037

@@ -49,6 +56,21 @@ func (q *testQueue) SetLockForMergedItems(ctx workflow.Context, state queue.Lock
4956
q.Lock = state
5057
}
5158

59+
func (q *testQueue) IsEmpty() bool {
60+
return q.Queue == nil || len(q.Queue) == 0
61+
}
62+
63+
func (q *testQueue) GetQueuedRevisionsSummary() string {
64+
var revisions []string
65+
if q.IsEmpty() {
66+
return "No other revisions ahead In queue."
67+
}
68+
for _, deploy := range q.Scan() {
69+
revisions = append(revisions, deploy.Commit.Revision)
70+
}
71+
return fmt.Sprintf("Revisions in queue: %s", strings.Join(revisions, ", "))
72+
}
73+
5274
type testWorker struct {
5375
Current queue.CurrentDeployment
5476
}
@@ -137,10 +159,11 @@ func TestEnqueue(t *testing.T) {
137159
env.ExecuteWorkflow(testWorkflow, req{
138160
ID: id,
139161
ExpectedRequest: notifier.GithubCheckRunRequest{
140-
Title: "atlantis/deploy: root",
141-
Sha: rev,
142-
Repo: github.Repo{Name: "nish"},
143-
State: github.CheckRunQueued,
162+
Title: "atlantis/deploy: root",
163+
Sha: rev,
164+
Repo: github.Repo{Name: "nish"},
165+
State: github.CheckRunQueued,
166+
Summary: "This deploy is queued and will be processed as soon as possible.\nNo other revisions ahead In queue.",
144167
},
145168
ExpectedT: t,
146169
})
@@ -197,10 +220,11 @@ func TestEnqueue_ManualTrigger(t *testing.T) {
197220
env.ExecuteWorkflow(testWorkflow, req{
198221
ID: id,
199222
ExpectedRequest: notifier.GithubCheckRunRequest{
200-
Title: "atlantis/deploy: root",
201-
Sha: rev,
202-
Repo: github.Repo{Name: "nish"},
203-
State: github.CheckRunQueued,
223+
Title: "atlantis/deploy: root",
224+
Sha: rev,
225+
Repo: github.Repo{Name: "nish"},
226+
State: github.CheckRunQueued,
227+
Summary: "This deploy is queued and will be processed as soon as possible.\nNo other revisions ahead In queue.",
204228
},
205229
ExpectedT: t,
206230
})
@@ -263,10 +287,11 @@ func TestEnqueue_ManualTrigger_QueueAlreadyLocked(t *testing.T) {
263287
Revision: "123334444555",
264288
},
265289
ExpectedRequest: notifier.GithubCheckRunRequest{
266-
Title: "atlantis/deploy: root",
267-
Sha: rev,
268-
Repo: github.Repo{Name: "nish"},
269-
State: github.CheckRunQueued,
290+
Title: "atlantis/deploy: root",
291+
Sha: rev,
292+
Repo: github.Repo{Name: "nish"},
293+
State: github.CheckRunQueued,
294+
Summary: "This deploy is queued and will be processed as soon as possible.\nNo other revisions ahead In queue.",
270295
},
271296
ExpectedT: t,
272297
})
@@ -321,8 +346,22 @@ func TestEnqueue_MergeTrigger_QueueAlreadyLocked(t *testing.T) {
321346

322347
id := uuid.Must(uuid.NewUUID())
323348

349+
deploymentInfo := terraformWorkflow.DeploymentInfo{
350+
Commit: github.Commit{
351+
Revision: "123334444555",
352+
Branch: "locking-branch",
353+
},
354+
CheckRunID: 0,
355+
Root: terraform.Root{Name: "root", TriggerInfo: terraform.TriggerInfo{
356+
Type: terraform.MergeTrigger,
357+
}, Trigger: terraform.MergeTrigger},
358+
ID: id,
359+
Repo: github.Repo{Name: "nish"},
360+
}
361+
324362
env.ExecuteWorkflow(testWorkflow, req{
325-
ID: id,
363+
ID: id,
364+
InitialElements: []terraformWorkflow.DeploymentInfo{deploymentInfo},
326365
Lock: queue.LockState{
327366
// ensure that the lock gets updated
328367
Status: queue.LockedStatus,
@@ -332,7 +371,7 @@ func TestEnqueue_MergeTrigger_QueueAlreadyLocked(t *testing.T) {
332371
Title: "atlantis/deploy: root",
333372
Sha: rev,
334373
Repo: github.Repo{Name: "nish"},
335-
Summary: "This deploy is locked from a manual deployment for revision [123334444555](https://github.com//nish/commit/123334444555). Unlock to proceed.",
374+
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",
336375
Actions: []github.CheckRunAction{github.CreateUnlockAction()},
337376
State: github.CheckRunActionRequired,
338377
},
@@ -346,6 +385,7 @@ func TestEnqueue_MergeTrigger_QueueAlreadyLocked(t *testing.T) {
346385
assert.NoError(t, err)
347386

348387
assert.Equal(t, []terraformWorkflow.DeploymentInfo{
388+
deploymentInfo,
349389
{
350390
Commit: github.Commit{
351391
Revision: rev,

0 commit comments

Comments
 (0)