Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/commander/uploadPdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ command
.option('--buildName <string>', 'Specify the build name')
.option('--markBaseline', 'Mark this build baseline')
.option('--pdfNames <string>', 'Specify PDF names for the upload')
.option('--approvalThreshold <number>', 'Mismatch % at or below which every PDF in this upload is auto-approved (0-100)')
.option('--rejectionThreshold <number>', 'Mismatch % at or above which every PDF in this upload is auto-rejected (0-100)')
.option('--thresholds <json|file>', 'Per-PDF overrides keyed by name, inline JSON or a path to a JSON file, e.g. {"invoice.pdf":{"approval":2,"rejection":5}}')
.option('--sync', 'Wait for the uploaded PDFs to be compared and return the results')
.action(async function(directory, _, command) {
const options = command.optsWithGlobals();
Expand Down
4 changes: 4 additions & 0 deletions src/lib/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ export default (options: Record<string, string>): Context => {
userName: options.userName || '',
accessKey: options.accessKey || '',
pdfNames: options.pdfNames || '',
// kept as strings so the backend does the range/band validation and "0" survives
approvalThreshold: options.approvalThreshold || '',
rejectionThreshold: options.rejectionThreshold || '',
thresholds: options.thresholds || '',
sync: options.sync ? true : false
},
cliVersion: version,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,10 @@ export default class httpClient {
if (snapshotUuids && snapshotUuids !== '') {
form.append('snapshotUuids', snapshotUuids);
}
// call-level thresholds apply to every pdf; the per-pdf map wins where it names a file
if (ctx.options.approvalThreshold) form.append('approvalThreshold', ctx.options.approvalThreshold);
if (ctx.options.rejectionThreshold) form.append('rejectionThreshold', ctx.options.rejectionThreshold);
if (ctx.options.thresholds) form.append('thresholds', ctx.options.thresholds);

if (ctx.git?.branch) form.append('branch', ctx.git.branch);
if (ctx.git?.commitId) form.append('commitId', ctx.git.commitId);
Expand Down
5 changes: 5 additions & 0 deletions src/tasks/uploadPdfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ async function uploadPdfs(ctx: Context, pdfPath: string): Promise<void> {
const buildName = ctx.options.buildName;
const pdfNames = ctx.options.pdfNames;

// --thresholds takes inline JSON or a path; either way the backend validates it against the names
if (ctx.options.thresholds && fs.existsSync(ctx.options.thresholds)) {
ctx.options.thresholds = fs.readFileSync(ctx.options.thresholds, 'utf8');
}

// The backend names each document from pdfNames when given, else the uploaded file name.
// Sync polling asks by that same name, so resolve it here rather than guessing later.
const providedNames = pdfNames ? pdfNames.split(',').map(name => name.trim()) : [];
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export interface Context {
gitURL?: string,
showRenderErrors?: boolean,
pdfNames?: string,
approvalThreshold?: string,
rejectionThreshold?: string,
thresholds?: string,
sync?: boolean,
userName?: string,
accessKey?: string
Expand Down