代码 PushUp 门户网站客户端
有代码PushUp Portal类型定义的API客户端.
设置
npm install @code-pushup/portal-client
使用量
上传报告到门户网站
import { uploadReportToPortal } from '@code-pushup/portal-client';
// ...
const report = await uploadReportToPortal({
server: '<GRAPHQL URL>',
apiKey: process.env.CODE_PUSHUP_API_KEY,
data: {
organization: '<ORGANIZATION SLUG>',
project: '<PROJECT SLUG>',
commit: '<COMMIT SHA>',
plugins: [
// ...
],
categories: [
// ...
],
// ...
},
});
链接到门户比较页面
import { getPortalComparisonLink } from '@code-pushup/portal-client';
// ...
const url = await getPortalComparisonLink({
server: '<GRAPHQL URL>',
apiKey: process.env.CODE_PUSHUP_API_KEY,
parameters: {
organization: '<ORGANIZATION SLUG>',
project: '<PROJECT SLUG>',
before: '<COMMIT SHA_1>',
after: '<COMMIT SHA_2>',
},
});
从门户网站下载报告
import { downloadReportFromPortal } from '@code-pushup/portal-client';
// ...
const report = await downloadReportFromPortal({
server: '<GRAPHQL URL>',
apiKey: process.env.CODE_PUSHUP_API_KEY,
parameters: {
organization: '<ORGANIZATION SLUG>',
project: '<PROJECT SLUG>',
/* OPTIONAL: if commit not provided, finds latest report in default branch */
// commit: '<COMMIT SHA>',
/* OPTIONAL: opt in to including audit details (issues, trees, etc.), omitted by default to minimize payload */
// withAuditDetails: true,
/* OPTIONAL: maximum number of recent commits to search for latest report (ignored if commit set) */
// maxCommits: 30,
},
});
从 Portal 下载工程
import { downloadProjectsFromPortal } from '@code-pushup/portal-client';
// ...
const report = await downloadProjectsFromPortal({
server: '<GRAPHQL URL>',
apiKey: process.env.CODE_PUSHUP_API_KEY,
parameters: {
/* OPTIONAL: filter projects by organization */
// organization: '<ORGANIZATION SLUG>',
/* OPTIONAL: opt in to including each project's latest report */
// withLatestReport: true,
/* OPTIONAL: opt in to including audit details (ignored unless withLatestReport enabled) */
// withAuditDetails: true,
/* OPTIONAL: maximum number of recent commits to search for latest report (ignored unless withLatestReport enabled) */
// maxCommits: 30,
},
});