Skip to content

Commit

Permalink
bugfix: url generation handling of all types (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuunit committed Jul 13, 2023
1 parent 015e230 commit 0cb0dd9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
28 changes: 17 additions & 11 deletions dist/index.js
Expand Up @@ -1804,22 +1804,30 @@ const TARGET_FILE = core.getInput("TARGET_FILE");

const capitalize = (str) => str.slice(0, 1).toUpperCase() + str.slice(1);

const urlPrefix = "https://github.com";

/**
* Returns a URL in markdown format for PR's and issues
* @param {Object | String} item - holds information concerning the issue/PR
*
* @returns {String}
*/

const toUrlFormat = (item) => {
if (typeof item === "object") {
return Object.hasOwnProperty.call(item.payload, "issue")
? `[#${item.payload.issue.number}](${urlPrefix}/${item.repo.name}/issues/${item.payload.issue.number})`
: `[#${item.payload.pull_request.number}](${urlPrefix}/${item.repo.name}/pull/${item.payload.pull_request.number})`;
if (typeof item !== "object") {
return `[${item}](https://github.com/${item})`;
}
if (Object.hasOwnProperty.call(item.payload, "comment")) {
return `[#${item.payload.issue.number}](${item.payload.comment.html_url})`;
}
if (Object.hasOwnProperty.call(item.payload, "issue")) {
return `[#${item.payload.issue.number}](${item.payload.issue.html_url})`;
}
if (Object.hasOwnProperty.call(item.payload, "pull_request")) {
return `[#${item.payload.pull_request.number}](${item.payload.pull_request.html_url})`;
}

if (Object.hasOwnProperty.call(item.payload, "release")) {
const release = item.payload.release.name || item.payload.release.tag_name;
return `[${release}](${item.payload.release.html_url})`;
}
return `[${item}](${urlPrefix}/${item})`;
};

/**
Expand Down Expand Up @@ -1883,9 +1891,7 @@ const serializers = {
},
ReleaseEvent: (item) => {
return `🚀 ${capitalize(item.payload.action)} release ${toUrlFormat(
item.payload.release.name
? item.payload.release.name
: item.payload.release.tag_name
item
)} in ${toUrlFormat(item.repo.name)}`;
},
};
Expand Down
28 changes: 17 additions & 11 deletions index.js
Expand Up @@ -21,22 +21,30 @@ const TARGET_FILE = core.getInput("TARGET_FILE");

const capitalize = (str) => str.slice(0, 1).toUpperCase() + str.slice(1);

const urlPrefix = "https://github.com";

/**
* Returns a URL in markdown format for PR's and issues
* @param {Object | String} item - holds information concerning the issue/PR
*
* @returns {String}
*/

const toUrlFormat = (item) => {
if (typeof item === "object") {
return Object.hasOwnProperty.call(item.payload, "issue")
? `[#${item.payload.issue.number}](${urlPrefix}/${item.repo.name}/issues/${item.payload.issue.number})`
: `[#${item.payload.pull_request.number}](${urlPrefix}/${item.repo.name}/pull/${item.payload.pull_request.number})`;
if (typeof item !== "object") {
return `[${item}](https://github.com/${item})`;
}
if (Object.hasOwnProperty.call(item.payload, "comment")) {
return `[#${item.payload.issue.number}](${item.payload.comment.html_url})`;
}
if (Object.hasOwnProperty.call(item.payload, "issue")) {
return `[#${item.payload.issue.number}](${item.payload.issue.html_url})`;
}
if (Object.hasOwnProperty.call(item.payload, "pull_request")) {
return `[#${item.payload.pull_request.number}](${item.payload.pull_request.html_url})`;
}

if (Object.hasOwnProperty.call(item.payload, "release")) {
const release = item.payload.release.name || item.payload.release.tag_name;
return `[${release}](${item.payload.release.html_url})`;
}
return `[${item}](${urlPrefix}/${item})`;
};

/**
Expand Down Expand Up @@ -100,9 +108,7 @@ const serializers = {
},
ReleaseEvent: (item) => {
return `🚀 ${capitalize(item.payload.action)} release ${toUrlFormat(
item.payload.release.name
? item.payload.release.name
: item.payload.release.tag_name
item
)} in ${toUrlFormat(item.repo.name)}`;
},
};
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "github-activity-readme",
"version": "0.4.0",
"version": "0.4.1",
"description": "Updates README with the recent GitHub activity of a user",
"main": "index.js",
"keywords": [],
Expand Down

0 comments on commit 0cb0dd9

Please sign in to comment.