Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically add and remove the "info needed" label #20970

Merged
merged 2 commits into from
Apr 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}