Skip to content

Commit 03b8cb1

Browse files
authored
Links in comment (#52)
* add pathPrefix * 1.1.21 * fix pax for line
1 parent 2bc9016 commit 03b8cb1

File tree

8 files changed

+18
-7
lines changed

8 files changed

+18
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ You can add this action to your GitHub workflow for Ubuntu runners (e.g. runs-on
2424
| --------------------------- | -------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
2525
| `github-token` | ✓ | `${{github.token}}` | An alternative GitHub token, other than the default provided by GitHub Actions runner |
2626
| `pytest-coverage-path` | | `./pytest-coverage.txt` | The location of the txt output of pytest-coverage. Used to generate the comment |
27+
| `coverage-path-prefix` | | '' | Prefix for path when link to files in comment |
2728
| `title` | | `Coverage Report` | Title for the coverage report. Useful for monorepo projects |
2829
| `badge-title` | | `Coverage` | Title for the badge icon |
2930
| `hide-badge` | | false | Hide badge with percentage |

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ inputs:
1616
default: './pytest-coverage.txt'
1717
required: false
1818

19+
coverage-path-prefix:
20+
description: 'Prefix for path when link to files in comment'
21+
default: ''
22+
required: false
23+
1924
title:
2025
description: 'Title for the coverage report. Useful for monorepo projects'
2126
default: 'Coverage Report'

dist/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15542,7 +15542,7 @@ const toTotalRow = (item, options) => {
1554215542
// make fileName cell - td
1554315543
const toFileNameTd = (item, indent = false, options) => {
1554415544
const relative = item.name.replace(options.prefix, '');
15545-
const href = `https://github.com/${options.repository}/blob/${options.commit}/${relative}`;
15545+
const href = `https://github.com/${options.repository}/blob/${options.commit}/${options.pathPrefix}${relative}`;
1554615546
const parts = relative.split('/');
1554715547
const last = parts[parts.length - 1];
1554815548
const space = indent ? '   ' : '';
@@ -15571,7 +15571,7 @@ const toMissingTd = (item, options) => {
1557115571
const [start, end = start] = range.split('-');
1557215572
const fragment = start === end ? `L${start}` : `L${start}-L${end}`;
1557315573
const relative = item.name;
15574-
const href = `https://github.com/${options.repository}/blob/${options.commit}/${relative}#${fragment}`;
15574+
const href = `https://github.com/${options.repository}/blob/${options.commit}/${options.pathPrefix}${relative}#${fragment}`;
1557515575
const text = start === end ? start : `${start}–${end}`;
1557615576

1557715577
return `<a href="${href}">${text}</a>`;
@@ -15848,6 +15848,7 @@ const main = async () => {
1584815848
);
1584915849
const defaultBranch = core.getInput('default-branch', { required: false });
1585015850
const covFile = core.getInput('pytest-coverage-path', { required: false });
15851+
const pathPrefix = core.getInput('coverage-path-prefix', { required: false });
1585115852
const xmlFile = core.getInput('junitxml-path', { required: false });
1585215853
const xmlTitle = core.getInput('junitxml-title', { required: false });
1585315854
const multipleFiles = core.getMultilineInput('multiple-files', {
@@ -15863,6 +15864,7 @@ const main = async () => {
1586315864
token,
1586415865
repository: repository || `${owner}/${repo}`,
1586515866
prefix: `${process.env.GITHUB_WORKSPACE}/`,
15867+
pathPrefix,
1586615868
covFile,
1586715869
xmlFile,
1586815870
title,

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pytest-coverage-comment",
3-
"version": "1.1.20",
3+
"version": "1.1.21",
44
"description": "Comments a pull request with the pytest code coverage badge, full report and tests summary",
55
"author": "Misha Kav",
66
"license": "MIT",

src/cli.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const main = async () => {
5050
repository: 'MishaKav/pytest-coverage-comment',
5151
commit: 'f9d42291812ed03bb197e48050ac38ac6befe4e5',
5252
prefix,
53+
pathPrefix: '',
5354
covFile: getPathToFile(covFile),
5455
xmlFile: getPathToFile(xmlFile),
5556
defaultBranch: 'main',

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const main = async () => {
3232
);
3333
const defaultBranch = core.getInput('default-branch', { required: false });
3434
const covFile = core.getInput('pytest-coverage-path', { required: false });
35+
const pathPrefix = core.getInput('coverage-path-prefix', { required: false });
3536
const xmlFile = core.getInput('junitxml-path', { required: false });
3637
const xmlTitle = core.getInput('junitxml-title', { required: false });
3738
const multipleFiles = core.getMultilineInput('multiple-files', {
@@ -47,6 +48,7 @@ const main = async () => {
4748
token,
4849
repository: repository || `${owner}/${repo}`,
4950
prefix: `${process.env.GITHUB_WORKSPACE}/`,
51+
pathPrefix,
5052
covFile,
5153
xmlFile,
5254
title,

src/parse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ const toTotalRow = (item, options) => {
297297
// make fileName cell - td
298298
const toFileNameTd = (item, indent = false, options) => {
299299
const relative = item.name.replace(options.prefix, '');
300-
const href = `https://github.com/${options.repository}/blob/${options.commit}/${relative}`;
300+
const href = `https://github.com/${options.repository}/blob/${options.commit}/${options.pathPrefix}${relative}`;
301301
const parts = relative.split('/');
302302
const last = parts[parts.length - 1];
303303
const space = indent ? '&nbsp; &nbsp;' : '';
@@ -326,7 +326,7 @@ const toMissingTd = (item, options) => {
326326
const [start, end = start] = range.split('-');
327327
const fragment = start === end ? `L${start}` : `L${start}-L${end}`;
328328
const relative = item.name;
329-
const href = `https://github.com/${options.repository}/blob/${options.commit}/${relative}#${fragment}`;
329+
const href = `https://github.com/${options.repository}/blob/${options.commit}/${options.pathPrefix}${relative}#${fragment}`;
330330
const text = start === end ? start : `${start}&ndash;${end}`;
331331

332332
return `<a href="${href}">${text}</a>`;

0 commit comments

Comments
 (0)