diff --git a/.github/workflows/getLabels.js b/.github/workflows/getLabels.js new file mode 100644 index 000000000000..2f8a21bae6fa --- /dev/null +++ b/.github/workflows/getLabels.js @@ -0,0 +1,17 @@ +/** + * To run this file: + * * npm install @octokit/rest + * * node .github/workflows/getLabels.js + */ + +const { Octokit } = require('@octokit/rest'); +const github = new Octokit(); +github.rest.issues + .listLabelsForRepo({ + owner: 'microsoft', + repo: 'vscode-python', + }) + .then((result) => { + const labels = result.data.map((label) => label.name); + console.log(JSON.stringify(labels)); + }); diff --git a/.github/workflows/issue-labels.yml b/.github/workflows/issue-labels.yml index d743d437428a..20f061828cbe 100644 --- a/.github/workflows/issue-labels.yml +++ b/.github/workflows/issue-labels.yml @@ -4,13 +4,18 @@ on: issues: types: [opened, reopened] +env: + # To update the list of labels, see `getLabels.js`. + REPO_LABELS: '["area-data science","area-debugging","area-diagnostics","area-editor-*","area-environments","area-formatting","area-intellisense","area-internal","area-linting","area-terminal","area-testing","author-verification-requested","bug","community ask","debt","dependencies","documentation","experimenting","feature-request","good first issue","help wanted","important","info-needed","invalid-testplan-item","investigating","iteration-candidate","iteration-plan","iteration-plan-draft","javascript","linux"]' + TRIAGERS: '["karrtikr","karthiknadig","paulacamargo25","eleanorjboyd"]' + permissions: issues: write jobs: # From https://github.com/marketplace/actions/github-script#apply-a-label-to-an-issue. add-classify-label: - name: "Add 'triage-needed'" + name: "Add 'triage-needed' and remove unrecognizable labels & assignees" runs-on: ubuntu-latest steps: - uses: actions/github-script@v6 @@ -37,3 +42,28 @@ jobs: } else { console.log('This issue already has a "needs __", "iteration-plan", "release-plan", or the "testplan-item" label, do not add the "triage-needed" label.') } + const knownLabels = ${{ env.REPO_LABELS }} + const knownTriagers = ${{ env.TRIAGERS }} + for( const label of labels) { + if (!knownLabels.includes(label)) { + await github.rest.issues.deleteLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: label, + }) + } + } + const currentAssignees = await github.rest.issues + .get({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }) + .then((result) => result.data.assignees.map((a) => a.login)); + const assigneesToRemove = currentAssignees.filter(a => !knownTriagers.includes(a)); + github.rest.issues.removeAssignees({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + assignees: assigneesToRemove, + });