Skip to content

Commit 8723f53

Browse files
authored
feat(stage): display staged package status (#9898)
1 parent dc43591 commit 8723f53

4 files changed

Lines changed: 57 additions & 1 deletion

File tree

‎lib/utils/key-values.js‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,23 @@ function logObject (values, { chalk, json, predicate = defaultPredicate }) {
2626
}
2727

2828
function logStageItem (item, { chalk }) {
29-
const { id, packageName, version, tag, createdAt, actor, actorType, shasum, ...rest } = item
29+
const {
30+
id,
31+
packageName,
32+
version,
33+
tag,
34+
createdAt,
35+
actor,
36+
actorType,
37+
shasum,
38+
status,
39+
...rest
40+
} = item
3041
logObject({
3142
id,
3243
'package name': packageName,
3344
version,
45+
status,
3446
tag,
3547
'date staged': createdAt,
3648
'staged by': actorType ? `${actor} (${actorType})` : actor,

‎test/lib/commands/stage/list.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const stageItems = [
1515
actor: 'octocat',
1616
actorType: 'user',
1717
shasum: '4f7f5f1d5bcf2f72f6e4d6c4f3b2812d8a2f6c19',
18+
status: 'validating',
1819
},
1920
{
2021
id: 'f8e7a45b-7a5f-4f31-8e6d-9dd1c6ef38c0',
@@ -25,6 +26,7 @@ const stageItems = [
2526
actor: 'npm-bot',
2627
actorType: 'trusted automation',
2728
shasum: '8eb3b4e9b6e3d0d2c86be1e6d4f43f4be62e80ad',
29+
status: 'staged',
2830
},
2931
]
3032

@@ -45,6 +47,9 @@ t.test('lists all staged packages', async t => {
4547
t.match(out, 'package name: example-lib')
4648
t.match(out, 'version: 1.2.3')
4749
t.match(out, 'version: 0.4.0')
50+
t.match(out, 'status: validating')
51+
t.match(out, 'status: staged')
52+
t.equal(out.match(/status:/g)?.length, 2, 'all server-provided statuses are shown')
4853
})
4954

5055
t.test('lists with package filter', async t => {
@@ -80,6 +85,8 @@ t.test('lists with --json', async t => {
8085
t.equal(out.length, 2)
8186
t.equal(out[0].packageName, '@npmcli/example-package')
8287
t.equal(out[0].id, '1de6f3db-2ed9-4d72-b3dd-8f0e2b474a2f', 'uuid id is not redacted')
88+
t.equal(out[0].status, 'validating')
89+
t.equal(out[1].status, 'staged')
8390
})
8491

8592
t.test('shows message when no packages', async t => {

‎test/lib/commands/stage/view.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const stageItem = {
1414
actor: 'octocat',
1515
actorType: 'user',
1616
shasum: '4f7f5f1d5bcf2f72f6e4d6c4f3b2812d8a2f6c19',
17+
status: 'awaiting_approval',
1718
}
1819

1920
t.test('views a staged package', async t => {
@@ -31,6 +32,7 @@ t.test('views a staged package', async t => {
3132
t.match(out, /id:/)
3233
t.match(out, 'package name: @npmcli/example-package')
3334
t.match(out, 'version: 1.2.3')
35+
t.match(out, 'status: awaiting_approval')
3436
})
3537

3638
t.test('views with --json', async t => {
@@ -47,6 +49,7 @@ t.test('views with --json', async t => {
4749
const out = JSON.parse(joinedOutput())
4850
t.ok(out.id)
4951
t.equal(out.packageName, '@npmcli/example-package')
52+
t.equal(out.status, 'awaiting_approval')
5053
})
5154

5255
t.test('throws usageError without stage-id', async t => {

‎test/lib/utils/key-values.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,40 @@ t.test('logStageItem without actorType shows actor alone', async t => {
7676
t.notMatch(out, /\(/)
7777
})
7878

79+
t.test('logStageItem shows status returned by the server', async t => {
80+
const { joinedOutput } = await loadMockNpm(t)
81+
const chalk = { cyan: v => v, green: v => v }
82+
const item = {
83+
id: 'abc',
84+
packageName: 'pkg',
85+
version: '1.0.0',
86+
tag: 'latest',
87+
createdAt: '2026-01-01',
88+
actor: 'user',
89+
shasum: 'sha1',
90+
}
91+
92+
logStageItem({ ...item, status: 'awaiting_approval' }, { chalk })
93+
t.match(joinedOutput(), /status: awaiting_approval/)
94+
})
95+
96+
t.test('logStageItem omits missing status', async t => {
97+
const { joinedOutput } = await loadMockNpm(t)
98+
const chalk = { cyan: v => v, green: v => v }
99+
const item = {
100+
id: 'abc',
101+
packageName: 'pkg',
102+
version: '1.0.0',
103+
tag: 'latest',
104+
createdAt: '2026-01-01',
105+
actor: 'user',
106+
shasum: 'sha1',
107+
}
108+
109+
logStageItem(item, { chalk })
110+
t.notMatch(joinedOutput(), /status:/)
111+
})
112+
79113
t.test('logObject with all values skipped produces no output', async t => {
80114
const { joinedOutput } = await loadMockNpm(t)
81115
const chalk = { cyan: v => v, green: v => v }

0 commit comments

Comments
 (0)