Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 41 additions & 26 deletions src/lib/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,51 +375,66 @@ export default class httpClient {
}, ctx.log)
}

processSnapshotCaps(ctx: Context, snapshot: ProcessedSnapshot, snapshotUuid: string, capsBuildId: string, capsProjectToken: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false) {
processSnapshotCaps(ctx: Context, snapshot: ProcessedSnapshot, snapshotUuid: string, capsBuildId: string, capsProjectToken: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false, approvalThreshold: number| undefined, rejectionThreshold: number| undefined) {
const requestData: any = {
name: snapshot.name,
url: snapshot.url,
snapshotUuid: snapshotUuid,
variantCount: variantCount,
test: {
type: ctx.testType,
source: 'cli'
},
doRemoteDiscovery: snapshot.options.doRemoteDiscovery,
discoveryErrors: discoveryErrors,
sync: sync
}
if (approvalThreshold !== undefined) {
requestData.approvalThreshold = approvalThreshold;
}
if (rejectionThreshold !== undefined) {
requestData.rejectionThreshold = rejectionThreshold;
}
return this.request({
url: `/build/${capsBuildId}/snapshot`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
projectToken: capsProjectToken !== '' ? capsProjectToken : this.projectToken
},
data: {
name: snapshot.name,
url: snapshot.url,
snapshotUuid: snapshotUuid,
variantCount: variantCount,
test: {
type: ctx.testType,
source: 'cli'
},
doRemoteDiscovery: snapshot.options.doRemoteDiscovery,
discoveryErrors: discoveryErrors,
sync: sync
}
data: requestData
}, ctx.log)
}

uploadSnapshotForCaps(ctx: Context, snapshot: ProcessedSnapshot, capsBuildId: string, capsProjectToken: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false) {
uploadSnapshotForCaps(ctx: Context, snapshot: ProcessedSnapshot, capsBuildId: string, capsProjectToken: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false, approvalThreshold: number| undefined, rejectionThreshold: number| undefined) {
// Use capsBuildId if provided, otherwise fallback to ctx.build.id
const buildId = capsBuildId !== '' ? capsBuildId : ctx.build.id;


const requestData: any = {
snapshot,
test: {
type: ctx.testType,
source: 'cli'
},
discoveryErrors: discoveryErrors,
variantCount: variantCount,
sync: sync
}
if (approvalThreshold !== undefined) {
requestData.approvalThreshold = approvalThreshold;
}
if (rejectionThreshold !== undefined) {
requestData.rejectionThreshold = rejectionThreshold;
}

return this.request({
url: `/builds/${buildId}/snapshot`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
projectToken: capsProjectToken !== '' ? capsProjectToken : this.projectToken // Use capsProjectToken dynamically
},
data: {
snapshot,
test: {
type: ctx.testType,
source: 'cli'
},
discoveryErrors: discoveryErrors,
variantCount: variantCount,
sync: sync
}
data: requestData
}, ctx.log);
}

Expand Down
7 changes: 4 additions & 3 deletions src/lib/snapshotQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,10 @@ export default class Queue {
}



if (useCapsBuildId) {
this.ctx.log.info(`Using cached buildId: ${capsBuildId}`);
let approvalThreshold = snapshot?.options?.approvalThreshold || this.ctx.config.approvalThreshold;
let rejectionThreshold = snapshot?.options?.rejectionThreshold || this.ctx.config.rejectionThreshold;
if (useKafkaFlowCaps) {
let snapshotUuid = uuidv4();
if (snapshot?.options?.contextId && this.ctx.contextToSnapshotMap?.has(snapshot.options.contextId)) {
Expand All @@ -378,9 +379,9 @@ export default class Queue {
this.ctx.log.debug(`Uploading dom to S3 for snapshot using LSRS`);
await this.ctx.client.sendDomToLSRSForCaps(this.ctx, processedSnapshot, snapshotUuid, capsBuildId, capsProjectToken);
}
await this.ctx.client.processSnapshotCaps(this.ctx, processedSnapshot, snapshotUuid, capsBuildId, capsProjectToken, discoveryErrors, calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config), snapshot?.options?.sync);
await this.ctx.client.processSnapshotCaps(this.ctx, processedSnapshot, snapshotUuid, capsBuildId, capsProjectToken, discoveryErrors, calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config), snapshot?.options?.sync, approvalThreshold, rejectionThreshold);
} else {
await this.ctx.client.uploadSnapshotForCaps(this.ctx, processedSnapshot, capsBuildId, capsProjectToken, discoveryErrors, calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config), snapshot?.options?.sync);
await this.ctx.client.uploadSnapshotForCaps(this.ctx, processedSnapshot, capsBuildId, capsProjectToken, discoveryErrors, calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config), snapshot?.options?.sync, approvalThreshold, rejectionThreshold);
}

// Increment snapshot count for the specific buildId
Expand Down