Skip to content

Commit 0cb0dd9

Browse files
authored
bugfix: url generation handling of all types (#104)
1 parent 015e230 commit 0cb0dd9

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

dist/index.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,22 +1804,30 @@ const TARGET_FILE = core.getInput("TARGET_FILE");
18041804

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

1807-
const urlPrefix = "https://github.com";
1808-
18091807
/**
18101808
* Returns a URL in markdown format for PR's and issues
18111809
* @param {Object | String} item - holds information concerning the issue/PR
18121810
*
18131811
* @returns {String}
18141812
*/
1815-
18161813
const toUrlFormat = (item) => {
1817-
if (typeof item === "object") {
1818-
return Object.hasOwnProperty.call(item.payload, "issue")
1819-
? `[#${item.payload.issue.number}](${urlPrefix}/${item.repo.name}/issues/${item.payload.issue.number})`
1820-
: `[#${item.payload.pull_request.number}](${urlPrefix}/${item.repo.name}/pull/${item.payload.pull_request.number})`;
1814+
if (typeof item !== "object") {
1815+
return `[${item}](https://github.com/${item})`;
1816+
}
1817+
if (Object.hasOwnProperty.call(item.payload, "comment")) {
1818+
return `[#${item.payload.issue.number}](${item.payload.comment.html_url})`;
1819+
}
1820+
if (Object.hasOwnProperty.call(item.payload, "issue")) {
1821+
return `[#${item.payload.issue.number}](${item.payload.issue.html_url})`;
1822+
}
1823+
if (Object.hasOwnProperty.call(item.payload, "pull_request")) {
1824+
return `[#${item.payload.pull_request.number}](${item.payload.pull_request.html_url})`;
1825+
}
1826+
1827+
if (Object.hasOwnProperty.call(item.payload, "release")) {
1828+
const release = item.payload.release.name || item.payload.release.tag_name;
1829+
return `[${release}](${item.payload.release.html_url})`;
18211830
}
1822-
return `[${item}](${urlPrefix}/${item})`;
18231831
};
18241832

18251833
/**
@@ -1883,9 +1891,7 @@ const serializers = {
18831891
},
18841892
ReleaseEvent: (item) => {
18851893
return `🚀 ${capitalize(item.payload.action)} release ${toUrlFormat(
1886-
item.payload.release.name
1887-
? item.payload.release.name
1888-
: item.payload.release.tag_name
1894+
item
18891895
)} in ${toUrlFormat(item.repo.name)}`;
18901896
},
18911897
};

index.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,30 @@ const TARGET_FILE = core.getInput("TARGET_FILE");
2121

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

24-
const urlPrefix = "https://github.com";
25-
2624
/**
2725
* Returns a URL in markdown format for PR's and issues
2826
* @param {Object | String} item - holds information concerning the issue/PR
2927
*
3028
* @returns {String}
3129
*/
32-
3330
const toUrlFormat = (item) => {
34-
if (typeof item === "object") {
35-
return Object.hasOwnProperty.call(item.payload, "issue")
36-
? `[#${item.payload.issue.number}](${urlPrefix}/${item.repo.name}/issues/${item.payload.issue.number})`
37-
: `[#${item.payload.pull_request.number}](${urlPrefix}/${item.repo.name}/pull/${item.payload.pull_request.number})`;
31+
if (typeof item !== "object") {
32+
return `[${item}](https://github.com/${item})`;
33+
}
34+
if (Object.hasOwnProperty.call(item.payload, "comment")) {
35+
return `[#${item.payload.issue.number}](${item.payload.comment.html_url})`;
36+
}
37+
if (Object.hasOwnProperty.call(item.payload, "issue")) {
38+
return `[#${item.payload.issue.number}](${item.payload.issue.html_url})`;
39+
}
40+
if (Object.hasOwnProperty.call(item.payload, "pull_request")) {
41+
return `[#${item.payload.pull_request.number}](${item.payload.pull_request.html_url})`;
42+
}
43+
44+
if (Object.hasOwnProperty.call(item.payload, "release")) {
45+
const release = item.payload.release.name || item.payload.release.tag_name;
46+
return `[${release}](${item.payload.release.html_url})`;
3847
}
39-
return `[${item}](${urlPrefix}/${item})`;
4048
};
4149

4250
/**
@@ -100,9 +108,7 @@ const serializers = {
100108
},
101109
ReleaseEvent: (item) => {
102110
return `🚀 ${capitalize(item.payload.action)} release ${toUrlFormat(
103-
item.payload.release.name
104-
? item.payload.release.name
105-
: item.payload.release.tag_name
111+
item
106112
)} in ${toUrlFormat(item.repo.name)}`;
107113
},
108114
};

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": "github-activity-readme",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "Updates README with the recent GitHub activity of a user",
55
"main": "index.js",
66
"keywords": [],

0 commit comments

Comments
 (0)