-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathupload.ts
More file actions
43 lines (39 loc) · 1.33 KB
/
Copy pathupload.ts
File metadata and controls
43 lines (39 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { SaveReportMutationVariables } from '@code-pushup/portal-client';
import type { PersistConfig, Report, UploadConfig } from '@code-pushup/models';
import { loadReport } from '@code-pushup/utils';
import { reportToGQL } from './implementation/report-to-gql.js';
import { loadPortalClient } from './load-portal-client.js';
import type { GlobalOptions } from './types.js';
export type UploadOptions = { upload?: UploadConfig } & {
persist: Required<PersistConfig>;
} & Partial<GlobalOptions>;
/**
* Uploads collected audits to the portal
* @param options
* @param uploadFn
*/
export async function upload(options: UploadOptions) {
if (options.upload == null) {
throw new Error('Upload configuration is not set.');
}
const portalClient = await loadPortalClient();
if (!portalClient) {
return;
}
const { uploadReportToPortal } = portalClient;
const { apiKey, server, organization, project, timeout } = options.upload;
const report: Report = await loadReport({
...options.persist,
format: 'json',
});
if (!report.commit) {
throw new Error('Commit must be linked in order to upload report');
}
const data: SaveReportMutationVariables = {
organization,
project,
commit: report.commit.hash,
...reportToGQL(report),
};
return uploadReportToPortal({ apiKey, server, data, timeout });
}