Skip to content

Commit

Permalink
Automatically add and remove the "info needed" label (#20970)
Browse files Browse the repository at this point in the history
Closes #20944
  • Loading branch information
Kartik Raj authored and eleanorjboyd committed Apr 6, 2023
1 parent d777aec commit 3970723
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/triage-info-needed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Triage "info-needed" label

on:
issue_comment:
types: [created]

env:
TRIAGERS: '["karrtikr","karthiknadig","paulacamargo25","eleanorjboyd", "brettcannon"]'

jobs:
add_label:
runs-on: ubuntu-latest
if: contains(github.event.issue.labels.*.name, 'triage-needed') && !contains(github.event.issue.labels.*.name, 'info-needed')
env:
KEYWORDS: '["\\?", "please", "kindly", "let me know", "try", "can you", "could you", "would you", "may I", "provide", "let us know", "tell me", "give me", "send me", "what", "when", "where", "why", "how"]'
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check for author
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue = await github.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const commentAuthor = context.payload.comment.user.login;
const commentBody = context.payload.comment.body;
const isTeamMember = ${{ env.TRIAGERS }}.includes(commentAuthor);
const keywords = ${{ env.KEYWORDS }};
const isRequestForInfo = new RegExp(keywords.join('|'), 'i').test(commentBody);
const shouldAddLabel = isTeamMember && commentAuthor !== issue.data.user.login && isRequestForInfo;
if (shouldAddLabel) {
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['info-needed']
});
}
remove_label:
if: contains(github.event.issue.labels.*.name, 'info-needed') && contains(github.event.issue.labels.*.name, 'triage-needed')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check for author
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue = await github.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const commentAuthor = context.payload.comment.user.login;
const issueAuthor = issue.data.user.login;
if (commentAuthor === issueAuthor) {
await github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'info-needed'
});
return;
}
if (${{ env.TRIAGERS }}.includes(commentAuthor)) {
// If one of triagers made a comment, ignore it
return;
}
// Loop through all the comments on the issue in reverse order and find the last username that a TRIAGER mentioned
// If the comment author is the last mentioned username, remove the "info-needed" label
const comments = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
for (const comment of comments.data.slice().reverse()) {
if (!${{ env.TRIAGERS }}.includes(comment.user.login)) {
continue;
}
const matches = comment.body.match(/@\w+/g) || [];
const mentionedUsernames = matches.map(match => match.replace('@', ''));
if (mentionedUsernames.includes(commentAuthor)) {
await github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'info-needed'
});
break;
}
}

0 comments on commit 3970723

Please sign in to comment.