From 2bdc2f2d9784b8d79ad61a640eca3e5e3381b601 Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Sun, 3 Mar 2024 15:15:29 +0900 Subject: [PATCH 1/6] get user list that are in discussions --- src/main.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main.ts b/src/main.ts index 7408a83..a9d1e3c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,21 @@ import * as core from '@actions/core' import { getOctokit, context } from '@actions/github' +const uniqueStringArray = (texts: string[]) => { + if (texts.length === 0) return [] + + const sorted = texts.sort() + const result = [sorted[0]] + + for (let i = 0; i < sorted.length - 1; i++) { + if (sorted[i + 1] !== sorted[i]) { + result.push(sorted[i + 1]) + } + } + + return result +} + /** * The main function for the action. * @returns {Promise} Resolves when the action is complete. @@ -38,6 +53,13 @@ export async function run(): Promise { }) ).data + const userLogins = uniqueStringArray( + comments + .map(comment => comment.user?.login) + .concat(reviewComments.map(comment => comment.user.login)) + .filter((comment): comment is string => !!comment) + ) + await octokit.rest.issues.createComment({ owner, repo, From da0f61b41d5d3003efead96aeaf0b2d298a36660 Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Sun, 3 Mar 2024 15:16:12 +0900 Subject: [PATCH 2/6] fix comment --- src/main.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index a9d1e3c..f7481c9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -64,10 +64,11 @@ export async function run(): Promise { owner, repo, issue_number: prNumber, - body: ` + body: `Hey ${userLogins.map(login => '@' + login).join(', ')}! -the number of the comments is ${comments.length} -the number of the review comments is ${reviewComments.length}` +It seems the discussion is dragging on. Perhaps instead of text communication, you could try having a conversation via face-to-face or video call, or even try mob programming? + +the number of the comments is ${comments.length} and the review comments is ${reviewComments.length}` }) core.debug(`Commented on PR #${prNumber}`) } catch (error) { From 1a19676322c47f167d82cdb7172c65ad655fe8fe Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Sun, 3 Mar 2024 15:16:32 +0900 Subject: [PATCH 3/6] pnpm bundle --- dist/index.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index c9bf9ad..1ed436d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29008,6 +29008,18 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.run = void 0; const core = __importStar(__nccwpck_require__(9093)); const github_1 = __nccwpck_require__(5942); +const uniqueStringArray = (texts) => { + if (texts.length === 0) + return []; + const sorted = texts.sort(); + const result = [sorted[0]]; + for (let i = 0; i < sorted.length - 1; i++) { + if (sorted[i + 1] !== sorted[i]) { + result.push(sorted[i + 1]); + } + } + return result; +}; /** * The main function for the action. * @returns {Promise} Resolves when the action is complete. @@ -29035,14 +29047,19 @@ async function run() { repo, pull_number: prNumber })).data; + const userLogins = uniqueStringArray(comments + .map(comment => comment.user?.login) + .concat(reviewComments.map(comment => comment.user.login)) + .filter((comment) => !!comment)); await octokit.rest.issues.createComment({ owner, repo, issue_number: prNumber, - body: ` + body: `Hey ${userLogins.map(login => '@' + login).join(', ')}! + +It seems the discussion is dragging on. Perhaps instead of text communication, you could try having a conversation via face-to-face or video call, or even try mob programming? -the number of the comments is ${comments.length} -the number of the review comments is ${reviewComments.length}` +the number of the comments is ${comments.length} and the review comments is ${reviewComments.length}` }); core.debug(`Commented on PR #${prNumber}`); } From 29c125a38c00d4708f4142748e0aa5d2ae5a1175 Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Sun, 3 Mar 2024 15:19:21 +0900 Subject: [PATCH 4/6] add type annotation --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index f7481c9..3783a44 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,7 @@ import * as core from '@actions/core' import { getOctokit, context } from '@actions/github' -const uniqueStringArray = (texts: string[]) => { +const uniqueStringArray = (texts: string[]): string[] => { if (texts.length === 0) return [] const sorted = texts.sort() From 8a9c34b595e3df31b80f42eb77c7b53680097fc4 Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Sun, 3 Mar 2024 15:22:33 +0900 Subject: [PATCH 5/6] fix --- dist/index.js | 4 ++-- src/main.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 1ed436d..bbf53a2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29050,12 +29050,12 @@ async function run() { const userLogins = uniqueStringArray(comments .map(comment => comment.user?.login) .concat(reviewComments.map(comment => comment.user.login)) - .filter((comment) => !!comment)); + .filter((comment) => !!comment)).map(login => `@${login}`); await octokit.rest.issues.createComment({ owner, repo, issue_number: prNumber, - body: `Hey ${userLogins.map(login => '@' + login).join(', ')}! + body: `Hey ${userLogins.join(', ')}! It seems the discussion is dragging on. Perhaps instead of text communication, you could try having a conversation via face-to-face or video call, or even try mob programming? diff --git a/src/main.ts b/src/main.ts index 3783a44..2ef313d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -58,13 +58,13 @@ export async function run(): Promise { .map(comment => comment.user?.login) .concat(reviewComments.map(comment => comment.user.login)) .filter((comment): comment is string => !!comment) - ) + ).map(login => `@${login}`) await octokit.rest.issues.createComment({ owner, repo, issue_number: prNumber, - body: `Hey ${userLogins.map(login => '@' + login).join(', ')}! + body: `Hey ${userLogins.join(', ')}! It seems the discussion is dragging on. Perhaps instead of text communication, you could try having a conversation via face-to-face or video call, or even try mob programming? From dafdcecbd8fb8536c7141265e40410841e6a34a7 Mon Sep 17 00:00:00 2001 From: Tomoya Kashifuku Date: Sun, 3 Mar 2024 15:28:32 +0900 Subject: [PATCH 6/6] fix filter --- dist/index.js | 4 ++-- src/main.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index bbf53a2..b2f2639 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29041,12 +29041,12 @@ async function run() { owner, repo, issue_number: prNumber - })).data.filter(c => c.user?.type === 'Bot'); + })).data.filter(c => c.user?.type !== 'Bot'); const reviewComments = (await octokit.rest.pulls.listReviewComments({ owner, repo, pull_number: prNumber - })).data; + })).data.filter(c => c.user.type !== 'Bot'); const userLogins = uniqueStringArray(comments .map(comment => comment.user?.login) .concat(reviewComments.map(comment => comment.user.login)) diff --git a/src/main.ts b/src/main.ts index 2ef313d..b0ea662 100644 --- a/src/main.ts +++ b/src/main.ts @@ -43,7 +43,7 @@ export async function run(): Promise { repo, issue_number: prNumber }) - ).data.filter(c => c.user?.type === 'Bot') + ).data.filter(c => c.user?.type !== 'Bot') const reviewComments = ( await octokit.rest.pulls.listReviewComments({ @@ -51,7 +51,7 @@ export async function run(): Promise { repo, pull_number: prNumber }) - ).data + ).data.filter(c => c.user.type !== 'Bot') const userLogins = uniqueStringArray( comments