Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use context repo html_url as base for links if available #101

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions dist/index.js
Expand Up @@ -17168,7 +17168,7 @@ const toHtml = (data, options, dataFromXml = null) => {
const total = dataFromXml ? dataFromXml.total : getTotal(data);
const color = getCoverageColor(total.cover);
const onlyChnaged = reportOnlyChangedFiles ? '• ' : '';
const readmeHref = `https://github.com/${options.repository}/blob/${options.commit}/README.md`;
const readmeHref = `${options.repoUrl}/blob/${options.commit}/README.md`;
const badge = `<img alt="${badgeTitle}" src="https://img.shields.io/badge/${badgeTitle}-${total.cover}25-${color}.svg" />`;
const badgeWithLink = removeLinkFromBadge
? badge
Expand Down Expand Up @@ -17266,7 +17266,7 @@ const toTotalRow = (item, options) => {
// make fileName cell - td
const toFileNameTd = (item, indent = false, options) => {
const relative = item.name.replace(options.prefix, '');
const href = `https://github.com/${options.repository}/blob/${options.commit}/${options.pathPrefix}${relative}`;
const href = `${options.repoUrl}/blob/${options.commit}/${options.pathPrefix}${relative}`;
const parts = relative.split('/');
const last = parts[parts.length - 1];
const space = indent ? '&nbsp; &nbsp;' : '';
Expand Down Expand Up @@ -17295,7 +17295,7 @@ const toMissingTd = (item, options) => {
const [start, end = start] = range.split('-');
const fragment = start === end ? `L${start}` : `L${start}-L${end}`;
const relative = item.name;
const href = `https://github.com/${options.repository}/blob/${options.commit}/${options.pathPrefix}${relative}#${fragment}`;
const href = `${options.repoUrl}/blob/${options.commit}/${options.pathPrefix}${relative}#${fragment}`;
const text = start === end ? start : `${start}&ndash;${end}`;

return `<a href="${href}">${text}</a>`;
Expand Down Expand Up @@ -17866,6 +17866,8 @@ const main = async () => {
xmlTitle,
multipleFiles,
};
options.repoUrl =
payload.repository?.html_url || `https://github.com/${options.repository}`;

if (eventName === 'pull_request') {
options.commit = payload.pull_request.head.sha;
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Expand Up @@ -77,6 +77,8 @@ const main = async () => {
xmlTitle,
multipleFiles,
};
options.repoUrl =
payload.repository?.html_url || `https://github.com/${options.repository}`;

if (eventName === 'pull_request') {
options.commit = payload.pull_request.head.sha;
Expand Down
6 changes: 3 additions & 3 deletions src/parse.js
Expand Up @@ -194,7 +194,7 @@ const toHtml = (data, options, dataFromXml = null) => {
const total = dataFromXml ? dataFromXml.total : getTotal(data);
const color = getCoverageColor(total.cover);
const onlyChnaged = reportOnlyChangedFiles ? '• ' : '';
const readmeHref = `https://github.com/${options.repository}/blob/${options.commit}/README.md`;
const readmeHref = `${options.repoUrl}/blob/${options.commit}/README.md`;
const badge = `<img alt="${badgeTitle}" src="https://img.shields.io/badge/${badgeTitle}-${total.cover}25-${color}.svg" />`;
const badgeWithLink = removeLinkFromBadge
? badge
Expand Down Expand Up @@ -292,7 +292,7 @@ const toTotalRow = (item, options) => {
// make fileName cell - td
const toFileNameTd = (item, indent = false, options) => {
const relative = item.name.replace(options.prefix, '');
const href = `https://github.com/${options.repository}/blob/${options.commit}/${options.pathPrefix}${relative}`;
const href = `${options.repoUrl}/blob/${options.commit}/${options.pathPrefix}${relative}`;
const parts = relative.split('/');
const last = parts[parts.length - 1];
const space = indent ? '&nbsp; &nbsp;' : '';
Expand Down Expand Up @@ -321,7 +321,7 @@ const toMissingTd = (item, options) => {
const [start, end = start] = range.split('-');
const fragment = start === end ? `L${start}` : `L${start}-L${end}`;
const relative = item.name;
const href = `https://github.com/${options.repository}/blob/${options.commit}/${options.pathPrefix}${relative}#${fragment}`;
const href = `${options.repoUrl}/blob/${options.commit}/${options.pathPrefix}${relative}#${fragment}`;
const text = start === end ? start : `${start}&ndash;${end}`;

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