@code-pushup/ci 0.56.0 → 0.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -8
- package/package.json +10 -8
- package/src/index.d.ts +4 -4
- package/src/index.js +3 -0
- package/src/index.js.map +1 -0
- package/src/lib/cli/commands/collect.d.ts +2 -3
- package/src/lib/cli/commands/collect.js +16 -0
- package/src/lib/cli/commands/collect.js.map +1 -0
- package/src/lib/cli/commands/compare.d.ts +2 -3
- package/src/lib/cli/commands/compare.js +20 -0
- package/src/lib/cli/commands/compare.js.map +1 -0
- package/src/lib/cli/commands/merge-diffs.d.ts +2 -3
- package/src/lib/cli/commands/merge-diffs.js +23 -0
- package/src/lib/cli/commands/merge-diffs.js.map +1 -0
- package/src/lib/cli/commands/print-config.d.ts +2 -2
- package/src/lib/cli/commands/print-config.js +26 -0
- package/src/lib/cli/commands/print-config.js.map +1 -0
- package/src/lib/cli/context.d.ts +3 -5
- package/src/lib/cli/context.js +9 -0
- package/src/lib/cli/context.js.map +1 -0
- package/src/lib/cli/index.d.ts +6 -6
- package/src/lib/cli/index.js +7 -0
- package/src/lib/cli/index.js.map +1 -0
- package/src/lib/cli/persist.d.ts +5 -26
- package/src/lib/cli/persist.js +24 -0
- package/src/lib/cli/persist.js.map +1 -0
- package/src/lib/comment.d.ts +1 -1
- package/src/lib/comment.js +29 -0
- package/src/lib/comment.js.map +1 -0
- package/src/lib/constants.d.ts +1 -1
- package/src/lib/constants.js +15 -0
- package/src/lib/constants.js.map +1 -0
- package/src/lib/git.js +99 -0
- package/src/lib/git.js.map +1 -0
- package/src/lib/issues.d.ts +1 -1
- package/src/lib/issues.js +96 -0
- package/src/lib/issues.js.map +1 -0
- package/src/lib/models.d.ts +9 -11
- package/src/lib/models.js +2 -0
- package/src/lib/models.js.map +1 -0
- package/src/lib/monorepo/detect-tool.d.ts +1 -1
- package/src/lib/monorepo/detect-tool.js +11 -0
- package/src/lib/monorepo/detect-tool.js.map +1 -0
- package/src/lib/monorepo/handlers/index.d.ts +1 -1
- package/src/lib/monorepo/handlers/index.js +20 -0
- package/src/lib/monorepo/handlers/index.js.map +1 -0
- package/src/lib/monorepo/handlers/npm.d.ts +1 -1
- package/src/lib/monorepo/handlers/npm.js +29 -0
- package/src/lib/monorepo/handlers/npm.js.map +1 -0
- package/src/lib/monorepo/handlers/nx.d.ts +1 -1
- package/src/lib/monorepo/handlers/nx.js +62 -0
- package/src/lib/monorepo/handlers/nx.js.map +1 -0
- package/src/lib/monorepo/handlers/pnpm.d.ts +1 -1
- package/src/lib/monorepo/handlers/pnpm.js +47 -0
- package/src/lib/monorepo/handlers/pnpm.js.map +1 -0
- package/src/lib/monorepo/handlers/turbo.d.ts +1 -1
- package/src/lib/monorepo/handlers/turbo.js +48 -0
- package/src/lib/monorepo/handlers/turbo.js.map +1 -0
- package/src/lib/monorepo/handlers/yarn.d.ts +1 -1
- package/src/lib/monorepo/handlers/yarn.js +44 -0
- package/src/lib/monorepo/handlers/yarn.js.map +1 -0
- package/src/lib/monorepo/index.d.ts +2 -2
- package/src/lib/monorepo/index.js +3 -0
- package/src/lib/monorepo/index.js.map +1 -0
- package/src/lib/monorepo/list-projects.d.ts +9 -3
- package/src/lib/monorepo/list-projects.js +99 -0
- package/src/lib/monorepo/list-projects.js.map +1 -0
- package/src/lib/monorepo/packages.js +50 -0
- package/src/lib/monorepo/packages.js.map +1 -0
- package/src/lib/monorepo/tools.d.ts +6 -0
- package/src/lib/monorepo/tools.js +5 -0
- package/src/lib/monorepo/tools.js.map +1 -0
- package/src/lib/run-monorepo.d.ts +3 -0
- package/src/lib/run-monorepo.js +141 -0
- package/src/lib/run-monorepo.js.map +1 -0
- package/src/lib/run-standalone.d.ts +3 -0
- package/src/lib/run-standalone.js +19 -0
- package/src/lib/run-standalone.js.map +1 -0
- package/src/lib/run-utils.d.ts +45 -0
- package/src/lib/run-utils.js +158 -0
- package/src/lib/run-utils.js.map +1 -0
- package/src/lib/run.d.ts +1 -1
- package/src/lib/run.js +24 -0
- package/src/lib/run.js.map +1 -0
- package/index.js +0 -1742
package/README.md
CHANGED
|
@@ -97,22 +97,20 @@ Optionally, you can override default options for further customization:
|
|
|
97
97
|
| Property | Type | Default | Description |
|
|
98
98
|
| :----------------- | :------------------------ | :------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
99
99
|
| `monorepo` | `boolean \| MonorepoTool` | `false` | Enables [monorepo mode](#monorepo-mode) |
|
|
100
|
+
| `parallel` | `boolean \| number` | `false` | Enables parallel execution in [monorepo mode](#monorepo-mode) |
|
|
100
101
|
| `projects` | `string[] \| null` | `null` | Custom projects configuration for [monorepo mode](#monorepo-mode) |
|
|
101
102
|
| `task` | `string` | `'code-pushup'` | Name of command to run Code PushUp per project in [monorepo mode](#monorepo-mode) |
|
|
102
|
-
| `nxProjectsFilter` | `string \| string[]` | `'--with-target={task}'` | Arguments passed to [`nx show projects`](https://nx.dev/nx-api/nx/documents/show#projects), only relevant for Nx in [monorepo mode](#monorepo-mode) [^
|
|
103
|
+
| `nxProjectsFilter` | `string \| string[]` | `'--with-target={task}'` | Arguments passed to [`nx show projects`](https://nx.dev/nx-api/nx/documents/show#projects), only relevant for Nx in [monorepo mode](#monorepo-mode) [^2] |
|
|
103
104
|
| `directory` | `string` | `process.cwd()` | Directory in which Code PushUp CLI should run |
|
|
104
105
|
| `config` | `string \| null` | `null` [^1] | Path to config file (`--config` option) |
|
|
105
106
|
| `silent` | `boolean` | `false` | Toggles if logs from CLI commands are printed |
|
|
106
107
|
| `bin` | `string` | `'npx --no-install code-pushup'` | Command for executing Code PushUp CLI |
|
|
107
108
|
| `detectNewIssues` | `boolean` | `true` | Toggles if new issues should be detected and returned in `newIssues` property |
|
|
108
109
|
| `logger` | `Logger` | `console` | Logger for reporting progress and encountered problems |
|
|
109
|
-
| `output` | `string` | `'.code-pushup'` | Directory where Code PushUp reports will be created (interpolates project name [^2]) |
|
|
110
110
|
|
|
111
111
|
[^1]: By default, the `code-pushup.config` file is autodetected as described in [`@code-pushup/cli` docs](../cli/README.md#configuration).
|
|
112
112
|
|
|
113
|
-
[^2]:
|
|
114
|
-
|
|
115
|
-
[^3]: The `{task}` pattern is replaced with the `task` value, so the default behaviour is to list projects using `npx nx show projects --with-target=code-pushup --json`. The `nxProjectsFilter` options gives Nx users the flexibility to filter projects in alternative ways supported by the Nx CLI (e.g. `--affected`, `--projects`, `--exclude`, `--type`) - refer to [options in Nx docs](https://nx.dev/nx-api/nx/documents/show#options) for details.
|
|
113
|
+
[^2]: The `{task}` pattern is replaced with the `task` value, so the default behaviour is to list projects using `npx nx show projects --with-target=code-pushup --json`. The `nxProjectsFilter` options gives Nx users the flexibility to filter projects in alternative ways supported by the Nx CLI (e.g. `--affected`, `--projects`, `--exclude`, `--type`) - refer to [options in Nx docs](https://nx.dev/nx-api/nx/documents/show#options) for details.
|
|
116
114
|
|
|
117
115
|
The `Logger` object has the following required properties:
|
|
118
116
|
|
|
@@ -138,7 +136,7 @@ const result = await runInCI(refs, api);
|
|
|
138
136
|
if (result.mode === 'standalone') {
|
|
139
137
|
const {
|
|
140
138
|
// output files, can be uploaded as job artifact
|
|
141
|
-
|
|
139
|
+
files: { report, diff },
|
|
142
140
|
// ID of created/updated PR comment
|
|
143
141
|
commentId,
|
|
144
142
|
// array of source code issues, can be used to annotate changed files in PR
|
|
@@ -196,6 +194,27 @@ await runInCI(refs, api, {
|
|
|
196
194
|
});
|
|
197
195
|
```
|
|
198
196
|
|
|
197
|
+
### Parallel tasks
|
|
198
|
+
|
|
199
|
+
By default, tasks are run sequentially for each project in the monorepo.
|
|
200
|
+
The `parallel` option enables parallel execution for tools which support it (Nx, Turborepo, PNPM, Yarn 2+).
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
await runInCI(refs, api, {
|
|
204
|
+
monorepo: true,
|
|
205
|
+
parallel: true,
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The maximum number of concurrent tasks can be set by passing in a number instead of a boolean:
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
await runInCI(refs, api, {
|
|
213
|
+
monorepo: true,
|
|
214
|
+
parallel: 3,
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
199
218
|
### Monorepo result
|
|
200
219
|
|
|
201
220
|
In monorepo mode, the resolved object includes the merged diff at the top-level, as well as a list of projects.
|
|
@@ -211,7 +230,7 @@ if (result.mode === 'monorepo') {
|
|
|
211
230
|
// ID of created/updated PR comment
|
|
212
231
|
commentId,
|
|
213
232
|
// merged report-diff.md used in PR comment, can also be uploaded as job artifact
|
|
214
|
-
|
|
233
|
+
diffPath,
|
|
215
234
|
} = result;
|
|
216
235
|
|
|
217
236
|
for (const project of projects) {
|
|
@@ -219,7 +238,7 @@ if (result.mode === 'monorepo') {
|
|
|
219
238
|
// detected project name (from package.json, project.json or folder name)
|
|
220
239
|
name,
|
|
221
240
|
// output files, can be uploaded as job artifacts
|
|
222
|
-
|
|
241
|
+
files: { report, diff },
|
|
223
242
|
// array of source code issues, can be used to annotate changed files in PR
|
|
224
243
|
newIssues,
|
|
225
244
|
} = project;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-pushup/ci",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0",
|
|
4
4
|
"description": "CI automation logic for Code PushUp (provider-agnostic)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/code-pushup/cli/tree/main/packages/ci#readme",
|
|
@@ -25,13 +25,15 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"type": "module",
|
|
28
|
-
"main": "./index.js",
|
|
29
|
-
"types": "./src/index.d.ts",
|
|
30
28
|
"dependencies": {
|
|
31
|
-
"@code-pushup/models": "0.
|
|
32
|
-
"@code-pushup/utils": "0.
|
|
29
|
+
"@code-pushup/models": "0.58.0",
|
|
30
|
+
"@code-pushup/utils": "0.58.0",
|
|
33
31
|
"glob": "^10.4.5",
|
|
34
32
|
"simple-git": "^3.20.0",
|
|
35
|
-
"yaml": "^2.5.1"
|
|
36
|
-
|
|
37
|
-
}
|
|
33
|
+
"yaml": "^2.5.1",
|
|
34
|
+
"zod": "^3.22.1"
|
|
35
|
+
},
|
|
36
|
+
"module": "./src/index.js",
|
|
37
|
+
"main": "./src/index.js",
|
|
38
|
+
"types": "./src/index.d.ts"
|
|
39
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { SourceFileIssue } from './lib/issues';
|
|
2
|
-
export type * from './lib/models';
|
|
3
|
-
export { MONOREPO_TOOLS, isMonorepoTool, type MonorepoTool, } from './lib/monorepo';
|
|
4
|
-
export { runInCI } from './lib/run';
|
|
1
|
+
export type { SourceFileIssue } from './lib/issues.js';
|
|
2
|
+
export type * from './lib/models.js';
|
|
3
|
+
export { MONOREPO_TOOLS, isMonorepoTool, type MonorepoTool, } from './lib/monorepo/index.js';
|
|
4
|
+
export { runInCI } from './lib/run.js';
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/ci/src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,cAAc,EACd,cAAc,GAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { CommandContext } from '../context';
|
|
2
|
-
|
|
3
|
-
export declare function runCollect({ bin, config, directory, silent, project, output, }: CommandContext): Promise<PersistedCliFiles>;
|
|
1
|
+
import type { CommandContext } from '../context.js';
|
|
2
|
+
export declare function runCollect({ bin, config, directory, silent, }: CommandContext): Promise<void>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DEFAULT_PERSIST_FORMAT } from '@code-pushup/models';
|
|
2
|
+
import { executeProcess } from '@code-pushup/utils';
|
|
3
|
+
export async function runCollect({ bin, config, directory, silent, }) {
|
|
4
|
+
const { stdout } = await executeProcess({
|
|
5
|
+
command: bin,
|
|
6
|
+
args: [
|
|
7
|
+
...(config ? [`--config=${config}`] : []),
|
|
8
|
+
...DEFAULT_PERSIST_FORMAT.map(format => `--persist.format=${format}`),
|
|
9
|
+
],
|
|
10
|
+
cwd: directory,
|
|
11
|
+
});
|
|
12
|
+
if (!silent) {
|
|
13
|
+
console.info(stdout);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=collect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collect.js","sourceRoot":"","sources":["../../../../../../../packages/ci/src/lib/cli/commands/collect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,EAC/B,GAAG,EACH,MAAM,EACN,SAAS,EACT,MAAM,GACS;IACf,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,cAAc,CAAC;QACtC,OAAO,EAAE,GAAG;QACZ,IAAI,EAAE;YACJ,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACzC,GAAG,sBAAsB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,oBAAoB,MAAM,EAAE,CAAC;SACtE;QACD,GAAG,EAAE,SAAS;KACf,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { CommandContext } from '../context';
|
|
2
|
-
import { type PersistedCliFiles } from '../persist';
|
|
1
|
+
import type { CommandContext } from '../context.js';
|
|
3
2
|
type CompareOptions = {
|
|
4
3
|
before: string;
|
|
5
4
|
after: string;
|
|
6
5
|
label?: string;
|
|
7
6
|
};
|
|
8
|
-
export declare function runCompare({ before, after, label }: CompareOptions, { bin, config, directory, silent
|
|
7
|
+
export declare function runCompare({ before, after, label }: CompareOptions, { bin, config, directory, silent }: CommandContext): Promise<void>;
|
|
9
8
|
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DEFAULT_PERSIST_FORMAT } from '@code-pushup/models';
|
|
2
|
+
import { executeProcess } from '@code-pushup/utils';
|
|
3
|
+
export async function runCompare({ before, after, label }, { bin, config, directory, silent }) {
|
|
4
|
+
const { stdout } = await executeProcess({
|
|
5
|
+
command: bin,
|
|
6
|
+
args: [
|
|
7
|
+
'compare',
|
|
8
|
+
`--before=${before}`,
|
|
9
|
+
`--after=${after}`,
|
|
10
|
+
...(label ? [`--label=${label}`] : []),
|
|
11
|
+
...(config ? [`--config=${config}`] : []),
|
|
12
|
+
...DEFAULT_PERSIST_FORMAT.map(format => `--persist.format=${format}`),
|
|
13
|
+
],
|
|
14
|
+
cwd: directory,
|
|
15
|
+
});
|
|
16
|
+
if (!silent) {
|
|
17
|
+
console.info(stdout);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../../../../../../../packages/ci/src/lib/cli/commands/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AASpD,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAkB,EACxC,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAkB;IAElD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,cAAc,CAAC;QACtC,OAAO,EAAE,GAAG;QACZ,IAAI,EAAE;YACJ,SAAS;YACT,YAAY,MAAM,EAAE;YACpB,WAAW,KAAK,EAAE;YAClB,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACtC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACzC,GAAG,sBAAsB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,oBAAoB,MAAM,EAAE,CAAC;SACtE;QACD,GAAG,EAAE,SAAS;KACf,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { CommandContext } from '../context';
|
|
2
|
-
|
|
3
|
-
export declare function runMergeDiffs(files: string[], { bin, config, directory, silent, output }: CommandContext): Promise<PersistedCliFiles<'md'>>;
|
|
1
|
+
import type { CommandContext } from '../context.js';
|
|
2
|
+
export declare function runMergeDiffs(files: string[], { bin, config, directory, silent }: CommandContext): Promise<string>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { DEFAULT_PERSIST_FILENAME, DEFAULT_PERSIST_OUTPUT_DIR, } from '@code-pushup/models';
|
|
3
|
+
import { executeProcess } from '@code-pushup/utils';
|
|
4
|
+
export async function runMergeDiffs(files, { bin, config, directory, silent }) {
|
|
5
|
+
const outputDir = path.join(directory, DEFAULT_PERSIST_OUTPUT_DIR);
|
|
6
|
+
const filename = `merged-${DEFAULT_PERSIST_FILENAME}`;
|
|
7
|
+
const { stdout } = await executeProcess({
|
|
8
|
+
command: bin,
|
|
9
|
+
args: [
|
|
10
|
+
'merge-diffs',
|
|
11
|
+
...files.map(file => `--files=${file}`),
|
|
12
|
+
...(config ? [`--config=${config}`] : []),
|
|
13
|
+
`--persist.outputDir=${outputDir}`,
|
|
14
|
+
`--persist.filename=${filename}`,
|
|
15
|
+
],
|
|
16
|
+
cwd: directory,
|
|
17
|
+
});
|
|
18
|
+
if (!silent) {
|
|
19
|
+
console.info(stdout);
|
|
20
|
+
}
|
|
21
|
+
return path.join(outputDir, `${filename}-diff.md`);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=merge-diffs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-diffs.js","sourceRoot":"","sources":["../../../../../../../packages/ci/src/lib/cli/commands/merge-diffs.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,wBAAwB,EACxB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAAe,EACf,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAkB;IAElD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,0BAA0B,CAAC,CAAC;IACnE,MAAM,QAAQ,GAAG,UAAU,wBAAwB,EAAE,CAAC;IAEtD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,cAAc,CAAC;QACtC,OAAO,EAAE,GAAG;QACZ,IAAI,EAAE;YACJ,aAAa;YACb,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,IAAI,EAAE,CAAC;YACvC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACzC,uBAAuB,SAAS,EAAE;YAClC,sBAAsB,QAAQ,EAAE;SACjC;QACD,GAAG,EAAE,SAAS;KACf,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,QAAQ,UAAU,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { CommandContext } from '../context';
|
|
2
|
-
export declare function runPrintConfig({ bin, config, directory, silent, }: CommandContext): Promise<
|
|
1
|
+
import type { CommandContext } from '../context.js';
|
|
2
|
+
export declare function runPrintConfig({ bin, config, directory, silent, }: CommandContext): Promise<unknown>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { executeProcess, stringifyError } from '@code-pushup/utils';
|
|
2
|
+
export async function runPrintConfig({ bin, config, directory, silent, }) {
|
|
3
|
+
const { stdout } = await executeProcess({
|
|
4
|
+
command: bin,
|
|
5
|
+
args: [...(config ? [`--config=${config}`] : []), 'print-config'],
|
|
6
|
+
cwd: directory,
|
|
7
|
+
});
|
|
8
|
+
if (!silent) {
|
|
9
|
+
console.info(stdout);
|
|
10
|
+
}
|
|
11
|
+
// workaround for 1st lines like `> nx run utils:code-pushup -- print-config`
|
|
12
|
+
const lines = stdout.split(/\r?\n/);
|
|
13
|
+
const jsonLines = lines.slice(lines.indexOf('{'), lines.indexOf('}') + 1);
|
|
14
|
+
const stdoutSanitized = jsonLines.join('\n');
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(stdoutSanitized);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (silent) {
|
|
20
|
+
console.info('Invalid output from print-config:');
|
|
21
|
+
console.info(stdout);
|
|
22
|
+
}
|
|
23
|
+
throw new Error(`Error parsing output of print-config command - ${stringifyError(error)}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=print-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print-config.js","sourceRoot":"","sources":["../../../../../../../packages/ci/src/lib/cli/commands/print-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpE,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EACnC,GAAG,EACH,MAAM,EACN,SAAS,EACT,MAAM,GACS;IACf,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,cAAc,CAAC;QACtC,OAAO,EAAE,GAAG;QACZ,IAAI,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC;QACjE,GAAG,EAAE,SAAS;KACf,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAED,6EAA6E;IAC7E,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1E,MAAM,eAAe,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAY,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;YAClD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;QACD,MAAM,IAAI,KAAK,CACb,kDAAkD,cAAc,CAAC,KAAK,CAAC,EAAE,CAC1E,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/src/lib/cli/context.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { Settings } from '../models';
|
|
2
|
-
import type { ProjectConfig } from '../monorepo';
|
|
3
|
-
export type CommandContext = Pick<Settings, 'bin' | 'config' | 'directory' | 'silent'
|
|
4
|
-
project?: string;
|
|
5
|
-
};
|
|
1
|
+
import type { Settings } from '../models.js';
|
|
2
|
+
import type { ProjectConfig } from '../monorepo/index.js';
|
|
3
|
+
export type CommandContext = Pick<Settings, 'bin' | 'config' | 'directory' | 'silent'>;
|
|
6
4
|
export declare function createCommandContext(settings: Settings, project: ProjectConfig | null | undefined): CommandContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../../../packages/ci/src/lib/cli/context.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,oBAAoB,CAClC,QAAkB,EAClB,OAAyC;IAEzC,OAAO;QACL,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,QAAQ,CAAC,GAAG;QACjC,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,QAAQ,CAAC,SAAS;QACnD,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;KACxB,CAAC;AACJ,CAAC"}
|
package/src/lib/cli/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { runCollect } from './commands/collect';
|
|
2
|
-
export { runCompare } from './commands/compare';
|
|
3
|
-
export { runMergeDiffs } from './commands/merge-diffs';
|
|
4
|
-
export { runPrintConfig } from './commands/print-config';
|
|
5
|
-
export { createCommandContext, type CommandContext } from './context';
|
|
6
|
-
export {
|
|
1
|
+
export { runCollect } from './commands/collect.js';
|
|
2
|
+
export { runCompare } from './commands/compare.js';
|
|
3
|
+
export { runMergeDiffs } from './commands/merge-diffs.js';
|
|
4
|
+
export { runPrintConfig } from './commands/print-config.js';
|
|
5
|
+
export { createCommandContext, type CommandContext } from './context.js';
|
|
6
|
+
export { persistedFilesFromConfig } from './persist.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { runCollect } from './commands/collect.js';
|
|
2
|
+
export { runCompare } from './commands/compare.js';
|
|
3
|
+
export { runMergeDiffs } from './commands/merge-diffs.js';
|
|
4
|
+
export { runPrintConfig } from './commands/print-config.js';
|
|
5
|
+
export { createCommandContext } from './context.js';
|
|
6
|
+
export { persistedFilesFromConfig } from './persist.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/ci/src/lib/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAuB,MAAM,cAAc,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC"}
|
package/src/lib/cli/persist.d.ts
CHANGED
|
@@ -1,27 +1,6 @@
|
|
|
1
|
-
import { type Format } from '@code-pushup/models';
|
|
2
|
-
export
|
|
3
|
-
artifactData: {
|
|
4
|
-
rootDir: string;
|
|
5
|
-
files: string[];
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
export type PersistedCliFilesFormats<T extends Format = Format> = {
|
|
9
|
-
[F in T as `${F}FilePath`]: string;
|
|
10
|
-
};
|
|
11
|
-
export declare function persistCliOptions({ directory, project, output, }: {
|
|
12
|
-
directory: string;
|
|
13
|
-
project?: string;
|
|
14
|
-
output: string;
|
|
15
|
-
}): string[];
|
|
16
|
-
export declare function persistedCliFiles<TFormat extends Format = Format>({ directory, isDiff, project, formats, output, }: {
|
|
17
|
-
directory: string;
|
|
1
|
+
import { type CoreConfig, type Format } from '@code-pushup/models';
|
|
2
|
+
export declare function persistedFilesFromConfig(config: Pick<CoreConfig, 'persist'>, { isDiff, directory }: {
|
|
18
3
|
isDiff?: boolean;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}): PersistedCliFiles<TFormat>;
|
|
23
|
-
export declare function findPersistedFiles({ rootDir, files, project, }: {
|
|
24
|
-
rootDir: string;
|
|
25
|
-
files: string[];
|
|
26
|
-
project?: string;
|
|
27
|
-
}): PersistedCliFiles;
|
|
4
|
+
directory: string;
|
|
5
|
+
}): Record<Format, string>;
|
|
6
|
+
export declare function parsePersistConfig(json: unknown): Promise<Pick<CoreConfig, 'persist'>>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { DEFAULT_PERSIST_FILENAME, DEFAULT_PERSIST_FORMAT, DEFAULT_PERSIST_OUTPUT_DIR, persistConfigSchema, } from '@code-pushup/models';
|
|
4
|
+
import { objectFromEntries, stringifyError } from '@code-pushup/utils';
|
|
5
|
+
export function persistedFilesFromConfig(config, { isDiff, directory }) {
|
|
6
|
+
const { persist: { outputDir = DEFAULT_PERSIST_OUTPUT_DIR, filename = DEFAULT_PERSIST_FILENAME, } = {}, } = config;
|
|
7
|
+
const dir = path.isAbsolute(outputDir)
|
|
8
|
+
? outputDir
|
|
9
|
+
: path.join(directory, outputDir);
|
|
10
|
+
const name = isDiff ? `${filename}-diff` : filename;
|
|
11
|
+
return objectFromEntries(DEFAULT_PERSIST_FORMAT.map(format => [
|
|
12
|
+
format,
|
|
13
|
+
path.join(dir, `${name}.${format}`),
|
|
14
|
+
]));
|
|
15
|
+
}
|
|
16
|
+
export async function parsePersistConfig(json) {
|
|
17
|
+
const schema = z.object({ persist: persistConfigSchema.optional() });
|
|
18
|
+
const result = await schema.safeParseAsync(json);
|
|
19
|
+
if (result.error) {
|
|
20
|
+
throw new Error(`Invalid persist config - ${stringifyError(result.error)}`);
|
|
21
|
+
}
|
|
22
|
+
return result.data;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=persist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persist.js","sourceRoot":"","sources":["../../../../../../packages/ci/src/lib/cli/persist.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,wBAAwB,EACxB,sBAAsB,EACtB,0BAA0B,EAE1B,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEvE,MAAM,UAAU,wBAAwB,CACtC,MAAmC,EACnC,EAAE,MAAM,EAAE,SAAS,EAA2C;IAE9D,MAAM,EACJ,OAAO,EAAE,EACP,SAAS,GAAG,0BAA0B,EACtC,QAAQ,GAAG,wBAAwB,GACpC,GAAG,EAAE,GACP,GAAG,MAAM,CAAC;IAEX,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;QACpC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,QAAQ,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;IAEpD,OAAO,iBAAiB,CACtB,sBAAsB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QACnC,MAAM;QACN,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,IAAI,MAAM,EAAE,CAAC;KACpC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAa;IAEb,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,mBAAmB,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACrE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,4BAA4B,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
|
package/src/lib/comment.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Logger, ProviderAPIClient } from './models';
|
|
1
|
+
import type { Logger, ProviderAPIClient } from './models.js';
|
|
2
2
|
export declare function commentOnPR(mdPath: string, api: ProviderAPIClient, logger: Logger): Promise<number>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
export async function commentOnPR(mdPath, api, logger) {
|
|
3
|
+
const markdown = await readFile(mdPath, 'utf8');
|
|
4
|
+
const identifier = `<!-- generated by @code-pushup/ci -->`;
|
|
5
|
+
const body = truncateBody(`${markdown}\n\n${identifier}\n`, api.maxCommentChars, logger);
|
|
6
|
+
const comments = await api.listComments();
|
|
7
|
+
logger.debug(`Fetched ${comments.length} comments for pull request`);
|
|
8
|
+
const prevComment = comments.find(comment => comment.body.includes(identifier));
|
|
9
|
+
logger.debug(prevComment
|
|
10
|
+
? `Found previous comment ${prevComment.id} from Code PushUp`
|
|
11
|
+
: 'Previous Code PushUp comment not found');
|
|
12
|
+
if (prevComment) {
|
|
13
|
+
const updatedComment = await api.updateComment(prevComment.id, body);
|
|
14
|
+
logger.info(`Updated body of comment ${updatedComment.url}`);
|
|
15
|
+
return updatedComment.id;
|
|
16
|
+
}
|
|
17
|
+
const createdComment = await api.createComment(body);
|
|
18
|
+
logger.info(`Created new comment ${createdComment.url}`);
|
|
19
|
+
return createdComment.id;
|
|
20
|
+
}
|
|
21
|
+
function truncateBody(body, max, logger) {
|
|
22
|
+
const truncateWarning = '...*[Comment body truncated]*';
|
|
23
|
+
if (body.length > max) {
|
|
24
|
+
logger.warn(`Comment body is too long. Truncating to ${max} characters.`);
|
|
25
|
+
return body.slice(0, max - truncateWarning.length) + truncateWarning;
|
|
26
|
+
}
|
|
27
|
+
return body;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=comment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comment.js","sourceRoot":"","sources":["../../../../../packages/ci/src/lib/comment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAc,EACd,GAAsB,EACtB,MAAc;IAEd,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChD,MAAM,UAAU,GAAG,uCAAuC,CAAC;IAC3D,MAAM,IAAI,GAAG,YAAY,CACvB,GAAG,QAAQ,OAAO,UAAU,IAAI,EAChC,GAAG,CAAC,eAAe,EACnB,MAAM,CACP,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,YAAY,EAAE,CAAC;IAC1C,MAAM,CAAC,KAAK,CAAC,WAAW,QAAQ,CAAC,MAAM,4BAA4B,CAAC,CAAC;IAErE,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAC1C,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAClC,CAAC;IACF,MAAM,CAAC,KAAK,CACV,WAAW;QACT,CAAC,CAAC,0BAA0B,WAAW,CAAC,EAAE,mBAAmB;QAC7D,CAAC,CAAC,wCAAwC,CAC7C,CAAC;IAEF,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,cAAc,GAAG,MAAM,GAAG,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACrE,MAAM,CAAC,IAAI,CAAC,2BAA2B,cAAc,CAAC,GAAG,EAAE,CAAC,CAAC;QAC7D,OAAO,cAAc,CAAC,EAAE,CAAC;IAC3B,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACrD,MAAM,CAAC,IAAI,CAAC,uBAAuB,cAAc,CAAC,GAAG,EAAE,CAAC,CAAC;IACzD,OAAO,cAAc,CAAC,EAAE,CAAC;AAC3B,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,GAAW,EAAE,MAAc;IAC7D,MAAM,eAAe,GAAG,+BAA+B,CAAC;IACxD,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QACtB,MAAM,CAAC,IAAI,CAAC,2CAA2C,GAAG,cAAc,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,eAAe,CAAC,MAAM,CAAC,GAAG,eAAe,CAAC;IACvE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/src/lib/constants.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Settings } from './models';
|
|
1
|
+
import type { Settings } from './models.js';
|
|
2
2
|
export declare const DEFAULT_SETTINGS: Settings;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const DEFAULT_SETTINGS = {
|
|
2
|
+
monorepo: false,
|
|
3
|
+
parallel: false,
|
|
4
|
+
projects: null,
|
|
5
|
+
task: 'code-pushup',
|
|
6
|
+
bin: 'npx --no-install code-pushup',
|
|
7
|
+
config: null,
|
|
8
|
+
directory: process.cwd(),
|
|
9
|
+
silent: false,
|
|
10
|
+
debug: false,
|
|
11
|
+
detectNewIssues: true,
|
|
12
|
+
logger: console,
|
|
13
|
+
nxProjectsFilter: '--with-target={task}',
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../packages/ci/src/lib/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAa;IACxC,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,IAAI;IACd,IAAI,EAAE,aAAa;IACnB,GAAG,EAAE,8BAA8B;IACnC,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,OAAO,CAAC,GAAG,EAAE;IACxB,MAAM,EAAE,KAAK;IACb,KAAK,EAAE,KAAK;IACZ,eAAe,EAAE,IAAI;IACrB,MAAM,EAAE,OAAO;IACf,gBAAgB,EAAE,sBAAsB;CACzC,CAAC"}
|
package/src/lib/git.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { DiffNameStatus, simpleGit } from 'simple-git';
|
|
2
|
+
export async function listChangedFiles(refs, git = simpleGit()) {
|
|
3
|
+
const statuses = [
|
|
4
|
+
DiffNameStatus.ADDED,
|
|
5
|
+
DiffNameStatus.COPIED,
|
|
6
|
+
DiffNameStatus.MODIFIED,
|
|
7
|
+
DiffNameStatus.RENAMED,
|
|
8
|
+
];
|
|
9
|
+
const { files } = await git.diffSummary([
|
|
10
|
+
refs.base,
|
|
11
|
+
refs.head,
|
|
12
|
+
`--diff-filter=${statuses.join('')}`,
|
|
13
|
+
'--find-renames',
|
|
14
|
+
'--find-copies',
|
|
15
|
+
]);
|
|
16
|
+
const entries = await Promise.all(files
|
|
17
|
+
.filter(({ binary }) => !binary)
|
|
18
|
+
.map(({ file }) => {
|
|
19
|
+
const rename = parseFileRename(file);
|
|
20
|
+
if (rename) {
|
|
21
|
+
return { file: rename.curr, originalFile: rename.prev };
|
|
22
|
+
}
|
|
23
|
+
return { file };
|
|
24
|
+
})
|
|
25
|
+
.map(async ({ file, originalFile }) => {
|
|
26
|
+
const diff = await git.diff([
|
|
27
|
+
'--unified=0',
|
|
28
|
+
refs.base,
|
|
29
|
+
refs.head,
|
|
30
|
+
'--',
|
|
31
|
+
file,
|
|
32
|
+
...(originalFile ? [originalFile] : []),
|
|
33
|
+
]);
|
|
34
|
+
const lineChanges = parseDiff(diff);
|
|
35
|
+
return [
|
|
36
|
+
file,
|
|
37
|
+
{ ...(originalFile && { originalFile }), lineChanges },
|
|
38
|
+
];
|
|
39
|
+
}));
|
|
40
|
+
return Object.fromEntries(entries);
|
|
41
|
+
}
|
|
42
|
+
function parseFileRename(file) {
|
|
43
|
+
const partialRenameMatch = file.match(/^(.*){(.*) => (.*)}(.*)$/);
|
|
44
|
+
if (partialRenameMatch) {
|
|
45
|
+
const [, prefix = '', prev, curr, suffix] = partialRenameMatch;
|
|
46
|
+
return {
|
|
47
|
+
prev: prefix + prev + suffix,
|
|
48
|
+
curr: prefix + curr + suffix,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const fullRenameMatch = file.match(/^(.*) => (.*)$/);
|
|
52
|
+
if (fullRenameMatch) {
|
|
53
|
+
const [, prev = '', curr = ''] = fullRenameMatch;
|
|
54
|
+
return { prev, curr };
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
function parseDiff(diff) {
|
|
59
|
+
const changeSummaries = diff.match(/@@ [ \d,+-]+ @@/g);
|
|
60
|
+
if (changeSummaries == null) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
return changeSummaries
|
|
64
|
+
.map(summary => summary.match(/^@@ -(\d+|\d+,\d+) \+(\d+|\d+,\d+) @@$/))
|
|
65
|
+
.filter((matches) => matches != null)
|
|
66
|
+
.map((matches) => {
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
68
|
+
const [prevLine = '', prevAdded = '1'] = matches[1].split(',');
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
70
|
+
const [currLine = '', currAdded = '1'] = matches[2].split(',');
|
|
71
|
+
return {
|
|
72
|
+
prev: {
|
|
73
|
+
line: Number.parseInt(prevLine, 10),
|
|
74
|
+
count: Number.parseInt(prevAdded, 10),
|
|
75
|
+
},
|
|
76
|
+
curr: {
|
|
77
|
+
line: Number.parseInt(currLine, 10),
|
|
78
|
+
count: Number.parseInt(currAdded, 10),
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
export function isFileChanged(changedFiles, file) {
|
|
84
|
+
return file in changedFiles;
|
|
85
|
+
}
|
|
86
|
+
export function adjustFileName(changedFiles, file) {
|
|
87
|
+
return (Object.entries(changedFiles).find(([, { originalFile }]) => originalFile === file)?.[0] ?? file);
|
|
88
|
+
}
|
|
89
|
+
export function adjustLine(changedFiles, file, line) {
|
|
90
|
+
const changedFile = changedFiles[adjustFileName(changedFiles, file)];
|
|
91
|
+
if (!changedFile) {
|
|
92
|
+
return line;
|
|
93
|
+
}
|
|
94
|
+
const offset = changedFile.lineChanges
|
|
95
|
+
.filter(({ prev }) => prev.line < line)
|
|
96
|
+
.reduce((acc, { prev, curr }) => acc + (curr.count - prev.count), 0);
|
|
97
|
+
return line + offset;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../../../../packages/ci/src/lib/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAcvD,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAGC,EACD,GAAG,GAAG,SAAS,EAAE;IAEjB,MAAM,QAAQ,GAAqB;QACjC,cAAc,CAAC,KAAK;QACpB,cAAc,CAAC,MAAM;QACrB,cAAc,CAAC,QAAQ;QACvB,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,IAAI,CAAC;SACtC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IACvE,OAAO,IAAI,GAAG,MAAM,CAAC;AACvB,CAAC"}
|
package/src/lib/issues.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Audit, CategoryRef, Issue, PluginMeta, Report, ReportsDiff } from '@code-pushup/models';
|
|
2
|
-
import { type ChangedFiles } from './git';
|
|
2
|
+
import { type ChangedFiles } from './git.js';
|
|
3
3
|
export type SourceFileIssue = Required<Issue> & IssueContext;
|
|
4
4
|
type IssueContext = {
|
|
5
5
|
audit: Pick<Audit, 'slug' | 'title'>;
|