Skip to content

Commit 82bbfa9

Browse files
committed
feat: added prefix_path input that can be used to add a prefix to each filename in the cobertura report
1 parent f25a8a0 commit 82bbfa9

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ artifacts to circumvent this. See the workflows in this project for an implement
2020

2121
A comment is added to the pull request with the coverage report.
2222

23-
![alt text](img/comment.png "Pull request comment with metrics")
23+
![alt text](img/comment.png 'Pull request comment with metrics')
2424

2525
A check is added to the workflow run.
2626

27-
![alt text](img/check.png "Check with metrics")
27+
![alt text](img/check.png 'Check with metrics')
2828

2929
The check will succeed or fail based on your threshold when `fail_below_threshold` is set to `true`, this allows you to mandate coverage checks pass on your [protected branches](https://docs.github.com/en/github/administering-a-repository/defining-the-mergeability-of-pull-requests/about-protected-branches).
3030

@@ -38,6 +38,10 @@ The GITHUB_TOKEN. Defaults to `${{github.token}}`
3838

3939
The path to the cobertura report. Defaults to `coverage.xml`. Glob pattern is supported, for example `coverage/*.xml`.
4040

41+
## `prefix_path`
42+
43+
This prefix is added to every `filename` within the cobertura report. This can resolve issues with `link_missing_lines` URLs and `only_changed_files`.
44+
4145
### `skip_covered`
4246

4347
If files with 100% coverage should be ignored. Defaults to `true`.

action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ inputs:
99
description: 'Path to the cobertura file.'
1010
required: true
1111
default: 'coverage.xml'
12+
prefix_path:
13+
description: 'Prefix path to add to each filename.'
14+
required: false
15+
default: ''
1216
skip_covered:
1317
description: 'If files with 100% should be skipped from report.'
1418
required: true
@@ -44,6 +48,11 @@ inputs:
4448
description: 'Link missing line numbers.'
4549
required: false
4650
default: false
51+
link_missing_lines_source_dir:
52+
description: 'Source directory used for link_missing_lines.'
53+
required: false
54+
default: ''
55+
deprecationMessage: 'Please switch to prefix_path instead (this input is forward to prefix_path).'
4756
only_changed_files:
4857
description: 'Only show coverage for changed files. (only if a PR is present)'
4958
required: true

src/action.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async function action(payload) {
1616
}
1717

1818
const path = core.getInput("path", { required: true });
19+
const prefixPath = core.getInput("prefix_path", { required: false });
1920
const skipCovered = JSON.parse(
2021
core.getInput("skip_covered", { required: true })
2122
);
@@ -53,7 +54,7 @@ async function action(payload) {
5354
? await listChangedFiles(pullRequestNumber)
5455
: null;
5556

56-
const reports = await processCoverage(path, { skipCovered });
57+
const reports = await processCoverage(path, { skipCovered, prefixPath });
5758
const comment = markdownReport(reports, commit, {
5859
minimumCoverage,
5960
showLine,

src/cobertura.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function readCoverageFromFile(path, options) {
2424
.map((klass) => {
2525
return {
2626
...calculateRates(klass),
27-
filename: klass["filename"],
27+
filename: (options.prefixPath || "") + klass["filename"],
2828
name: klass["name"],
2929
missing: missingLines(klass),
3030
};

src/cobertura.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,13 @@ test("longestCommonPrefix", () => {
271271
expect(longestCommonPrefix(null)).toBe(0);
272272
expect(longestCommonPrefix([])).toBe(0);
273273
});
274+
275+
test("processCoverage(test-prefix.xml, {prefixPath: 'somethingrandom/'})", async () => {
276+
const reports = await processCoverage("./src/fixtures/test-istanbul.xml", {
277+
prefixPath: "somethingrandom/",
278+
skipCovered: false,
279+
});
280+
281+
const files = reports[0].files;
282+
expect(files[0].filename).toBe("somethingrandom/src/action.js");
283+
});

0 commit comments

Comments
 (0)