From b4a7c9d9ea12d2dd10d76b560a52269f44f21c1c Mon Sep 17 00:00:00 2001 From: James Champ Date: Tue, 30 Jan 2024 14:08:49 -0800 Subject: [PATCH 1/2] Fix bugs --- scripts/gh_scripts/auto_unassigner.mjs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/gh_scripts/auto_unassigner.mjs b/scripts/gh_scripts/auto_unassigner.mjs index 6b582b185d5..3d7ffebf2f8 100644 --- a/scripts/gh_scripts/auto_unassigner.mjs +++ b/scripts/gh_scripts/auto_unassigner.mjs @@ -92,7 +92,7 @@ async function main() { // XXX : Inject octokit for easier testing const actionableIssues = await filterIssues(issues, filters) console.log(`Issues remaining after filtering: ${actionableIssues.length}`) - const digestPublished = await postSlackDigest(issues) + const digestPublished = await postSlackDigest(actionableIssues) if (!digestPublished) { console.log('Something went wrong while publishing the digest to Slack...') @@ -203,18 +203,21 @@ async function postSlackDigest(issues) { const slackChannel = process.env.SLACK_CHANNEL if (!(slackToken && slackChannel)) { - console.log('Digest could not be published to Slack.') + console.log('Digest could not be published to Slack due to missing environment variables.') return false } const parentThreadMessage = `${issues.length} issue(s) have stale assignees.` - fetch('https://slack.com.api/chat.postMessage', { + fetch('https://slack.com/api/chat.postMessage', { method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8', 'Authorization': `Bearer ${slackToken}` }, - body: JSON.stringify(parentThreadMessage) + body: JSON.stringify({ + text: parentThreadMessage, + channel: process.env.SLACK_CHANNEL + }) }) .then((resp) => { if (!resp.ok) { @@ -227,7 +230,7 @@ async function postSlackDigest(issues) { const ts = data['ts'] for (const issue of issues) { - const message = `<${issue.comment_url}|${issue_title}>` + const message = `<${issue.html_url}|${issue.title}>` // Wait for one second... await wait(1000) // ...then POST again @@ -252,7 +255,7 @@ async function postSlackDigest(issues) { channel: slackChannel } - await fetch('https://slack.com.api/chat.postMessage', { + await fetch('https://slack.com/api/chat.postMessage', { method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8', From 3be947c2b55d01c1b78b482d8f923fe28b91b3e7 Mon Sep 17 00:00:00 2001 From: James Champ Date: Tue, 30 Jan 2024 14:14:26 -0800 Subject: [PATCH 2/2] Prevent assigning secrets to variables --- scripts/gh_scripts/auto_unassigner.mjs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/gh_scripts/auto_unassigner.mjs b/scripts/gh_scripts/auto_unassigner.mjs index 3d7ffebf2f8..30192f1c704 100644 --- a/scripts/gh_scripts/auto_unassigner.mjs +++ b/scripts/gh_scripts/auto_unassigner.mjs @@ -199,10 +199,7 @@ async function getTimeline(issue) { * @returns {Promise} */ async function postSlackDigest(issues) { - const slackToken = process.env.SLACK_TOKEN - const slackChannel = process.env.SLACK_CHANNEL - - if (!(slackToken && slackChannel)) { + if (!(process.env.SLACK_TOKEN && process.env.SLACK_CHANNEL)) { console.log('Digest could not be published to Slack due to missing environment variables.') return false } @@ -212,7 +209,7 @@ async function postSlackDigest(issues) { method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8', - 'Authorization': `Bearer ${slackToken}` + 'Authorization': `Bearer ${process.env.SLACK_TOKEN}` }, body: JSON.stringify({ text: parentThreadMessage, @@ -252,14 +249,14 @@ async function postSlackDigest(issues) { const body = { text: message, thread_ts: ts, - channel: slackChannel + channel: process.env.SLACK_CHANNEL } await fetch('https://slack.com/api/chat.postMessage', { method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8', - 'Authorization': `Bearer ${slackToken}` + 'Authorization': `Bearer ${process.env.SLACK_TOKEN}` }, body: JSON.stringify(body) })