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

fix: url generation handling of all types #104

Merged
merged 1 commit into from
Jul 13, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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