From 5a7694485ad10e53d469e948443bd57b9719e9ef Mon Sep 17 00:00:00 2001 From: tuunit Date: Sat, 3 Jun 2023 21:51:16 +0200 Subject: [PATCH] feat: add direct urls for comments - add direct urls for comments and replace custom url handling with html_url property provided by github api - remove redundant else branches - separate into if blocks for better readability - remove unnecessary constant for github base url Co-authored-by: James George --- dist/index.js | 21 ++++++++++++++------- index.js | 21 ++++++++++++++------- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8c9fc9c..8dfe05d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1804,8 +1804,6 @@ 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 @@ -1814,12 +1812,21 @@ const urlPrefix = "https://github.com"; */ 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})`; } - return `[${item}](${urlPrefix}/${item})`; }; /** diff --git a/index.js b/index.js index 6b63690..7046fcb 100644 --- a/index.js +++ b/index.js @@ -21,8 +21,6 @@ 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 @@ -31,12 +29,21 @@ const urlPrefix = "https://github.com"; */ 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})`; } - return `[${item}](${urlPrefix}/${item})`; }; /** diff --git a/package-lock.json b/package-lock.json index 42f4f50..2cafb5e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "github-activity-readme", - "version": "0.4.0", + "version": "0.5.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "github-activity-readme", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "dependencies": { "@actions/core": "^1.2.6", diff --git a/package.json b/package.json index 2c05738..29ed4c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "github-activity-readme", - "version": "0.4.0", + "version": "0.5.0", "description": "Updates README with the recent GitHub activity of a user", "main": "index.js", "keywords": [],