Skip to content

Commit 9360f58

Browse files
committed
Add totalSnapshots in param in build finalize
1 parent 5982008 commit 9360f58

File tree

7 files changed

+16
-12
lines changed

7 files changed

+16
-12
lines changed

src/commander/capture.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ command
2424
getGitInfo(ctx),
2525
createBuild(ctx),
2626
captureScreenshots(ctx),
27-
finalizeBuild(ctx, 0)
27+
finalizeBuild(ctx)
2828
],
2929
{
3030
rendererOptions: {

src/commander/exec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ command
2424
return
2525
}
2626
ctx.args.execCommand = execCommand
27+
ctx.totalSnapshots = 0
2728

2829
let tasks = new Listr<Context>(
2930
[
@@ -32,7 +33,7 @@ command
3233
getGitInfo(ctx),
3334
createBuild(ctx),
3435
exec(ctx),
35-
finalizeBuild(ctx, 30000)
36+
finalizeBuild(ctx)
3637
],
3738
{
3839
rendererOptions: {

src/lib/ctx.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default (options: Record<string, string>): Context => {
4747
projectId: '',
4848
},
4949
args: {},
50-
cliVersion: version
50+
cliVersion: version,
51+
totalSnapshots: -1
5152
}
5253
}

src/lib/httpClient.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ export default class httpClient {
6565
}, log)
6666
}
6767

68-
finalizeBuild(buildId: string, log: Logger) {
68+
finalizeBuild(buildId: string, totalSnapshots: number, log: Logger) {
69+
let params: Record<string, string | number> = {buildId};
70+
if (totalSnapshots > -1) params.totalSnapshots = totalSnapshots;
71+
6972
return this.request({
7073
url: '/build',
7174
method: 'DELETE',
72-
params: {
73-
buildId: buildId
74-
}
75+
params: params
7576
}, log)
7677
}
7778

src/lib/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export default async (ctx: Context): Promise<FastifyInstance<Server, IncomingMes
2929
} catch (error: any) {
3030
reply.code(500).send({ error: { message: error.message}})
3131
}
32+
33+
ctx.totalSnapshots++
3234
reply.code(200).send({data: { message: "success" }});
3335
});
3436

src/tasks/finalizeBuild.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ import { ListrTask, ListrRendererFactory } from 'listr2';
22
import { Context } from '../types.js'
33
import chalk from 'chalk';
44

5-
export default (ctx: Context, waitTime: number): ListrTask<Context, ListrRendererFactory, ListrRendererFactory> => {
5+
export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRendererFactory> => {
66
return {
77
title: `Finalizing build`,
88
task: async (ctx, task): Promise<void> => {
99
try {
10-
if (waitTime > 0) {
11-
await new Promise(resolve => (setTimeout(resolve, waitTime)));
12-
await ctx.client.finalizeBuild(ctx.build.id, ctx.log);
13-
}
10+
await new Promise(resolve => (setTimeout(resolve, 2000)));
11+
await ctx.client.finalizeBuild(ctx.build.id, ctx.totalSnapshots, ctx.log);
1412
task.output = chalk.gray(`build url: ${ctx.build.url}`);
1513
task.title = 'Finalized build'
1614
} catch (error) {

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface Context {
2020
execCommand?: Array<string>
2121
}
2222
cliVersion: string;
23+
totalSnapshots: number;
2324

2425
}
2526

0 commit comments

Comments
 (0)