From c95f427131cf3c531e00a9f2194f9a64855a02a0 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Thu, 26 Jun 2025 03:03:05 +0530 Subject: [PATCH 01/33] updated notify team new comment workflow --- .github/workflows/notify_team_new_comment.yml | 68 +++++++++++-- scripts/keywords.txt | 98 +++++++++++++++++++ scripts/notify_team_new_comment.js | 85 ++++++++++++++++ 3 files changed, 243 insertions(+), 8 deletions(-) create mode 100644 scripts/keywords.txt create mode 100644 scripts/notify_team_new_comment.js diff --git a/.github/workflows/notify_team_new_comment.yml b/.github/workflows/notify_team_new_comment.yml index 6bf8a32..4fd638a 100644 --- a/.github/workflows/notify_team_new_comment.yml +++ b/.github/workflows/notify_team_new_comment.yml @@ -3,8 +3,19 @@ name: Send a slack notification when a contributor comments on issue on: workflow_call: secrets: + APP_ID: + required: true + description: The ID of the GitHub App. + APP_PRIVATE_KEY: + required: true + description: The private key of the GitHub App. SLACK_WEBHOOK_URL: required: true + description: Webhook URL for the Slack support-dev channel where notifications should be sent. + SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL: + required: true + description: Webhook URL for the Slack support-dev-notifications channel where notifications should be sent. + jobs: contributor_issue_comment: @@ -21,17 +32,58 @@ jobs: runs-on: ubuntu-latest steps: - - name: Escape title double quotes - id: escape_title + - name: Generate App Token + id: generate-token + uses: tibdex/github-app-token@v2 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + + - name: Checkout called repository + uses: actions/checkout@v4 + with: + repository: testiamshobh/.github + ref: main + token: ${{ steps.generate-token.outputs.token }} + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '16' + + - name: Install dependancies + run: npm install + + - name: Run check script + id: check + uses: actions/github-script@v7 + with: + github-token: ${{ steps.generate-token.outputs.token }} + script: | + const script = require('./scripts/notify_team_new_comment.js'); + return await script({github, context, core}); env: - ISSUE_TITLE: ${{ github.event.issue.title }} - run: echo "ISSUE_TITLE=${ISSUE_TITLE//\"/\\\"}" >> "$GITHUB_OUTPUT" + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL: ${{ secrets.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL }} - name: Send message to Slack channel - uses: slackapi/slack-github-action@v2.0.0 + uses: slackapi/slack-github-action@v2.1.0 + with: + webhook-type: incoming-webhook + webhook: ${{ steps.check.outputs.webhook_url }} + payload: > + { + "text": "${{ steps.check.outputs.text }}" + } + + - name: Send bot message to Slack channel + if: ${{ steps.check.outputs.bot_replied }} + uses: slackapi/slack-github-action@v2.1.0 with: - webhook: ${{ secrets.SLACK_WEBHOOK_URL }} webhook-type: incoming-webhook - payload: | - text: "*[${{ github.event.repository.name }}] New comment on issue: <${{ github.event.issue.html_url }}#issuecomment-${{ github.event.comment.id }}|${{ steps.escape_title.outputs.ISSUE_TITLE }} by ${{ github.event.comment.user.login }}>*" + webhook: ${{ steps.check.outputs.webhook_url }} + payload: > + { + "text": "${{ steps.check.outputs.bot_reply_message }}" + } diff --git a/scripts/keywords.txt b/scripts/keywords.txt new file mode 100644 index 0000000..aad9609 --- /dev/null +++ b/scripts/keywords.txt @@ -0,0 +1,98 @@ +assign +assign me +please assign +assign to me +assign this +claim +claim this +i claim this +i’ll take this +take this +taking this +taken +i want this +mine +dibs +this is mine +i’ll do this +i’ll take care +let me take this +can i take this +can i work on this +can i help +can help +let me help +i want to help +want to help +working on this +i’m on it +i’ll work on it +i want to work +want this +i can do this +can do this +i can solve this +can solve this +let me try +i’ll try +i’ll try this +trying this +i’ll pick this +pick this +picking this +want to pick +grab this +grabbing this +i’m interested +interested +i want in +count me in +i’m doing this +doing now +will do +i’ll handle this +let me handle +let me solve +solve this +want to solve +taking charge +let me take care +taking it +bagging this +need this +can i own this +i’ll own this +i want to own +let me own this +i own this +assign it +this one please +working on it +i’ll do it +let me do it +doing it +i’ve got this +got this +i got this +my task +my issue +my pick +take charge +assign pls +assign me pls +let me pick +can i take +can i pick +can i try +need assign +i’m available +available to help +want issue +need issue +pick for me +pick me +assign me this +ready to help +mark mine +flag mine +dibs on this \ No newline at end of file diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js new file mode 100644 index 0000000..942a1b0 --- /dev/null +++ b/scripts/notify_team_new_comment.js @@ -0,0 +1,85 @@ +const fs = require('fs'); +const path = require('path'); + +function hasLabel(labels, name) { + return labels.some(label => label.toLowerCase() === name.toLowerCase()); +} + +module.exports = async ({ github, context, core }) => { + try { + const issueNumber = context.payload.issue.number; + const issueUrl = context.payload.issue.html_url; + const issueTitle = context.payload.issue.title; + const escapedTitle = issueTitle.replace(/"/g, '\\"'); + const commentId = context.payload.comment.id; + const commentTime = new Date(context.payload.comment.created_at); + const commentAuthor = context.payload.comment.user.login; + const commentBody = context.payload.comment.body; + const repo = context.repo.repo; + const owner = context.repo.owner; + const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL; + const communityWebhookUrl = process.env.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL; + const botMessage = `👋 +Thanks so much for your interest! This issue is currently reserved for the core team and isn’t available for assignment right now. +If you’d like to get started contributing, please take a look at our [Contributing Guidelines](https://github.com/your-org/your-repo/blob/main/CONTRIBUTING.md) for tips on finding “help-wanted” issues, setting up your environment, and submitting a PR. +We really appreciate your willingness to help — feel free to pick another issue labeled **help-wanted** and let us know if you have any questions. 😊` + + const Close_Contributors = ['user1', 'user2']; + const keywordsPath = path.join(__dirname, 'keywords.txt'); + const keywords = fs.readFileSync(keywordsPath, 'utf-8') + .split('\n') + .map(k => k.trim().toLowerCase()) + .filter(Boolean); + + const { data: labels } = await github.rest.issues.listLabelsOnIssue({ + owner, + repo, + issue_number: issueNumber + }); + + const labelNames = labels.map(label => label.name); + let message; + + if (hasLabel(labelNames, 'help wanted') || Close_Contributors.includes(commentAuthor)) { + message = `*[${repo}] <${issueUrl}#issuecomment-${commentId}|New comment> on issue: <${issueUrl}|${escapedTitle}> by ${commentAuthor}*`; + core.setOutput('webhook_url', slackWebhookUrl); + } else { + const matchedKeywords = keywords.find(keyword => commentBody.toLowerCase().includes(keyword)); + let lastBotComment; + if(matchedKeywords){ + const oneHourBefore = new Date(commentTime - 3600000); + const PastComments = await github.rest.issues.listComments({ + owner, + repo, + issue_number: issueNumber, + since: oneHourBefore.toISOString() + }); + + const PastBotComments = PastComments.data.filter(comment => comment.user.login === 'testshobh[bot]'); + + if(PastBotComments.length > 0){ + lastBotComment = PastBotComments.at(-1); + core.setOutput('bot_replied', false); + } else if(PastBotComments.length === 0){ + lastBotComment = await github.rest.issues.createComment({ + owner, + repo, + issue_number: issueNumber, + body: `Hi @${commentAuthor} ${botMessage}` + }); + core.setOutput('bot_replied', true); + const botReply = `*[${repo}] <${lastBotComment.data.html_url}|Bot response sent> on issue: <${issueUrl}|${escapedTitle}>*`; + core.setOutput('bot_reply_message', botReply); + } + } + message = `*[${repo}] <${issueUrl}#issuecomment-${commentId}|New comment> on issue: <${issueUrl}|${escapedTitle}> by ${commentAuthor}*`; + + core.setOutput('webhook_url', communityWebhookUrl); + } + + core.setOutput('text', message); + + } catch (error) { + core.setFailed(`Action failed with error: ${error.message}`); + } +}; From c71409e50dfdeaaa1f79dcb86ae3d097b6118c56 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Thu, 26 Jun 2025 03:10:25 +0530 Subject: [PATCH 02/33] updated the name of secrets for LE bot --- .github/workflows/notify_team_new_comment.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/notify_team_new_comment.yml b/.github/workflows/notify_team_new_comment.yml index 4fd638a..a0a2961 100644 --- a/.github/workflows/notify_team_new_comment.yml +++ b/.github/workflows/notify_team_new_comment.yml @@ -3,12 +3,12 @@ name: Send a slack notification when a contributor comments on issue on: workflow_call: secrets: - APP_ID: - required: true - description: The ID of the GitHub App. - APP_PRIVATE_KEY: - required: true - description: The private key of the GitHub App. + LE_BOT_APP_ID: + description: "GitHub App ID for authentication" + required: true + LE_BOT_PRIVATE_KEY: + description: "GitHub App Private Key for authentication" + required: true SLACK_WEBHOOK_URL: required: true description: Webhook URL for the Slack support-dev channel where notifications should be sent. From 74c7cbd4eb780e20aa2f4be6433ed669f6a4b7e6 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Thu, 26 Jun 2025 03:12:24 +0530 Subject: [PATCH 03/33] updated the name of secrets for LE bot --- .github/workflows/notify_team_new_comment.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/notify_team_new_comment.yml b/.github/workflows/notify_team_new_comment.yml index a0a2961..303de1a 100644 --- a/.github/workflows/notify_team_new_comment.yml +++ b/.github/workflows/notify_team_new_comment.yml @@ -36,8 +36,8 @@ jobs: id: generate-token uses: tibdex/github-app-token@v2 with: - app_id: ${{ secrets.APP_ID }} - private_key: ${{ secrets.APP_PRIVATE_KEY }} + app_id: ${{ secrets.LE_BOT_APP_ID }} + private_key: ${{ secrets.LE_BOT_PRIVATE_KEY }} - name: Checkout called repository uses: actions/checkout@v4 From 54ae934b5e10b6351ba0974557ec1691d6197689 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Sat, 28 Jun 2025 23:14:52 +0530 Subject: [PATCH 04/33] updated bot username --- scripts/notify_team_new_comment.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index 942a1b0..153b2bd 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -19,6 +19,7 @@ module.exports = async ({ github, context, core }) => { const owner = context.repo.owner; const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL; const communityWebhookUrl = process.env.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL; + const LE_bot_username = 'learningequality[bot]'; const botMessage = `👋 Thanks so much for your interest! This issue is currently reserved for the core team and isn’t available for assignment right now. If you’d like to get started contributing, please take a look at our [Contributing Guidelines](https://github.com/your-org/your-repo/blob/main/CONTRIBUTING.md) for tips on finding “help-wanted” issues, setting up your environment, and submitting a PR. @@ -55,7 +56,7 @@ We really appreciate your willingness to help — feel free to pick another issu since: oneHourBefore.toISOString() }); - const PastBotComments = PastComments.data.filter(comment => comment.user.login === 'testshobh[bot]'); + const PastBotComments = PastComments.data.filter(comment => comment.user.login === LE_bot_username); if(PastBotComments.length > 0){ lastBotComment = PastBotComments.at(-1); From ee5556728ea9e5b3a2f98fb8b6e7eaceb6a247e7 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Sat, 28 Jun 2025 23:16:17 +0530 Subject: [PATCH 05/33] fixed the spelling of dependency --- .github/workflows/notify_team_new_comment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/notify_team_new_comment.yml b/.github/workflows/notify_team_new_comment.yml index 303de1a..e27593b 100644 --- a/.github/workflows/notify_team_new_comment.yml +++ b/.github/workflows/notify_team_new_comment.yml @@ -51,7 +51,7 @@ jobs: with: node-version: '16' - - name: Install dependancies + - name: Install dependencies run: npm install - name: Run check script From add029bf2f51c80a455b93c865e009fa7deecdd4 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Sat, 28 Jun 2025 23:25:08 +0530 Subject: [PATCH 06/33] added fallback for bot create comment api call --- scripts/notify_team_new_comment.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index 153b2bd..5c8965c 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -62,15 +62,22 @@ We really appreciate your willingness to help — feel free to pick another issu lastBotComment = PastBotComments.at(-1); core.setOutput('bot_replied', false); } else if(PastBotComments.length === 0){ - lastBotComment = await github.rest.issues.createComment({ - owner, - repo, - issue_number: issueNumber, - body: `Hi @${commentAuthor} ${botMessage}` - }); - core.setOutput('bot_replied', true); - const botReply = `*[${repo}] <${lastBotComment.data.html_url}|Bot response sent> on issue: <${issueUrl}|${escapedTitle}>*`; - core.setOutput('bot_reply_message', botReply); + try { + lastBotComment = await github.rest.issues.createComment({ + owner, + repo, + issue_number: issueNumber, + body: `Hi @${commentAuthor} ${botMessage}` + }); + if (lastBotComment?.data?.html_url) { + core.setOutput('bot_replied', true); + const botReply = `*[${repo}] <${lastBotComment.data.html_url}|Bot response sent> on issue: <${issueUrl}|${escapedTitle}>*`; + core.setOutput('bot_reply_message', botReply); + } + } catch (error) { + core.warning(`Failed to post bot comment: ${error.message}`); + core.setOutput('bot_replied', false); + } } } message = `*[${repo}] <${issueUrl}#issuecomment-${commentId}|New comment> on issue: <${issueUrl}|${escapedTitle}> by ${commentAuthor}*`; From 41deb3ac746c457108ba2f67313e15d0925a6c89 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Sat, 28 Jun 2025 23:28:47 +0530 Subject: [PATCH 07/33] added fallback for fetchig labels on the issue api call --- scripts/notify_team_new_comment.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index 5c8965c..5d87d72 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -32,11 +32,18 @@ We really appreciate your willingness to help — feel free to pick another issu .map(k => k.trim().toLowerCase()) .filter(Boolean); - const { data: labels } = await github.rest.issues.listLabelsOnIssue({ - owner, - repo, - issue_number: issueNumber - }); + let labels = []; + try { + const response = await github.rest.issues.listLabelsOnIssue({ + owner, + repo, + issue_number: issueNumber + }); + labels = response.data; + } catch (error) { + core.warning(`⚠️ Failed to fetch labels on issue #${issueNumber}: ${error.message}`); + labels = []; + } const labelNames = labels.map(label => label.name); let message; From abf3932bad1b2e52100ea7b79ae295f6d773e2ee Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Sat, 28 Jun 2025 23:34:34 +0530 Subject: [PATCH 08/33] added fallback for fetchig comments on the issue api call --- scripts/notify_team_new_comment.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index 5d87d72..450bfcd 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -56,14 +56,19 @@ We really appreciate your willingness to help — feel free to pick another issu let lastBotComment; if(matchedKeywords){ const oneHourBefore = new Date(commentTime - 3600000); - const PastComments = await github.rest.issues.listComments({ - owner, - repo, - issue_number: issueNumber, - since: oneHourBefore.toISOString() - }); - - const PastBotComments = PastComments.data.filter(comment => comment.user.login === LE_bot_username); + let PastBotComments; + try{ + let response = await github.rest.issues.listComments({ + owner, + repo, + issue_number: issueNumber, + since: oneHourBefore.toISOString() + }); + PastBotComments = response.data.filter(comment => comment.user.login === LE_bot_username); + } catch (error) { + core.warning(`⚠️ Failed to fetch comments on issue #${issueNumber}: ${error.message}`); + PastBotComments = []; + } if(PastBotComments.length > 0){ lastBotComment = PastBotComments.at(-1); From a7e40da8b8ff83388e0c19712871490ebc973017 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Sat, 28 Jun 2025 23:36:40 +0530 Subject: [PATCH 09/33] linting fix --- scripts/notify_team_new_comment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index 450bfcd..4998ebb 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -19,7 +19,7 @@ module.exports = async ({ github, context, core }) => { const owner = context.repo.owner; const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL; const communityWebhookUrl = process.env.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL; - const LE_bot_username = 'learningequality[bot]'; + const LE_bot_username = 'learningequality[bot]'; const botMessage = `👋 Thanks so much for your interest! This issue is currently reserved for the core team and isn’t available for assignment right now. If you’d like to get started contributing, please take a look at our [Contributing Guidelines](https://github.com/your-org/your-repo/blob/main/CONTRIBUTING.md) for tips on finding “help-wanted” issues, setting up your environment, and submitting a PR. From 1989bab823649dd24f2a78ba5e8a0d4b66445b82 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Sun, 29 Jun 2025 01:12:15 +0530 Subject: [PATCH 10/33] reduced bigger fn into smaller ones --- scripts/notify_team_new_comment.js | 114 +++++++++++++++-------------- 1 file changed, 59 insertions(+), 55 deletions(-) diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index 4998ebb..6c71d49 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -1,10 +1,6 @@ const fs = require('fs'); const path = require('path'); -function hasLabel(labels, name) { - return labels.some(label => label.toLowerCase() === name.toLowerCase()); -} - module.exports = async ({ github, context, core }) => { try { const issueNumber = context.payload.issue.number; @@ -13,6 +9,7 @@ module.exports = async ({ github, context, core }) => { const escapedTitle = issueTitle.replace(/"/g, '\\"'); const commentId = context.payload.comment.id; const commentTime = new Date(context.payload.comment.created_at); + const oneHourBefore = new Date(commentTime - 3600000); const commentAuthor = context.payload.comment.user.login; const commentBody = context.payload.comment.body; const repo = context.repo.repo; @@ -20,11 +17,11 @@ module.exports = async ({ github, context, core }) => { const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL; const communityWebhookUrl = process.env.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL; const LE_bot_username = 'learningequality[bot]'; + const message = `*[${repo}] <${issueUrl}#issuecomment-${commentId}|New comment> on issue: <${issueUrl}|${escapedTitle}> by ${commentAuthor}*`; const botMessage = `👋 Thanks so much for your interest! This issue is currently reserved for the core team and isn’t available for assignment right now. If you’d like to get started contributing, please take a look at our [Contributing Guidelines](https://github.com/your-org/your-repo/blob/main/CONTRIBUTING.md) for tips on finding “help-wanted” issues, setting up your environment, and submitting a PR. We really appreciate your willingness to help — feel free to pick another issue labeled **help-wanted** and let us know if you have any questions. 😊` - const Close_Contributors = ['user1', 'user2']; const keywordsPath = path.join(__dirname, 'keywords.txt'); const keywords = fs.readFileSync(keywordsPath, 'utf-8') @@ -32,68 +29,75 @@ We really appreciate your willingness to help — feel free to pick another issu .map(k => k.trim().toLowerCase()) .filter(Boolean); - let labels = []; - try { - const response = await github.rest.issues.listLabelsOnIssue({ - owner, - repo, - issue_number: issueNumber - }); - labels = response.data; - } catch (error) { - core.warning(`⚠️ Failed to fetch labels on issue #${issueNumber}: ${error.message}`); - labels = []; + + async function hasLabel(name) { + let labels = []; + try { + const response = await github.rest.issues.listLabelsOnIssue({ + owner, + repo, + issue_number: issueNumber + }); + labels = response.data.map(label => label.name); + } catch (error) { + core.warning(`⚠️ Failed to fetch labels on issue #${issueNumber}: ${error.message}`); + labels = []; + } + return labels.some(label => label.toLowerCase() === name.toLowerCase()); + } + + async function findRecentCommentsByUser(username) { + try{ + let response = await github.rest.issues.listComments({ + owner, + repo, + issue_number: issueNumber, + since: oneHourBefore.toISOString() + }); + return response.data.filter(comment => comment.user.login === username); + } catch (error) { + core.warning(`⚠️ Failed to fetch comments on issue #${issueNumber}: ${error.message}`); + return []; + } } - const labelNames = labels.map(label => label.name); - let message; + async function botReply(){ + let response = null; + try { + response = await github.rest.issues.createComment({ + owner, + repo, + issue_number: issueNumber, + body: `Hi @${commentAuthor} ${botMessage}` + }); + if (response?.data?.html_url) { + core.setOutput('bot_replied', true); + const botReplyMessage = `*[${repo}] <${response.data.html_url}|Bot response sent> on issue: <${issueUrl}|${escapedTitle}>*`; + core.setOutput('bot_reply_message', botReplyMessage); + } + } catch (error) { + core.warning(`Failed to post bot comment: ${error.message}`); + core.setOutput('bot_replied', false); + } + return response; + } - if (hasLabel(labelNames, 'help wanted') || Close_Contributors.includes(commentAuthor)) { - message = `*[${repo}] <${issueUrl}#issuecomment-${commentId}|New comment> on issue: <${issueUrl}|${escapedTitle}> by ${commentAuthor}*`; + + if (hasLabel('help wanted') || Close_Contributors.includes(commentAuthor)) { core.setOutput('webhook_url', slackWebhookUrl); } else { - const matchedKeywords = keywords.find(keyword => commentBody.toLowerCase().includes(keyword)); + const matchedKeywords = keywords.find(keyword => commentBody.toLowerCase().includes(keyword)); + if(matchedKeywords){ let lastBotComment; - if(matchedKeywords){ - const oneHourBefore = new Date(commentTime - 3600000); - let PastBotComments; - try{ - let response = await github.rest.issues.listComments({ - owner, - repo, - issue_number: issueNumber, - since: oneHourBefore.toISOString() - }); - PastBotComments = response.data.filter(comment => comment.user.login === LE_bot_username); - } catch (error) { - core.warning(`⚠️ Failed to fetch comments on issue #${issueNumber}: ${error.message}`); - PastBotComments = []; - } + let PastBotComments = findRecentCommentsByUser(LE_bot_username); - if(PastBotComments.length > 0){ + if(PastBotComments.length > 0){ lastBotComment = PastBotComments.at(-1); core.setOutput('bot_replied', false); } else if(PastBotComments.length === 0){ - try { - lastBotComment = await github.rest.issues.createComment({ - owner, - repo, - issue_number: issueNumber, - body: `Hi @${commentAuthor} ${botMessage}` - }); - if (lastBotComment?.data?.html_url) { - core.setOutput('bot_replied', true); - const botReply = `*[${repo}] <${lastBotComment.data.html_url}|Bot response sent> on issue: <${issueUrl}|${escapedTitle}>*`; - core.setOutput('bot_reply_message', botReply); - } - } catch (error) { - core.warning(`Failed to post bot comment: ${error.message}`); - core.setOutput('bot_replied', false); - } + lastBotComment = botReply(); } } - message = `*[${repo}] <${issueUrl}#issuecomment-${commentId}|New comment> on issue: <${issueUrl}|${escapedTitle}> by ${commentAuthor}*`; - core.setOutput('webhook_url', communityWebhookUrl); } From 5d717f4f024bee1ccfe9e564a2bff753f9487a75 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Mon, 30 Jun 2025 21:48:31 +0530 Subject: [PATCH 11/33] fixed promise errors and reorganised code --- scripts/notify_team_new_comment.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index 6c71d49..ddc9fa0 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -17,7 +17,6 @@ module.exports = async ({ github, context, core }) => { const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL; const communityWebhookUrl = process.env.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL; const LE_bot_username = 'learningequality[bot]'; - const message = `*[${repo}] <${issueUrl}#issuecomment-${commentId}|New comment> on issue: <${issueUrl}|${escapedTitle}> by ${commentAuthor}*`; const botMessage = `👋 Thanks so much for your interest! This issue is currently reserved for the core team and isn’t available for assignment right now. If you’d like to get started contributing, please take a look at our [Contributing Guidelines](https://github.com/your-org/your-repo/blob/main/CONTRIBUTING.md) for tips on finding “help-wanted” issues, setting up your environment, and submitting a PR. @@ -40,7 +39,7 @@ We really appreciate your willingness to help — feel free to pick another issu }); labels = response.data.map(label => label.name); } catch (error) { - core.warning(`⚠️ Failed to fetch labels on issue #${issueNumber}: ${error.message}`); + core.warning(`⚠️ Failed to fetch labels on issue #${issueNumber}: ${error.message}`); labels = []; } return labels.some(label => label.toLowerCase() === name.toLowerCase()); @@ -83,24 +82,27 @@ We really appreciate your willingness to help — feel free to pick another issu } - if (hasLabel('help wanted') || Close_Contributors.includes(commentAuthor)) { + if (await hasLabel('help wanted') || Close_Contributors.includes(commentAuthor)) { core.setOutput('webhook_url', slackWebhookUrl); } else { const matchedKeywords = keywords.find(keyword => commentBody.toLowerCase().includes(keyword)); if(matchedKeywords){ + core.setOutput('webhook_url', communityWebhookUrl); let lastBotComment; - let PastBotComments = findRecentCommentsByUser(LE_bot_username); - + let PastBotComments = await findRecentCommentsByUser(LE_bot_username); + // post a bot reply if there is matched keyword and no previous bot comment in past hour if(PastBotComments.length > 0){ lastBotComment = PastBotComments.at(-1); core.setOutput('bot_replied', false); } else if(PastBotComments.length === 0){ - lastBotComment = botReply(); + console.log("bot is replying"); + lastBotComment = await botReply(); } } - core.setOutput('webhook_url', communityWebhookUrl); + } + const message = `*[${repo}] <${issueUrl}#issuecomment-${commentId}|New comment> on issue: <${issueUrl}|${escapedTitle}> by ${commentAuthor}*`; core.setOutput('text', message); } catch (error) { From 5e36f17cc6d6a6ad887404cd77a798776dd13cde Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Mon, 30 Jun 2025 22:10:33 +0530 Subject: [PATCH 12/33] added regex to check matched keywords --- scripts/notify_team_new_comment.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index ddc9fa0..49edce8 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -16,17 +16,19 @@ module.exports = async ({ github, context, core }) => { const owner = context.repo.owner; const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL; const communityWebhookUrl = process.env.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL; - const LE_bot_username = 'learningequality[bot]'; + const LE_bot_username = 'testshobh[bot]'; const botMessage = `👋 Thanks so much for your interest! This issue is currently reserved for the core team and isn’t available for assignment right now. If you’d like to get started contributing, please take a look at our [Contributing Guidelines](https://github.com/your-org/your-repo/blob/main/CONTRIBUTING.md) for tips on finding “help-wanted” issues, setting up your environment, and submitting a PR. We really appreciate your willingness to help — feel free to pick another issue labeled **help-wanted** and let us know if you have any questions. 😊` const Close_Contributors = ['user1', 'user2']; const keywordsPath = path.join(__dirname, 'keywords.txt'); - const keywords = fs.readFileSync(keywordsPath, 'utf-8') - .split('\n') - .map(k => k.trim().toLowerCase()) - .filter(Boolean); + const keywordRegexes = fs.readFileSync(keywordsPath, 'utf-8') + .split('\n') + .map(k => k.trim().toLowerCase()) + .filter(Boolean) + .map(keyword => new RegExp(`\\b${keyword}\\b`, 'i')); + async function hasLabel(name) { @@ -85,12 +87,12 @@ We really appreciate your willingness to help — feel free to pick another issu if (await hasLabel('help wanted') || Close_Contributors.includes(commentAuthor)) { core.setOutput('webhook_url', slackWebhookUrl); } else { - const matchedKeywords = keywords.find(keyword => commentBody.toLowerCase().includes(keyword)); - if(matchedKeywords){ - core.setOutput('webhook_url', communityWebhookUrl); + core.setOutput('webhook_url', communityWebhookUrl); + const matchedKeyword = keywordRegexes.find(regex => regex.test(commentBody)); + // post a bot reply if there is matched keyword and no previous bot comment in past hour + if(matchedKeyword){ let lastBotComment; let PastBotComments = await findRecentCommentsByUser(LE_bot_username); - // post a bot reply if there is matched keyword and no previous bot comment in past hour if(PastBotComments.length > 0){ lastBotComment = PastBotComments.at(-1); core.setOutput('bot_replied', false); @@ -98,8 +100,7 @@ We really appreciate your willingness to help — feel free to pick another issu console.log("bot is replying"); lastBotComment = await botReply(); } - } - + } } const message = `*[${repo}] <${issueUrl}#issuecomment-${commentId}|New comment> on issue: <${issueUrl}|${escapedTitle}> by ${commentAuthor}*`; From c816e2681653c6e9d761c24e028d0c5275c77f32 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Mon, 30 Jun 2025 22:11:01 +0530 Subject: [PATCH 13/33] removed extra lines --- scripts/notify_team_new_comment.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index 49edce8..fdd815d 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -84,6 +84,7 @@ We really appreciate your willingness to help — feel free to pick another issu } + // set webhook url based on label on issue if (await hasLabel('help wanted') || Close_Contributors.includes(commentAuthor)) { core.setOutput('webhook_url', slackWebhookUrl); } else { From b93ac489d715212d615a258c6e1f677ce206068c Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Mon, 30 Jun 2025 22:33:27 +0530 Subject: [PATCH 14/33] moved literal constants to seperate file --- scripts/constants.js | 8 ++++++++ scripts/notify_team_new_comment.js | 14 ++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 scripts/constants.js diff --git a/scripts/constants.js b/scripts/constants.js new file mode 100644 index 0000000..fa21119 --- /dev/null +++ b/scripts/constants.js @@ -0,0 +1,8 @@ +module.exports = { + LE_BOT_USERNAME: 'testshobh[bot]', + BOT_MESSAGE: `👋 +Thanks so much for your interest! This issue is currently reserved for the core team and isn’t available for assignment right now. +If you’d like to get started contributing, please take a look at our [Contributing Guidelines](https://github.com/your-org/your-repo/blob/main/CONTRIBUTING.md) for tips on finding “help-wanted” issues, setting up your environment, and submitting a PR. +We really appreciate your willingness to help — feel free to pick another issue labeled **help-wanted** and let us know if you have any questions. 😊`, + CLOSE_CONTRIBUTORS: ['user1', 'user2'], +}; diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index fdd815d..b042ad4 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -1,5 +1,6 @@ const fs = require('fs'); const path = require('path'); +const { LE_BOT_USERNAME, BOT_MESSAGE, CLOSE_CONTRIBUTORS } = require('./constants'); module.exports = async ({ github, context, core }) => { try { @@ -16,12 +17,6 @@ module.exports = async ({ github, context, core }) => { const owner = context.repo.owner; const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL; const communityWebhookUrl = process.env.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL; - const LE_bot_username = 'testshobh[bot]'; - const botMessage = `👋 -Thanks so much for your interest! This issue is currently reserved for the core team and isn’t available for assignment right now. -If you’d like to get started contributing, please take a look at our [Contributing Guidelines](https://github.com/your-org/your-repo/blob/main/CONTRIBUTING.md) for tips on finding “help-wanted” issues, setting up your environment, and submitting a PR. -We really appreciate your willingness to help — feel free to pick another issue labeled **help-wanted** and let us know if you have any questions. 😊` - const Close_Contributors = ['user1', 'user2']; const keywordsPath = path.join(__dirname, 'keywords.txt'); const keywordRegexes = fs.readFileSync(keywordsPath, 'utf-8') .split('\n') @@ -69,7 +64,7 @@ We really appreciate your willingness to help — feel free to pick another issu owner, repo, issue_number: issueNumber, - body: `Hi @${commentAuthor} ${botMessage}` + body: `Hi @${commentAuthor} ${BOT_MESSAGE}` }); if (response?.data?.html_url) { core.setOutput('bot_replied', true); @@ -84,8 +79,7 @@ We really appreciate your willingness to help — feel free to pick another issu } - // set webhook url based on label on issue - if (await hasLabel('help wanted') || Close_Contributors.includes(commentAuthor)) { + if (await hasLabel('help wanted') || CLOSE_CONTRIBUTORS.includes(commentAuthor)) { core.setOutput('webhook_url', slackWebhookUrl); } else { core.setOutput('webhook_url', communityWebhookUrl); @@ -93,7 +87,7 @@ We really appreciate your willingness to help — feel free to pick another issu // post a bot reply if there is matched keyword and no previous bot comment in past hour if(matchedKeyword){ let lastBotComment; - let PastBotComments = await findRecentCommentsByUser(LE_bot_username); + let PastBotComments = await findRecentCommentsByUser(LE_BOT_USERNAME); if(PastBotComments.length > 0){ lastBotComment = PastBotComments.at(-1); core.setOutput('bot_replied', false); From a1d6dbfd1e9b95437e2e0549a67e534edcb87372 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Tue, 1 Jul 2025 17:07:30 +0530 Subject: [PATCH 15/33] updated bot username --- scripts/constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/constants.js b/scripts/constants.js index fa21119..572f996 100644 --- a/scripts/constants.js +++ b/scripts/constants.js @@ -1,5 +1,5 @@ module.exports = { - LE_BOT_USERNAME: 'testshobh[bot]', + LE_BOT_USERNAME: 'learningequality[bot]', BOT_MESSAGE: `👋 Thanks so much for your interest! This issue is currently reserved for the core team and isn’t available for assignment right now. If you’d like to get started contributing, please take a look at our [Contributing Guidelines](https://github.com/your-org/your-repo/blob/main/CONTRIBUTING.md) for tips on finding “help-wanted” issues, setting up your environment, and submitting a PR. From ccde01a675d4186a81e0ebc61fc9393915c3cd9d Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Tue, 1 Jul 2025 17:14:21 +0530 Subject: [PATCH 16/33] added seperate file for close contributors --- scripts/close_contributors.js | 3 +++ scripts/constants.js | 1 - scripts/notify_team_new_comment.js | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 scripts/close_contributors.js diff --git a/scripts/close_contributors.js b/scripts/close_contributors.js new file mode 100644 index 0000000..a111f10 --- /dev/null +++ b/scripts/close_contributors.js @@ -0,0 +1,3 @@ +module.exports = { + CLOSE_CONTRIBUTORS: ['user1', 'user2'], +}; diff --git a/scripts/constants.js b/scripts/constants.js index 572f996..80bb949 100644 --- a/scripts/constants.js +++ b/scripts/constants.js @@ -4,5 +4,4 @@ module.exports = { Thanks so much for your interest! This issue is currently reserved for the core team and isn’t available for assignment right now. If you’d like to get started contributing, please take a look at our [Contributing Guidelines](https://github.com/your-org/your-repo/blob/main/CONTRIBUTING.md) for tips on finding “help-wanted” issues, setting up your environment, and submitting a PR. We really appreciate your willingness to help — feel free to pick another issue labeled **help-wanted** and let us know if you have any questions. 😊`, - CLOSE_CONTRIBUTORS: ['user1', 'user2'], }; diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index b042ad4..da0f286 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -1,6 +1,7 @@ const fs = require('fs'); const path = require('path'); -const { LE_BOT_USERNAME, BOT_MESSAGE, CLOSE_CONTRIBUTORS } = require('./constants'); +const { LE_BOT_USERNAME, BOT_MESSAGE } = require('./constants'); +const { CLOSE_CONTRIBUTORS } = require('./close_contributors'); module.exports = async ({ github, context, core }) => { try { From 8f7517b3742b096f21466e0779a3f6774804fc40 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Wed, 16 Jul 2025 01:25:25 +0530 Subject: [PATCH 17/33] updated node version --- .github/workflows/notify_team_new_comment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/notify_team_new_comment.yml b/.github/workflows/notify_team_new_comment.yml index e27593b..87050a5 100644 --- a/.github/workflows/notify_team_new_comment.yml +++ b/.github/workflows/notify_team_new_comment.yml @@ -49,7 +49,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '16' + node-version: '20' - name: Install dependencies run: npm install From 7e7a36b5b9166e9eb7b10aeaba664eaaf13b3712 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Wed, 16 Jul 2025 01:28:55 +0530 Subject: [PATCH 18/33] updated secrets variable name --- scripts/notify_team_new_comment.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index da0f286..97e4c12 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -16,8 +16,8 @@ module.exports = async ({ github, context, core }) => { const commentBody = context.payload.comment.body; const repo = context.repo.repo; const owner = context.repo.owner; - const slackWebhookUrl = process.env.SLACK_WEBHOOK_URL; - const communityWebhookUrl = process.env.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL; + const supportDevSlackWebhookUrl = process.env.SLACK_WEBHOOK_URL; + const supportDevNotificationsSlackWebhookUrl = process.env.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL; const keywordsPath = path.join(__dirname, 'keywords.txt'); const keywordRegexes = fs.readFileSync(keywordsPath, 'utf-8') .split('\n') @@ -81,9 +81,9 @@ module.exports = async ({ github, context, core }) => { if (await hasLabel('help wanted') || CLOSE_CONTRIBUTORS.includes(commentAuthor)) { - core.setOutput('webhook_url', slackWebhookUrl); + core.setOutput('webhook_url', supportDevSlackWebhookUrl); } else { - core.setOutput('webhook_url', communityWebhookUrl); + core.setOutput('webhook_url', supportDevNotificationsSlackWebhookUrl); const matchedKeyword = keywordRegexes.find(regex => regex.test(commentBody)); // post a bot reply if there is matched keyword and no previous bot comment in past hour if(matchedKeyword){ From dc2a320c0fd79868f4be420377a5155c833ebc7d Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Wed, 16 Jul 2025 01:30:09 +0530 Subject: [PATCH 19/33] updated the bot reply step name --- .github/workflows/notify_team_new_comment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/notify_team_new_comment.yml b/.github/workflows/notify_team_new_comment.yml index 87050a5..b366d3f 100644 --- a/.github/workflows/notify_team_new_comment.yml +++ b/.github/workflows/notify_team_new_comment.yml @@ -76,7 +76,7 @@ jobs: "text": "${{ steps.check.outputs.text }}" } - - name: Send bot message to Slack channel + - name: Send Slack notification about GitHub bot reply if: ${{ steps.check.outputs.bot_replied }} uses: slackapi/slack-github-action@v2.1.0 with: From e3e34ab9b13e4510de5662da60aa4ac68c8206d2 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Wed, 16 Jul 2025 01:31:27 +0530 Subject: [PATCH 20/33] renamed a step --- .github/workflows/notify_team_new_comment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/notify_team_new_comment.yml b/.github/workflows/notify_team_new_comment.yml index b366d3f..8df8ab5 100644 --- a/.github/workflows/notify_team_new_comment.yml +++ b/.github/workflows/notify_team_new_comment.yml @@ -66,7 +66,7 @@ jobs: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL: ${{ secrets.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL }} - - name: Send message to Slack channel + - name: Send Slack notification about GitHub comment uses: slackapi/slack-github-action@v2.1.0 with: webhook-type: incoming-webhook From e9741f4b5009a209fca23d9bd5fcbc25b7811329 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Wed, 16 Jul 2025 01:34:14 +0530 Subject: [PATCH 21/33] renamed a output variable name for message --- .github/workflows/notify_team_new_comment.yml | 2 +- scripts/notify_team_new_comment.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/notify_team_new_comment.yml b/.github/workflows/notify_team_new_comment.yml index 8df8ab5..e4f4e4a 100644 --- a/.github/workflows/notify_team_new_comment.yml +++ b/.github/workflows/notify_team_new_comment.yml @@ -73,7 +73,7 @@ jobs: webhook: ${{ steps.check.outputs.webhook_url }} payload: > { - "text": "${{ steps.check.outputs.text }}" + "text": "${{ steps.check.outputs.slack_notification_comment }}" } - name: Send Slack notification about GitHub bot reply diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index 97e4c12..55a73ac 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -100,7 +100,7 @@ module.exports = async ({ github, context, core }) => { } const message = `*[${repo}] <${issueUrl}#issuecomment-${commentId}|New comment> on issue: <${issueUrl}|${escapedTitle}> by ${commentAuthor}*`; - core.setOutput('text', message); + core.setOutput('slack_notification_comment', message); } catch (error) { core.setFailed(`Action failed with error: ${error.message}`); From c1e13f51c71ac7753e01cd27fdd0fdd13bd65220 Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Wed, 16 Jul 2025 01:36:17 +0530 Subject: [PATCH 22/33] renamed a output variable name for bot message --- .github/workflows/notify_team_new_comment.yml | 2 +- scripts/notify_team_new_comment.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/notify_team_new_comment.yml b/.github/workflows/notify_team_new_comment.yml index e4f4e4a..beb34f8 100644 --- a/.github/workflows/notify_team_new_comment.yml +++ b/.github/workflows/notify_team_new_comment.yml @@ -84,6 +84,6 @@ jobs: webhook: ${{ steps.check.outputs.webhook_url }} payload: > { - "text": "${{ steps.check.outputs.bot_reply_message }}" + "text": "${{ steps.check.outputs.slack_notification_bot_comment }}" } diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index 55a73ac..8fab4c0 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -70,7 +70,7 @@ module.exports = async ({ github, context, core }) => { if (response?.data?.html_url) { core.setOutput('bot_replied', true); const botReplyMessage = `*[${repo}] <${response.data.html_url}|Bot response sent> on issue: <${issueUrl}|${escapedTitle}>*`; - core.setOutput('bot_reply_message', botReplyMessage); + core.setOutput('slack_notification_bot_comment', botReplyMessage); } } catch (error) { core.warning(`Failed to post bot comment: ${error.message}`); From b4d5d6688e41b0a96ba1b171002041b9b0d099af Mon Sep 17 00:00:00 2001 From: iamshobhraj Date: Wed, 16 Jul 2025 01:44:29 +0530 Subject: [PATCH 23/33] cleaned up keywords.txt --- scripts/keywords.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/keywords.txt b/scripts/keywords.txt index aad9609..e7f734d 100644 --- a/scripts/keywords.txt +++ b/scripts/keywords.txt @@ -1,10 +1,5 @@ assign -assign me -please assign -assign to me -assign this claim -claim this i claim this i’ll take this take this From 5f4c9989f6a416f035c385da4efecc7a645fca02 Mon Sep 17 00:00:00 2001 From: Michaela Robosova Date: Mon, 21 Jul 2025 15:22:57 +0200 Subject: [PATCH 24/33] Adjust bot message - Align with our most recent messaging - Remove contributor handle to keep a response more general. Due to bot response optimization that prevents from sending more than one response in an hour, not every contributor will receive a response. --- scripts/constants.js | 5 +---- scripts/notify_team_new_comment.js | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/constants.js b/scripts/constants.js index 80bb949..c84b9c4 100644 --- a/scripts/constants.js +++ b/scripts/constants.js @@ -1,7 +1,4 @@ module.exports = { LE_BOT_USERNAME: 'learningequality[bot]', - BOT_MESSAGE: `👋 -Thanks so much for your interest! This issue is currently reserved for the core team and isn’t available for assignment right now. -If you’d like to get started contributing, please take a look at our [Contributing Guidelines](https://github.com/your-org/your-repo/blob/main/CONTRIBUTING.md) for tips on finding “help-wanted” issues, setting up your environment, and submitting a PR. -We really appreciate your willingness to help — feel free to pick another issue labeled **help-wanted** and let us know if you have any questions. 😊`, + BOT_MESSAGE: `Hi! 👋 \n\n Thanks so much for your interest! **This issue is not open for contribution. Visit [Contributing guidelines](https://learningequality.org/contributing-to-our-open-code-base) to learn about the contributing process and how to find suitable issues.** \n\n We really appreciate your willingness to help—you're welcome to find a more suitable issue, and let us know if you have any questions. 😊`, }; diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index 8fab4c0..d0b1a23 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -65,7 +65,7 @@ module.exports = async ({ github, context, core }) => { owner, repo, issue_number: issueNumber, - body: `Hi @${commentAuthor} ${BOT_MESSAGE}` + body: BOT_MESSAGE }); if (response?.data?.html_url) { core.setOutput('bot_replied', true); From 53fdd727a8539851a85e807e5e56ad92330f9663 Mon Sep 17 00:00:00 2001 From: Michaela Robosova Date: Mon, 21 Jul 2025 15:23:59 +0200 Subject: [PATCH 25/33] Cleanup keywords --- scripts/keywords.txt | 126 +++++++++++++------------------------------ 1 file changed, 37 insertions(+), 89 deletions(-) diff --git a/scripts/keywords.txt b/scripts/keywords.txt index e7f734d..b108366 100644 --- a/scripts/keywords.txt +++ b/scripts/keywords.txt @@ -1,93 +1,41 @@ assign +assigned +work +working +contribute +contributing +request +requested +pick +picked +picking +address +addressing +help claim -i claim this -i’ll take this -take this -taking this -taken -i want this -mine -dibs -this is mine -i’ll do this -i’ll take care -let me take this -can i take this -can i work on this -can i help -can help -let me help -i want to help -want to help -working on this -i’m on it -i’ll work on it -i want to work -want this -i can do this -can do this -i can solve this -can solve this -let me try -i’ll try -i’ll try this -trying this -i’ll pick this -pick this -picking this -want to pick -grab this -grabbing this -i’m interested +claimed +take +want +would like +handle +handling +solve +solving +resolve +resolving +address +addressing +try +trying +grab +grabbing +own +do +doing +on it +interest interested -i want in -count me in -i’m doing this -doing now -will do -i’ll handle this -let me handle -let me solve -solve this -want to solve -taking charge -let me take care -taking it -bagging this -need this -can i own this -i’ll own this -i want to own -let me own this -i own this -assign it -this one please -working on it -i’ll do it -let me do it -doing it -i’ve got this +available +take care +help got this -i got this -my task -my issue -my pick -take charge -assign pls -assign me pls -let me pick -can i take -can i pick -can i try -need assign -i’m available -available to help -want issue -need issue -pick for me -pick me -assign me this -ready to help -mark mine -flag mine -dibs on this \ No newline at end of file From 0dd8c72d9d4d354341e056fb5e512f68ea84cea5 Mon Sep 17 00:00:00 2001 From: Michaela Robosova Date: Mon, 21 Jul 2025 15:26:31 +0200 Subject: [PATCH 26/33] Minor naming and documentation tweaks to improve clarity. --- .github/workflows/notify_team_new_comment.yml | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/notify_team_new_comment.yml b/.github/workflows/notify_team_new_comment.yml index beb34f8..6523d72 100644 --- a/.github/workflows/notify_team_new_comment.yml +++ b/.github/workflows/notify_team_new_comment.yml @@ -11,10 +11,10 @@ on: required: true SLACK_WEBHOOK_URL: required: true - description: Webhook URL for the Slack support-dev channel where notifications should be sent. + description: "Webhook URL for Slack #support-dev channel" SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL: required: true - description: Webhook URL for the Slack support-dev-notifications channel where notifications should be sent. + description: "Webhook URL for Slack #support-dev-notifications channel" jobs: @@ -39,7 +39,7 @@ jobs: app_id: ${{ secrets.LE_BOT_APP_ID }} private_key: ${{ secrets.LE_BOT_PRIVATE_KEY }} - - name: Checkout called repository + - name: Checkout .github repository uses: actions/checkout@v4 with: repository: testiamshobh/.github @@ -54,8 +54,8 @@ jobs: - name: Install dependencies run: npm install - - name: Run check script - id: check + - name: Run script + id: script uses: actions/github-script@v7 with: github-token: ${{ steps.generate-token.outputs.token }} @@ -70,20 +70,20 @@ jobs: uses: slackapi/slack-github-action@v2.1.0 with: webhook-type: incoming-webhook - webhook: ${{ steps.check.outputs.webhook_url }} + webhook: ${{ steps.script.outputs.webhook_url }} payload: > { - "text": "${{ steps.check.outputs.slack_notification_comment }}" + "text": "${{ steps.script.outputs.slack_notification_comment }}" } - name: Send Slack notification about GitHub bot reply - if: ${{ steps.check.outputs.bot_replied }} + if: ${{ steps.script.outputs.bot_replied }} uses: slackapi/slack-github-action@v2.1.0 with: webhook-type: incoming-webhook - webhook: ${{ steps.check.outputs.webhook_url }} + webhook: ${{ steps.script.outputs.webhook_url }} payload: > { - "text": "${{ steps.check.outputs.slack_notification_bot_comment }}" + "text": "${{ steps.script.outputs.slack_notification_bot_comment }}" } From 0713ff51ecaa202d104e74759181703381f8fbd8 Mon Sep 17 00:00:00 2001 From: Michaela Robosova Date: Mon, 21 Jul 2025 15:30:54 +0200 Subject: [PATCH 27/33] Consolidate constants --- scripts/close_contributors.js | 3 --- scripts/constants.js | 38 +++++++++++++++++++++++++-- scripts/keywords.txt | 41 ------------------------------ scripts/notify_team_new_comment.js | 19 +++++++------- 4 files changed, 46 insertions(+), 55 deletions(-) delete mode 100644 scripts/close_contributors.js delete mode 100644 scripts/keywords.txt diff --git a/scripts/close_contributors.js b/scripts/close_contributors.js deleted file mode 100644 index a111f10..0000000 --- a/scripts/close_contributors.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - CLOSE_CONTRIBUTORS: ['user1', 'user2'], -}; diff --git a/scripts/constants.js b/scripts/constants.js index c84b9c4..c08f231 100644 --- a/scripts/constants.js +++ b/scripts/constants.js @@ -1,4 +1,38 @@ +const LE_BOT_USERNAME = 'learningequality[bot]'; +const CLOSE_CONTRIBUTORS = ['user1', 'user2']; + +const KEYWORDS_DETECT_ASSIGNMENT_REQUEST = [ + 'assign', 'assigned', + 'work', 'working', + 'contribute', 'contributing', + 'request', 'requested', + 'pick', 'picked', 'picking', + 'address', 'addressing', + 'handle', 'handling', + 'solve', 'solving', 'resolve', 'resolving', + 'try', 'trying', + 'grab', 'grabbing', + 'claim', 'claimed', + 'interest', 'interested', + 'do', 'doing', + 'help', + 'take', + 'want', + 'would like', + 'own', + 'on it', + 'available', + 'got this' +]; + +const ISSUE_LABEL_HELP_WANTED = 'help wanted'; + +const BOT_MESSAGE_ISSUE_NOT_OPEN = `Hi! 👋 \n\n Thanks so much for your interest! **This issue is not open for contribution. Visit [Contributing guidelines](https://learningequality.org/contributing-to-our-open-code-base) to learn about the contributing process and how to find suitable issues.** \n\n We really appreciate your willingness to help—you're welcome to find a more suitable issue, and let us know if you have any questions. 😊`; + module.exports = { - LE_BOT_USERNAME: 'learningequality[bot]', - BOT_MESSAGE: `Hi! 👋 \n\n Thanks so much for your interest! **This issue is not open for contribution. Visit [Contributing guidelines](https://learningequality.org/contributing-to-our-open-code-base) to learn about the contributing process and how to find suitable issues.** \n\n We really appreciate your willingness to help—you're welcome to find a more suitable issue, and let us know if you have any questions. 😊`, + LE_BOT_USERNAME, + CLOSE_CONTRIBUTORS, + KEYWORDS_DETECT_ASSIGNMENT_REQUEST, + ISSUE_LABEL_HELP_WANTED, + BOT_MESSAGE_ISSUE_NOT_OPEN, }; diff --git a/scripts/keywords.txt b/scripts/keywords.txt deleted file mode 100644 index b108366..0000000 --- a/scripts/keywords.txt +++ /dev/null @@ -1,41 +0,0 @@ -assign -assigned -work -working -contribute -contributing -request -requested -pick -picked -picking -address -addressing -help -claim -claimed -take -want -would like -handle -handling -solve -solving -resolve -resolving -address -addressing -try -trying -grab -grabbing -own -do -doing -on it -interest -interested -available -take care -help -got this diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index d0b1a23..4d04264 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -1,7 +1,10 @@ -const fs = require('fs'); -const path = require('path'); -const { LE_BOT_USERNAME, BOT_MESSAGE } = require('./constants'); -const { CLOSE_CONTRIBUTORS } = require('./close_contributors'); +const { + LE_BOT_USERNAME, + CLOSE_CONTRIBUTORS, + KEYWORDS_DETECT_ASSIGNMENT_REQUEST, + ISSUE_LABEL_HELP_WANTED, + BOT_MESSAGE_ISSUE_NOT_OPEN +} = require('./constants'); module.exports = async ({ github, context, core }) => { try { @@ -18,9 +21,7 @@ module.exports = async ({ github, context, core }) => { const owner = context.repo.owner; const supportDevSlackWebhookUrl = process.env.SLACK_WEBHOOK_URL; const supportDevNotificationsSlackWebhookUrl = process.env.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL; - const keywordsPath = path.join(__dirname, 'keywords.txt'); - const keywordRegexes = fs.readFileSync(keywordsPath, 'utf-8') - .split('\n') + const keywordRegexes = KEYWORDS_DETECT_ASSIGNMENT_REQUEST .map(k => k.trim().toLowerCase()) .filter(Boolean) .map(keyword => new RegExp(`\\b${keyword}\\b`, 'i')); @@ -65,7 +66,7 @@ module.exports = async ({ github, context, core }) => { owner, repo, issue_number: issueNumber, - body: BOT_MESSAGE + body: BOT_MESSAGE_ISSUE_NOT_OPEN }); if (response?.data?.html_url) { core.setOutput('bot_replied', true); @@ -80,7 +81,7 @@ module.exports = async ({ github, context, core }) => { } - if (await hasLabel('help wanted') || CLOSE_CONTRIBUTORS.includes(commentAuthor)) { + if (await hasLabel(ISSUE_LABEL_HELP_WANTED) || CLOSE_CONTRIBUTORS.includes(commentAuthor)) { core.setOutput('webhook_url', supportDevSlackWebhookUrl); } else { core.setOutput('webhook_url', supportDevNotificationsSlackWebhookUrl); From 5a073d1a2d290532623fa8d113b1e06be4f8f769 Mon Sep 17 00:00:00 2001 From: Michaela Robosova Date: Mon, 21 Jul 2025 15:32:19 +0200 Subject: [PATCH 28/33] Rename variable for clarity. --- scripts/notify_team_new_comment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/notify_team_new_comment.js b/scripts/notify_team_new_comment.js index 4d04264..f89b171 100644 --- a/scripts/notify_team_new_comment.js +++ b/scripts/notify_team_new_comment.js @@ -70,8 +70,8 @@ module.exports = async ({ github, context, core }) => { }); if (response?.data?.html_url) { core.setOutput('bot_replied', true); - const botReplyMessage = `*[${repo}] <${response.data.html_url}|Bot response sent> on issue: <${issueUrl}|${escapedTitle}>*`; - core.setOutput('slack_notification_bot_comment', botReplyMessage); + const slackMessage = `*[${repo}] <${response.data.html_url}|Bot response sent> on issue: <${issueUrl}|${escapedTitle}>*`; + core.setOutput('slack_notification_bot_comment', slackMessage); } } catch (error) { core.warning(`Failed to post bot comment: ${error.message}`); From 3437b1bb06610f547cb32f46b48a625a8d32da5a Mon Sep 17 00:00:00 2001 From: Michaela Robosova Date: Mon, 21 Jul 2025 15:38:53 +0200 Subject: [PATCH 29/33] Re-organize workflow to align with the emerging patterns and structures of other newer workflows. --- .../workflows/call-contributor-issue-comment.yml | 14 ++++++++++++++ ...w_comment.yml => contributor-issue-comment.yml} | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/call-contributor-issue-comment.yml rename .github/workflows/{notify_team_new_comment.yml => contributor-issue-comment.yml} (95%) diff --git a/.github/workflows/call-contributor-issue-comment.yml b/.github/workflows/call-contributor-issue-comment.yml new file mode 100644 index 0000000..4e8b7db --- /dev/null +++ b/.github/workflows/call-contributor-issue-comment.yml @@ -0,0 +1,14 @@ +name: Handle contributor comment on GitHub issue + +on: + issue_comment: + types: [created] + +jobs: + call-workflow: + uses: learningequality/.github/.github/workflows/contributor-issue-comment.yml@main + secrets: + LE_BOT_APP_ID: ${{ secrets.LE_BOT_APP_ID }} + LE_BOT_PRIVATE_KEY: ${{ secrets.LE_BOT_PRIVATE_KEY }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL: ${{ secrets.SLACK_COMMUNITY_NOTIFICATIONS_WEBHOOK_URL }} diff --git a/.github/workflows/notify_team_new_comment.yml b/.github/workflows/contributor-issue-comment.yml similarity index 95% rename from .github/workflows/notify_team_new_comment.yml rename to .github/workflows/contributor-issue-comment.yml index 6523d72..2f78fa0 100644 --- a/.github/workflows/notify_team_new_comment.yml +++ b/.github/workflows/contributor-issue-comment.yml @@ -1,4 +1,4 @@ -name: Send a slack notification when a contributor comments on issue +name: Handle contributor comment on GitHub issue on: workflow_call: @@ -18,8 +18,8 @@ on: jobs: - contributor_issue_comment: - name: Contributor issue comment + process-issue-comment: + name: Process issue comment if: >- ${{ From a45a3ad9931fa0e4a3b0ddb01e0efa0c524a4487 Mon Sep 17 00:00:00 2001 From: Michaela Robosova Date: Mon, 21 Jul 2025 15:40:06 +0200 Subject: [PATCH 30/33] Add close contributors --- scripts/constants.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/constants.js b/scripts/constants.js index c08f231..f5a9a6e 100644 --- a/scripts/constants.js +++ b/scripts/constants.js @@ -1,5 +1,9 @@ const LE_BOT_USERNAME = 'learningequality[bot]'; -const CLOSE_CONTRIBUTORS = ['user1', 'user2']; + +// close contributors are treated a bit special in some workflows, +// for example, we receive a high priority notification about their +// comments on all issues rather than just on 'help wanted' issues +const CLOSE_CONTRIBUTORS = ['BabyElias', 'Dimi20cen', 'EshaanAgg', 'GarvitSinghal47', 'habibayman', 'iamshobhraj', 'indirectlylit', 'Jakoma02', 'KshitijThareja', 'muditchoudhary', 'nathanaelg16', 'nikkuAg', 'Sahil-Sinha-11', 'shivam-daksh', 'shruti862', 'thesujai', 'WinnyChang']; const KEYWORDS_DETECT_ASSIGNMENT_REQUEST = [ 'assign', 'assigned', From 734b989bf05445eac539438c2a40f377449b2a20 Mon Sep 17 00:00:00 2001 From: Michaela Robosova Date: Mon, 21 Jul 2025 15:41:21 +0200 Subject: [PATCH 31/33] Reference learningequality org --- .github/workflows/contributor-issue-comment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/contributor-issue-comment.yml b/.github/workflows/contributor-issue-comment.yml index 2f78fa0..3d77c23 100644 --- a/.github/workflows/contributor-issue-comment.yml +++ b/.github/workflows/contributor-issue-comment.yml @@ -42,7 +42,7 @@ jobs: - name: Checkout .github repository uses: actions/checkout@v4 with: - repository: testiamshobh/.github + repository: learningequality/.github ref: main token: ${{ steps.generate-token.outputs.token }} From 67ea64b80e5da8832b348732413c2ff7b0dd32bd Mon Sep 17 00:00:00 2001 From: Michaela Robosova Date: Mon, 21 Jul 2025 15:47:53 +0200 Subject: [PATCH 32/33] Fix bot name --- scripts/constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/constants.js b/scripts/constants.js index f5a9a6e..0033d1e 100644 --- a/scripts/constants.js +++ b/scripts/constants.js @@ -1,4 +1,4 @@ -const LE_BOT_USERNAME = 'learningequality[bot]'; +const LE_BOT_USERNAME = 'learning-equality-bot[bot]'; // close contributors are treated a bit special in some workflows, // for example, we receive a high priority notification about their From 8aceb703b454e664bc168755937e944120785067 Mon Sep 17 00:00:00 2001 From: Michaela Robosova Date: Mon, 21 Jul 2025 15:48:41 +0200 Subject: [PATCH 33/33] Rename script to align it with the new workflow name. --- .github/workflows/contributor-issue-comment.yml | 2 +- ...{notify_team_new_comment.js => contributor-issue-comment.js} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename scripts/{notify_team_new_comment.js => contributor-issue-comment.js} (100%) diff --git a/.github/workflows/contributor-issue-comment.yml b/.github/workflows/contributor-issue-comment.yml index 3d77c23..c26bd48 100644 --- a/.github/workflows/contributor-issue-comment.yml +++ b/.github/workflows/contributor-issue-comment.yml @@ -60,7 +60,7 @@ jobs: with: github-token: ${{ steps.generate-token.outputs.token }} script: | - const script = require('./scripts/notify_team_new_comment.js'); + const script = require('./scripts/contributor-issue-comment.js'); return await script({github, context, core}); env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/scripts/notify_team_new_comment.js b/scripts/contributor-issue-comment.js similarity index 100% rename from scripts/notify_team_new_comment.js rename to scripts/contributor-issue-comment.js