sonar-sweep 0.1.0 → 0.2.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 +1 -1
- package/dist/cli/index.d.mts +4 -0
- package/dist/cli/index.mjs +3 -0
- package/dist/cli-DYHj3O_0.mjs +650 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +14 -0
- package/dist/index.d.mts +263 -0
- package/dist/index.mjs +3 -0
- package/dist/issue-transition-C1WIMpYQ.mjs +338 -0
- package/package.json +36 -11
- package/dist/cli/commands/issue-accept.d.ts +0 -13
- package/dist/cli/commands/issue-accept.js +0 -49
- package/dist/cli/commands/issue-accept.js.map +0 -1
- package/dist/cli/commands/pr-coverage.d.ts +0 -16
- package/dist/cli/commands/pr-coverage.js +0 -79
- package/dist/cli/commands/pr-coverage.js.map +0 -1
- package/dist/cli/commands/pr-issues.d.ts +0 -15
- package/dist/cli/commands/pr-issues.js +0 -78
- package/dist/cli/commands/pr-issues.js.map +0 -1
- package/dist/cli/commands/pr-report.d.ts +0 -13
- package/dist/cli/commands/pr-report.js +0 -94
- package/dist/cli/commands/pr-report.js.map +0 -1
- package/dist/cli/commands/pr-review.d.ts +0 -16
- package/dist/cli/commands/pr-review.js +0 -93
- package/dist/cli/commands/pr-review.js.map +0 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +0 -28
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/project-key.d.ts +0 -1
- package/dist/cli/project-key.js +0 -32
- package/dist/cli/project-key.js.map +0 -1
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -8
- package/dist/cli.js.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -7
- package/dist/index.js.map +0 -1
- package/dist/service/issue-transition.d.ts +0 -12
- package/dist/service/issue-transition.js +0 -20
- package/dist/service/issue-transition.js.map +0 -1
- package/dist/service/pr-coverage.d.ts +0 -22
- package/dist/service/pr-coverage.js +0 -48
- package/dist/service/pr-coverage.js.map +0 -1
- package/dist/service/pr-issues.d.ts +0 -29
- package/dist/service/pr-issues.js +0 -45
- package/dist/service/pr-issues.js.map +0 -1
- package/dist/service/pr-report.d.ts +0 -27
- package/dist/service/pr-report.js +0 -59
- package/dist/service/pr-report.js.map +0 -1
- package/dist/service/pr-review.d.ts +0 -39
- package/dist/service/pr-review.js +0 -81
- package/dist/service/pr-review.js.map +0 -1
- package/dist/service/sonarcloud-client.d.ts +0 -100
- package/dist/service/sonarcloud-client.js +0 -112
- package/dist/service/sonarcloud-client.js.map +0 -1
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { SonarCloudClient } from './sonarcloud-client.js';
|
|
2
|
-
export async function transitionIssue(clientOptions, input) {
|
|
3
|
-
const issueKey = input.issueKey.trim();
|
|
4
|
-
const transition = input.transition.trim();
|
|
5
|
-
const comment = input.comment?.trim();
|
|
6
|
-
if (!issueKey) {
|
|
7
|
-
throw new Error('Missing issueKey');
|
|
8
|
-
}
|
|
9
|
-
if (!transition) {
|
|
10
|
-
throw new Error('Missing transition');
|
|
11
|
-
}
|
|
12
|
-
const client = new SonarCloudClient(clientOptions);
|
|
13
|
-
await client.doIssueTransition(issueKey, transition, comment);
|
|
14
|
-
return {
|
|
15
|
-
issueKey,
|
|
16
|
-
transition,
|
|
17
|
-
applied: true,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=issue-transition.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"issue-transition.js","sourceRoot":"","sources":["../../src/service/issue-transition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAgC,MAAM,wBAAwB,CAAA;AAcvF,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,aAAsC,EACtC,KAA2B;IAE3B,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;IACtC,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAA;IAC1C,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,CAAA;IAErC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;IACrC,CAAC;IAED,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;IACvC,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,gBAAgB,CAAC,aAAa,CAAC,CAAA;IAClD,MAAM,MAAM,CAAC,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;IAE7D,OAAO;QACL,QAAQ;QACR,UAAU;QACV,OAAO,EAAE,IAAI;KACd,CAAA;AACH,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type SonarCloudClientOptions } from './sonarcloud-client.js';
|
|
2
|
-
export type PullRequestCoverageFile = {
|
|
3
|
-
file: string;
|
|
4
|
-
coverageOnNewCode: number;
|
|
5
|
-
linesToCover: number;
|
|
6
|
-
uncoveredLines: number;
|
|
7
|
-
};
|
|
8
|
-
export type PullRequestCoverageReport = {
|
|
9
|
-
projectKey: string;
|
|
10
|
-
pullRequest: string;
|
|
11
|
-
threshold: number;
|
|
12
|
-
analysisUrl: string;
|
|
13
|
-
files: PullRequestCoverageFile[];
|
|
14
|
-
};
|
|
15
|
-
export type PullRequestCoverageInput = {
|
|
16
|
-
projectKey: string;
|
|
17
|
-
pullRequest: string;
|
|
18
|
-
threshold?: number;
|
|
19
|
-
includePassing?: boolean;
|
|
20
|
-
maxFiles?: number;
|
|
21
|
-
};
|
|
22
|
-
export declare function getPullRequestCoverage(clientOptions: SonarCloudClientOptions, input: PullRequestCoverageInput): Promise<PullRequestCoverageReport>;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { SonarCloudClient } from './sonarcloud-client.js';
|
|
2
|
-
export async function getPullRequestCoverage(clientOptions, input) {
|
|
3
|
-
const projectKey = input.projectKey.trim();
|
|
4
|
-
const pullRequest = input.pullRequest.trim();
|
|
5
|
-
if (!projectKey) {
|
|
6
|
-
throw new Error('Missing projectKey');
|
|
7
|
-
}
|
|
8
|
-
if (!pullRequest) {
|
|
9
|
-
throw new Error('Missing pullRequest');
|
|
10
|
-
}
|
|
11
|
-
const threshold = input.threshold ?? 80;
|
|
12
|
-
const includePassing = input.includePassing ?? false;
|
|
13
|
-
const maxFiles = Math.max(1, input.maxFiles ?? 20);
|
|
14
|
-
const baseUrl = (clientOptions.baseUrl ?? 'https://sonarcloud.io').replace(/\/$/, '');
|
|
15
|
-
const client = new SonarCloudClient(clientOptions);
|
|
16
|
-
const tree = await client.getCoverageComponentTree(projectKey, pullRequest, 1, 500);
|
|
17
|
-
const files = tree.components
|
|
18
|
-
.map((component) => {
|
|
19
|
-
const file = component.path ?? component.name;
|
|
20
|
-
const coverageOnNewCode = value(component.measures, 'new_coverage');
|
|
21
|
-
const linesToCover = value(component.measures, 'new_lines_to_cover');
|
|
22
|
-
const uncoveredLines = value(component.measures, 'new_uncovered_lines');
|
|
23
|
-
return {
|
|
24
|
-
file,
|
|
25
|
-
coverageOnNewCode,
|
|
26
|
-
linesToCover,
|
|
27
|
-
uncoveredLines,
|
|
28
|
-
};
|
|
29
|
-
})
|
|
30
|
-
.filter((item) => item.linesToCover > 0)
|
|
31
|
-
.filter((item) => includePassing || item.coverageOnNewCode < threshold)
|
|
32
|
-
.sort((a, b) => a.coverageOnNewCode - b.coverageOnNewCode)
|
|
33
|
-
.slice(0, maxFiles);
|
|
34
|
-
return {
|
|
35
|
-
projectKey,
|
|
36
|
-
pullRequest,
|
|
37
|
-
threshold,
|
|
38
|
-
analysisUrl: `${baseUrl}/dashboard?id=${encodeURIComponent(projectKey)}&pullRequest=${encodeURIComponent(pullRequest)}`,
|
|
39
|
-
files,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function value(measures, metric) {
|
|
43
|
-
const measure = measures.find((item) => item.metric === metric);
|
|
44
|
-
const raw = measure?.periods?.[0]?.value ?? measure?.value ?? '0';
|
|
45
|
-
const parsed = Number.parseFloat(raw);
|
|
46
|
-
return Number.isFinite(parsed) ? parsed : 0;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=pr-coverage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pr-coverage.js","sourceRoot":"","sources":["../../src/service/pr-coverage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAgC,MAAM,wBAAwB,CAAA;AAyBvF,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,aAAsC,EACtC,KAA+B;IAE/B,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAA;IAC1C,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,CAAA;IAC5C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;IACvC,CAAC;IACD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;IACxC,CAAC;IAED,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,EAAE,CAAA;IACvC,MAAM,cAAc,GAAG,KAAK,CAAC,cAAc,IAAI,KAAK,CAAA;IACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAA;IAClD,MAAM,OAAO,GAAG,CAAC,aAAa,CAAC,OAAO,IAAI,uBAAuB,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IAErF,MAAM,MAAM,GAAG,IAAI,gBAAgB,CAAC,aAAa,CAAC,CAAA;IAClD,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,wBAA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AAM,CAAC,CAAA;IAC/D,MAAM,GAAG,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,OAAO,EAAE,KAAK,IAAI,GAAG,CAAA;IACjE,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;IACrC,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7C,CAAC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type SonarCloudClientOptions } from './sonarcloud-client.js';
|
|
2
|
-
export type PullRequestIssue = {
|
|
3
|
-
key: string;
|
|
4
|
-
type: string;
|
|
5
|
-
severity: string;
|
|
6
|
-
status: string;
|
|
7
|
-
issueStatus: string;
|
|
8
|
-
rule: string;
|
|
9
|
-
message: string;
|
|
10
|
-
file: string;
|
|
11
|
-
line?: number;
|
|
12
|
-
effort?: string;
|
|
13
|
-
};
|
|
14
|
-
export type PullRequestIssuesReport = {
|
|
15
|
-
projectKey: string;
|
|
16
|
-
pullRequest: string;
|
|
17
|
-
total: number;
|
|
18
|
-
page: number;
|
|
19
|
-
pageSize: number;
|
|
20
|
-
analysisUrl: string;
|
|
21
|
-
issues: PullRequestIssue[];
|
|
22
|
-
};
|
|
23
|
-
export type PullRequestIssuesInput = {
|
|
24
|
-
projectKey: string;
|
|
25
|
-
pullRequest: string;
|
|
26
|
-
page?: number;
|
|
27
|
-
pageSize?: number;
|
|
28
|
-
};
|
|
29
|
-
export declare function getPullRequestIssues(clientOptions: SonarCloudClientOptions, input: PullRequestIssuesInput): Promise<PullRequestIssuesReport>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { SonarCloudClient, } from './sonarcloud-client.js';
|
|
2
|
-
export async function getPullRequestIssues(clientOptions, input) {
|
|
3
|
-
const projectKey = input.projectKey.trim();
|
|
4
|
-
const pullRequest = input.pullRequest.trim();
|
|
5
|
-
if (!projectKey) {
|
|
6
|
-
throw new Error('Missing projectKey');
|
|
7
|
-
}
|
|
8
|
-
if (!pullRequest) {
|
|
9
|
-
throw new Error('Missing pullRequest');
|
|
10
|
-
}
|
|
11
|
-
const page = input.page ?? 1;
|
|
12
|
-
const pageSize = input.pageSize ?? 100;
|
|
13
|
-
const baseUrl = (clientOptions.baseUrl ?? 'https://sonarcloud.io').replace(/\/$/, '');
|
|
14
|
-
const client = new SonarCloudClient(clientOptions);
|
|
15
|
-
const response = await client.getPullRequestIssues(projectKey, pullRequest, page, pageSize);
|
|
16
|
-
const componentPathByKey = new Map((response.components ?? []).map((component) => [
|
|
17
|
-
component.key,
|
|
18
|
-
component.path ?? component.longName ?? component.key,
|
|
19
|
-
]));
|
|
20
|
-
const issues = (response.issues ?? []).map((issue) => {
|
|
21
|
-
const file = componentPathByKey.get(issue.component) ?? issue.component.split(':').slice(1).join(':') ?? issue.component;
|
|
22
|
-
return {
|
|
23
|
-
key: issue.key,
|
|
24
|
-
type: issue.type,
|
|
25
|
-
severity: issue.severity,
|
|
26
|
-
status: issue.status,
|
|
27
|
-
issueStatus: issue.issueStatus ?? issue.status,
|
|
28
|
-
rule: issue.rule,
|
|
29
|
-
message: issue.message,
|
|
30
|
-
file,
|
|
31
|
-
line: issue.line,
|
|
32
|
-
effort: issue.effort,
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
return {
|
|
36
|
-
projectKey,
|
|
37
|
-
pullRequest,
|
|
38
|
-
total: response.total,
|
|
39
|
-
page: response.paging?.pageIndex ?? page,
|
|
40
|
-
pageSize: response.paging?.pageSize ?? pageSize,
|
|
41
|
-
analysisUrl: `${baseUrl}/dashboard?id=${encodeURIComponent(projectKey)}&pullRequest=${encodeURIComponent(pullRequest)}`,
|
|
42
|
-
issues,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=pr-issues.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file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,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAiB,EAAoB,EAAE;QACjF,MAAM,IAAI,GACR,kBAAkB,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,SAAS,CAAA;QAE7G,OAAO;YACL,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,WAAW,EAAE,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,MAAM;YAC9C,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,IAAI;YACJ,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,OAAO;QACL,UAAU;QACV,WAAW;QACX,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,IAAI,IAAI;QACxC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,IAAI,QAAQ;QAC/C,WAAW,EAAE,GAAG,OAAO,iBAAiB,kBAAkB,CAAC,UAAU,CAAC,gBAAgB,kBAAkB,CAAC,WAAW,CAAC,EAAE;QACvH,MAAM;KACP,CAAA;AACH,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type SonarCloudClientOptions } from './sonarcloud-client.js';
|
|
2
|
-
export type PullRequestReport = {
|
|
3
|
-
projectKey: string;
|
|
4
|
-
pullRequest: string;
|
|
5
|
-
qualityGateStatus: string;
|
|
6
|
-
failingQualityGateConditions: Array<{
|
|
7
|
-
metricKey: string;
|
|
8
|
-
comparator: string;
|
|
9
|
-
errorThreshold?: string;
|
|
10
|
-
actualValue?: string;
|
|
11
|
-
}>;
|
|
12
|
-
analysisUrl: string;
|
|
13
|
-
issueCounts: {
|
|
14
|
-
newIssues: number;
|
|
15
|
-
acceptedIssues: number;
|
|
16
|
-
};
|
|
17
|
-
measures: {
|
|
18
|
-
securityHotspots: number;
|
|
19
|
-
coverageOnNewCode: number;
|
|
20
|
-
duplicationOnNewCode: number;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
export type PullRequestReportInput = {
|
|
24
|
-
projectKey: string;
|
|
25
|
-
pullRequest: string;
|
|
26
|
-
};
|
|
27
|
-
export declare function getPullRequestReport(clientOptions: SonarCloudClientOptions, input: PullRequestReportInput): Promise<PullRequestReport>;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { SonarCloudClient, } from './sonarcloud-client.js';
|
|
2
|
-
export async function getPullRequestReport(clientOptions, input) {
|
|
3
|
-
const projectKey = input.projectKey.trim();
|
|
4
|
-
const pullRequest = input.pullRequest.trim();
|
|
5
|
-
if (!projectKey) {
|
|
6
|
-
throw new Error('Missing projectKey');
|
|
7
|
-
}
|
|
8
|
-
if (!pullRequest) {
|
|
9
|
-
throw new Error('Missing pullRequest');
|
|
10
|
-
}
|
|
11
|
-
const baseUrl = (clientOptions.baseUrl ?? 'https://sonarcloud.io').replace(/\/$/, '');
|
|
12
|
-
const client = new SonarCloudClient(clientOptions);
|
|
13
|
-
const [projectStatusResponse, issuesResponse, measuresResponse] = await Promise.all([
|
|
14
|
-
client.getProjectStatus(projectKey, pullRequest),
|
|
15
|
-
client.getIssuesFacets(projectKey, pullRequest),
|
|
16
|
-
client.getMeasures(projectKey, pullRequest),
|
|
17
|
-
]);
|
|
18
|
-
const issueStatuses = issuesResponse.facets.find((facet) => facet.property === 'issueStatuses');
|
|
19
|
-
const newIssues = sumCounts(issueStatuses?.values, ['OPEN', 'CONFIRMED', 'REOPENED']);
|
|
20
|
-
const acceptedIssues = sumCounts(issueStatuses?.values, ['ACCEPTED']);
|
|
21
|
-
return {
|
|
22
|
-
projectKey,
|
|
23
|
-
pullRequest,
|
|
24
|
-
qualityGateStatus: projectStatusResponse.projectStatus.status,
|
|
25
|
-
failingQualityGateConditions: projectStatusResponse.projectStatus.conditions
|
|
26
|
-
.filter((condition) => condition.status !== 'OK')
|
|
27
|
-
.map((condition) => ({
|
|
28
|
-
metricKey: condition.metricKey,
|
|
29
|
-
comparator: condition.comparator,
|
|
30
|
-
errorThreshold: condition.errorThreshold,
|
|
31
|
-
actualValue: condition.actualValue,
|
|
32
|
-
})),
|
|
33
|
-
analysisUrl: `${baseUrl}/dashboard?id=${encodeURIComponent(projectKey)}&pullRequest=${encodeURIComponent(pullRequest)}`,
|
|
34
|
-
issueCounts: {
|
|
35
|
-
newIssues,
|
|
36
|
-
acceptedIssues,
|
|
37
|
-
},
|
|
38
|
-
measures: {
|
|
39
|
-
securityHotspots: measureValue(measuresResponse.component.measures, 'new_security_hotspots'),
|
|
40
|
-
coverageOnNewCode: measureValue(measuresResponse.component.measures, 'new_coverage'),
|
|
41
|
-
duplicationOnNewCode: measureValue(measuresResponse.component.measures, 'new_duplicated_lines_density'),
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function sumCounts(values, keys) {
|
|
46
|
-
if (!values) {
|
|
47
|
-
return 0;
|
|
48
|
-
}
|
|
49
|
-
return values
|
|
50
|
-
.filter((item) => keys.includes(item.val))
|
|
51
|
-
.reduce((total, item) => total + item.count, 0);
|
|
52
|
-
}
|
|
53
|
-
function measureValue(measures, metric) {
|
|
54
|
-
const measure = measures.find((item) => item.metric === metric);
|
|
55
|
-
const rawValue = measure?.periods?.[0]?.value ?? measure?.value ?? '0';
|
|
56
|
-
const parsed = Number.parseFloat(rawValue);
|
|
57
|
-
return Number.isFinite(parsed) ? parsed : 0;
|
|
58
|
-
}
|
|
59
|
-
//# sourceMapp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C,IAAI,CAAC,GAAG,CAAC,CAAC;SACzC,MAAM,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;AACnD,CAAC;AAED,SAAS,YAAY,CACnB,QAAuF,EACvF,MAAc;IAEd,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,CAAA;IAC/D,MAAM,QAAQ,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,OAAO,EAAE,KAAK,IAAI,GAAG,CAAA;IACtE,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;IAC1C,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7C,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type SonarCloudClientOptions } from './sonarcloud-client.js';
|
|
2
|
-
export type PullRequestIssueReview = {
|
|
3
|
-
key: string;
|
|
4
|
-
type: string;
|
|
5
|
-
severity: string;
|
|
6
|
-
status: string;
|
|
7
|
-
issueStatus: string;
|
|
8
|
-
rule: string;
|
|
9
|
-
message: string;
|
|
10
|
-
file: string;
|
|
11
|
-
line?: number;
|
|
12
|
-
effort?: string;
|
|
13
|
-
issueUrl: string;
|
|
14
|
-
snippet?: {
|
|
15
|
-
startLine: number;
|
|
16
|
-
endLine: number;
|
|
17
|
-
lines: Array<{
|
|
18
|
-
line: number;
|
|
19
|
-
text: string;
|
|
20
|
-
highlight: boolean;
|
|
21
|
-
}>;
|
|
22
|
-
};
|
|
23
|
-
sourceError?: string;
|
|
24
|
-
};
|
|
25
|
-
export type PullRequestReviewReport = {
|
|
26
|
-
projectKey: string;
|
|
27
|
-
pullRequest: string;
|
|
28
|
-
total: number;
|
|
29
|
-
analysisUrl: string;
|
|
30
|
-
issues: PullRequestIssueReview[];
|
|
31
|
-
};
|
|
32
|
-
export type PullRequestReviewInput = {
|
|
33
|
-
projectKey: string;
|
|
34
|
-
pullRequest: string;
|
|
35
|
-
contextLines?: number;
|
|
36
|
-
page?: number;
|
|
37
|
-
pageSize?: number;
|
|
38
|
-
};
|
|
39
|
-
export declare function getPullRequestReview(clientOptions: SonarCloudClientOptions, input: PullRequestReviewInput): Promise<PullRequestReviewReport>;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { SonarCloudClient } from './sonarcloud-client.js';
|
|
2
|
-
export async function getPullRequestReview(clientOptions, input) {
|
|
3
|
-
const projectKey = input.projectKey.trim();
|
|
4
|
-
const pullRequest = input.pullRequest.trim();
|
|
5
|
-
if (!projectKey) {
|
|
6
|
-
throw new Error('Missing projectKey');
|
|
7
|
-
}
|
|
8
|
-
if (!pullRequest) {
|
|
9
|
-
throw new Error('Missing pullRequest');
|
|
10
|
-
}
|
|
11
|
-
const page = input.page ?? 1;
|
|
12
|
-
const pageSize = input.pageSize ?? 100;
|
|
13
|
-
const contextLines = Math.max(0, input.contextLines ?? 3);
|
|
14
|
-
const baseUrl = (clientOptions.baseUrl ?? 'https://sonarcloud.io').replace(/\/$/, '');
|
|
15
|
-
const client = new SonarCloudClient(clientOptions);
|
|
16
|
-
const response = await client.getPullRequestIssues(projectKey, pullRequest, page, pageSize);
|
|
17
|
-
const componentPathByKey = new Map((response.components ?? []).map((component) => [
|
|
18
|
-
component.key,
|
|
19
|
-
component.path ?? component.longName ?? component.key,
|
|
20
|
-
]));
|
|
21
|
-
const issues = await Promise.all((response.issues ?? []).map(async (issue) => {
|
|
22
|
-
const file = componentPathByKey.get(issue.component) ?? issue.component.split(':').slice(1).join(':') ?? issue.component;
|
|
23
|
-
const result = {
|
|
24
|
-
key: issue.key,
|
|
25
|
-
type: issue.type,
|
|
26
|
-
severity: issue.severity,
|
|
27
|
-
status: issue.status,
|
|
28
|
-
issueStatus: issue.issueStatus ?? issue.status,
|
|
29
|
-
rule: issue.rule,
|
|
30
|
-
message: issue.message,
|
|
31
|
-
file,
|
|
32
|
-
line: issue.line,
|
|
33
|
-
effort: issue.effort,
|
|
34
|
-
issueUrl: buildIssueUrl(baseUrl, projectKey, pullRequest, issue.key),
|
|
35
|
-
};
|
|
36
|
-
if (!issue.line) {
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
const source = await client.getSourceRaw(issue.component, pullRequest);
|
|
41
|
-
result.snippet = makeSnippet(source, issue.line, contextLines);
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
result.sourceError = error instanceof Error ? error.message : String(error);
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
}));
|
|
48
|
-
return {
|
|
49
|
-
projectKey,
|
|
50
|
-
pullRequest,
|
|
51
|
-
total: response.total,
|
|
52
|
-
analysisUrl: `${baseUrl}/dashboard?id=${encodeURIComponent(projectKey)}&pullRequest=${encodeURIComponent(pullRequest)}`,
|
|
53
|
-
issues,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function buildIssueUrl(baseUrl, projectKey, pullRequest, issueKey) {
|
|
57
|
-
const url = new URL('/project/issues', baseUrl);
|
|
58
|
-
url.searchParams.set('id', projectKey);
|
|
59
|
-
url.searchParams.set('pullRequest', pullRequest);
|
|
60
|
-
url.searchParams.set('issues', issueKey);
|
|
61
|
-
url.searchParams.set('open', issueKey);
|
|
62
|
-
return String(url);
|
|
63
|
-
}
|
|
64
|
-
function makeSnippet(source, issueLine, contextLines) {
|
|
65
|
-
const lines = source.split(/\r?\n/);
|
|
66
|
-
const startLine = Math.max(1, issueLine - contextLines);
|
|
67
|
-
const endLine = Math.min(lines.length, issueLine + contextLines);
|
|
68
|
-
return {
|
|
69
|
-
startLine,
|
|
70
|
-
endLine,
|
|
71
|
-
lines: lines.slice(startLine - 1, endLine).map((text, index) => {
|
|
72
|
-
const line = startLine + index;
|
|
73
|
-
return {
|
|
74
|
-
line,
|
|
75
|
-
text,
|
|
76
|
-
highlight: line === issueLine,
|
|
77
|
-
};
|
|
78
|
-
}),
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=pr-review.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pr-review.js","sourceRoot":"","sources":["../../src/service/pr-review.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAgC,MAAM,wBAAwB,CAAA;AA0CvF,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,aAAsC,EACtC,KAA6B;IAE7B,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAA;IAC1C,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,CAAA;IAC5C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;IACvC,CAAC;IACD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;IACxC,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,CAAC,CAAA;IAC5B,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,GAAG,CAAA;IACtC,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,YAAY,IAAI,CAAC,CAAC,CAAA;IACzD,MAAM,OAAO,GAAG,CAAC,aAAa,CAAC,OAAO,IAAI,uBAAuB,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IAErF,MAAM,MAAM,GAAG,IAAI,gBAAgB,CAAC,aAAa,CAAC,CAAA;IAClD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,UAAU,EAAE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AG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACnC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC,CAAA;IACvD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,YAAY,CAAC,CAAA;IAEhE,OAAO;QACL,SAAS;QACT,OAAO;QACP,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAC7D,MAAM,IAAI,GAAG,SAAS,GAAG,KAAK,CAAA;YAC9B,OAAO;gBACL,IAAI;gBACJ,IAAI;gBACJ,SAAS,EAAE,IAAI,KAAK,SAAS;aAC9B,CAAA;QACH,CAAC,CAAC;KACH,CAAA;AACH,CAAC"}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
export type SonarCloudClientOptions = {
|
|
2
|
-
token: string;
|
|
3
|
-
baseUrl?: string;
|
|
4
|
-
fetchImpl?: typeof fetch;
|
|
5
|
-
};
|
|
6
|
-
export type QualityGateCondition = {
|
|
7
|
-
status: string;
|
|
8
|
-
metricKey: string;
|
|
9
|
-
comparator: string;
|
|
10
|
-
errorThreshold?: string;
|
|
11
|
-
actualValue?: string;
|
|
12
|
-
};
|
|
13
|
-
export type ProjectStatusResponse = {
|
|
14
|
-
projectStatus: {
|
|
15
|
-
status: string;
|
|
16
|
-
conditions: QualityGateCondition[];
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export type IssuesFacetValue = {
|
|
20
|
-
val: string;
|
|
21
|
-
count: number;
|
|
22
|
-
};
|
|
23
|
-
export type IssuesSearchResponse = {
|
|
24
|
-
total: number;
|
|
25
|
-
paging?: {
|
|
26
|
-
pageIndex: number;
|
|
27
|
-
pageSize: number;
|
|
28
|
-
total: number;
|
|
29
|
-
};
|
|
30
|
-
issues?: SonarIssue[];
|
|
31
|
-
components?: SonarIssueComponent[];
|
|
32
|
-
facets: Array<{
|
|
33
|
-
property: string;
|
|
34
|
-
values: IssuesFacetValue[];
|
|
35
|
-
}>;
|
|
36
|
-
};
|
|
37
|
-
export type SonarIssue = {
|
|
38
|
-
key: string;
|
|
39
|
-
rule: string;
|
|
40
|
-
severity: string;
|
|
41
|
-
component: string;
|
|
42
|
-
line?: number;
|
|
43
|
-
status: string;
|
|
44
|
-
issueStatus?: string;
|
|
45
|
-
message: string;
|
|
46
|
-
type: string;
|
|
47
|
-
effort?: string;
|
|
48
|
-
};
|
|
49
|
-
export type SonarIssueComponent = {
|
|
50
|
-
key: string;
|
|
51
|
-
path?: string;
|
|
52
|
-
longName?: string;
|
|
53
|
-
};
|
|
54
|
-
export type MeasuresResponse = {
|
|
55
|
-
component: {
|
|
56
|
-
measures: Array<{
|
|
57
|
-
metric: string;
|
|
58
|
-
value?: string;
|
|
59
|
-
periods?: Array<{
|
|
60
|
-
index: number;
|
|
61
|
-
value: string;
|
|
62
|
-
}>;
|
|
63
|
-
}>;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
export type ComponentTreeResponse = {
|
|
67
|
-
paging: {
|
|
68
|
-
pageIndex: number;
|
|
69
|
-
pageSize: number;
|
|
70
|
-
total: number;
|
|
71
|
-
};
|
|
72
|
-
components: Array<{
|
|
73
|
-
key: string;
|
|
74
|
-
path?: string;
|
|
75
|
-
name: string;
|
|
76
|
-
measures: Array<{
|
|
77
|
-
metric: string;
|
|
78
|
-
value?: string;
|
|
79
|
-
periods?: Array<{
|
|
80
|
-
index: number;
|
|
81
|
-
value: string;
|
|
82
|
-
}>;
|
|
83
|
-
}>;
|
|
84
|
-
}>;
|
|
85
|
-
};
|
|
86
|
-
export declare class SonarCloudClient {
|
|
87
|
-
private readonly token;
|
|
88
|
-
private readonly baseUrl;
|
|
89
|
-
private readonly fetchImpl;
|
|
90
|
-
constructor(options: SonarCloudClientOptions);
|
|
91
|
-
getProjectStatus(projectKey: string, pullRequest: string): Promise<ProjectStatusResponse>;
|
|
92
|
-
getIssuesFacets(projectKey: string, pullRequest: string): Promise<IssuesSearchResponse>;
|
|
93
|
-
getPullRequestIssues(projectKey: string, pullRequest: string, page?: number, pageSize?: number): Promise<IssuesSearchResponse>;
|
|
94
|
-
getMeasures(projectKey: string, pullRequest: string): Promise<MeasuresResponse>;
|
|
95
|
-
getCoverageComponentTree(projectKey: string, pullRequest: string, page?: number, pageSize?: number): Promise<ComponentTreeResponse>;
|
|
96
|
-
getSourceRaw(componentKey: string, pullRequest: string): Promise<string>;
|
|
97
|
-
doIssueTransition(issueKey: string, transition: string, comment?: string): Promise<void>;
|
|
98
|
-
private get;
|
|
99
|
-
private post;
|
|
100
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
export class SonarCloudClient {
|
|
2
|
-
token;
|
|
3
|
-
baseUrl;
|
|
4
|
-
fetchImpl;
|
|
5
|
-
constructor(options) {
|
|
6
|
-
if (!options.token?.trim()) {
|
|
7
|
-
throw new Error('Missing Sonar token');
|
|
8
|
-
}
|
|
9
|
-
this.token = options.token.trim();
|
|
10
|
-
this.baseUrl = (options.baseUrl ?? 'https://sonarcloud.io').replace(/\/$/, '');
|
|
11
|
-
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
12
|
-
}
|
|
13
|
-
async getProjectStatus(projectKey, pullRequest) {
|
|
14
|
-
return this.get('/api/qualitygates/project_status', {
|
|
15
|
-
projectKey,
|
|
16
|
-
pullRequest,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
async getIssuesFacets(projectKey, pullRequest) {
|
|
20
|
-
return this.get('/api/issues/search', {
|
|
21
|
-
componentKeys: projectKey,
|
|
22
|
-
pullRequest,
|
|
23
|
-
inNewCodePeriod: 'true',
|
|
24
|
-
facets: 'issueStatuses',
|
|
25
|
-
ps: '1',
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
async getPullRequestIssues(projectKey, pullRequest, page = 1, pageSize = 100) {
|
|
29
|
-
return this.get('/api/issues/search', {
|
|
30
|
-
componentKeys: projectKey,
|
|
31
|
-
pullRequest,
|
|
32
|
-
inNewCodePeriod: 'true',
|
|
33
|
-
resolved: 'false',
|
|
34
|
-
p: String(page),
|
|
35
|
-
ps: String(pageSize),
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
async getMeasures(projectKey, pullRequest) {
|
|
39
|
-
return this.get('/api/measures/component', {
|
|
40
|
-
component: projectKey,
|
|
41
|
-
pullRequest,
|
|
42
|
-
metricKeys: 'new_security_hotspots,new_coverage,new_duplicated_lines_density',
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
async getCoverageComponentTree(projectKey, pullRequest, page = 1, pageSize = 100) {
|
|
46
|
-
return this.get('/api/measures/component_tree', {
|
|
47
|
-
component: projectKey,
|
|
48
|
-
pullRequest,
|
|
49
|
-
qualifiers: 'FIL',
|
|
50
|
-
metricKeys: 'new_coverage,new_lines_to_cover,new_uncovered_lines',
|
|
51
|
-
p: String(page),
|
|
52
|
-
ps: String(pageSize),
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
async getSourceRaw(componentKey, pullRequest) {
|
|
56
|
-
const url = new URL('/api/sources/raw', this.baseUrl);
|
|
57
|
-
url.searchParams.set('key', componentKey);
|
|
58
|
-
url.searchParams.set('pullRequest', pullRequest);
|
|
59
|
-
const response = await this.fetchImpl(url, {
|
|
60
|
-
method: 'GET',
|
|
61
|
-
headers: {
|
|
62
|
-
Authorization: `Bearer ${this.token}`,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
if (!response.ok) {
|
|
66
|
-
const body = await response.text();
|
|
67
|
-
throw new Error(`Sonar API request failed (${response.status}) for /api/sources/raw: ${body}`);
|
|
68
|
-
}
|
|
69
|
-
return response.text();
|
|
70
|
-
}
|
|
71
|
-
async doIssueTransition(issueKey, transition, comment) {
|
|
72
|
-
await this.post('/api/issues/do_transition', {
|
|
73
|
-
issue: issueKey,
|
|
74
|
-
transition,
|
|
75
|
-
...(comment ? { comment } : {}),
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
async get(path, query) {
|
|
79
|
-
const url = new URL(path, this.baseUrl);
|
|
80
|
-
for (const [key, value] of Object.entries(query)) {
|
|
81
|
-
url.searchParams.set(key, value);
|
|
82
|
-
}
|
|
83
|
-
const response = await this.fetchImpl(url, {
|
|
84
|
-
method: 'GET',
|
|
85
|
-
headers: {
|
|
86
|
-
Authorization: `Bearer ${this.token}`,
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
if (!response.ok) {
|
|
90
|
-
const body = await response.text();
|
|
91
|
-
throw new Error(`Sonar API request failed (${response.status}) for ${path}: ${body}`);
|
|
92
|
-
}
|
|
93
|
-
return (await response.json());
|
|
94
|
-
}
|
|
95
|
-
async post(path, form) {
|
|
96
|
-
const url = new URL(path, this.baseUrl);
|
|
97
|
-
const body = new URLSearchParams(form);
|
|
98
|
-
const response = await this.fetchImpl(url, {
|
|
99
|
-
method: 'POST',
|
|
100
|
-
headers: {
|
|
101
|
-
Authorization: `Bearer ${this.token}`,
|
|
102
|
-
'content-type': 'application/x-www-form-urlencoded',
|
|
103
|
-
},
|
|
104
|
-
body,
|
|
105
|
-
});
|
|
106
|
-
if (!response.ok) {
|
|
107
|
-
const responseBody = await response.text();
|
|
108
|
-
throw new Error(`Sonar API request failed (${response.status}) for ${path}: ${responseBody}`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
//# sourceMappingURL=sonarcloud-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sonarcloud-client.js","sourceRoot":"","sources":["../../src/service/sonarcloud-client.ts"],"names":[],"mappings":"AA8FA,MAAM,OAAO,gBAAgB;IACV,KAAK,CAAQ;IACb,OAAO,CAAQ;IACf,SAAS,CAAc;IAExC,YAAY,OAAgC;QAC1C,IAAI,CAAC,OA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