Skip to content

Commit 5173f00

Browse files
committed
refactor(core,ci): handle URL source union type
1 parent ab26349 commit 5173f00

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

packages/ci/src/lib/issues.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ import type {
22
Audit,
33
AuditReport,
44
CategoryRef,
5-
Issue,
5+
FileIssue,
66
PluginMeta,
77
Report,
88
ReportsDiff,
99
} from '@code-pushup/models';
10+
import { isFileIssue } from '@code-pushup/utils';
1011
import {
1112
type ChangedFiles,
1213
adjustFileName,
1314
adjustLine,
1415
isFileChanged,
1516
} from './git.js';
1617

17-
export type SourceFileIssue = Required<Issue> & IssueContext;
18+
export type SourceFileIssue = FileIssue & IssueContext;
1819

1920
type IssueContext = {
2021
audit: Pick<Audit, 'slug' | 'title'>;
@@ -71,7 +72,7 @@ function getAuditIssues(
7172
): SourceFileIssue[] {
7273
return (
7374
audit.details?.issues
74-
?.filter((issue): issue is Required<Issue> => issue.source?.file != null)
75+
?.filter(isFileIssue)
7576
.map(issue => ({ ...issue, audit, plugin })) ?? []
7677
);
7778
}

packages/core/src/lib/implementation/report-to-gql.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type {
3333
TableAlignment,
3434
Tree,
3535
} from '@code-pushup/models';
36+
import { isFileIssue } from '@code-pushup/utils';
3637

3738
export function reportToGQL(
3839
report: Report,
@@ -106,7 +107,7 @@ export function issueToGQL(issue: Issue): PortalIssue {
106107
return {
107108
message: issue.message,
108109
severity: issueSeverityToGQL(issue.severity),
109-
...(issue.source?.file && {
110+
...(isFileIssue(issue) && {
110111
sourceType: safeEnum<PortalIssueSourceType>('SourceCode'),
111112
sourceFilePath: issue.source.file,
112113
sourceStartLine: issue.source.position?.startLine,

packages/core/src/lib/normalize.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import type { AuditOutputs, Issue } from '@code-pushup/models';
2-
import { formatGitPath, getGitRoot } from '@code-pushup/utils';
2+
import { formatGitPath, getGitRoot, isFileIssue } from '@code-pushup/utils';
33

44
export function normalizeIssue(issue: Issue, gitRoot: string): Issue {
5+
// Early exit to avoid cloning; only file sources need path normalization
6+
if (!isFileIssue(issue)) {
7+
return issue;
8+
}
59
const { source, ...issueWithoutSource } = issue;
6-
// early exit to avoid issue object cloning.
7-
return source == null
8-
? issue
9-
: {
10-
...issueWithoutSource,
11-
source: {
12-
...source,
13-
file: formatGitPath(source.file, gitRoot),
14-
},
15-
};
10+
return {
11+
...issueWithoutSource,
12+
source: {
13+
...source,
14+
file: formatGitPath(source.file, gitRoot),
15+
},
16+
};
1617
}
1718

1819
export async function normalizeAuditOutputs(

0 commit comments

Comments
 (0)