-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add triage label on communtiy issues
- Loading branch information
Showing
4 changed files
with
88 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Add Triage Label | ||
|
||
on: | ||
issue: | ||
types: [opened] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
check: | ||
name: Verify | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
- name: Install Octokit | ||
run: npm --prefix .github/workflows/scripts install @octokit/action | ||
|
||
- name: Check if user is a community contributor | ||
id: check | ||
run: node .github/workflows/scripts/add-triage-label.js | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const { Octokit } = require('@octokit/action'); | ||
const { isCommunityContributor } = require('./is-community-contributor'); | ||
|
||
const octokit = new Octokit(); | ||
|
||
const getAuthor = (payload) => { | ||
return payload?.issue?.user?.login || payload?.pull_request?.user?.login || null; | ||
}; | ||
|
||
async function start() { | ||
const payload = require(process.env.GITHUB_EVENT_PATH); | ||
if (payload?.pull_request) { | ||
console.log('Skipping pull request execution'); | ||
return; | ||
} | ||
|
||
const username = getAuthor(payload); | ||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/'); | ||
const { number } = payload?.issue || payload?.pull_request; | ||
|
||
const isCommunityUser = await isCommunityContributor(owner, repo, username); | ||
console.log('::set-output name=is-community::%s', isCommunityUser ? 'yes' : 'no'); | ||
|
||
if (isCommunityUser) { | ||
await addLabel('triage', owner, repo, number); | ||
} | ||
} | ||
|
||
const addLabel = async (label, owner, repo, issueNumber) => { | ||
await octokit.rest.issues.addLabels({ | ||
owner, | ||
repo, | ||
issue_number: issueNumber, | ||
labels: [label], | ||
}); | ||
}; | ||
|
||
start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { Octokit } = require('@octokit/action'); | ||
|
||
const octokit = new Octokit(); | ||
|
||
const isCommunityContributor = async (owner, repo, username) => { | ||
if (!username) return false; | ||
|
||
const { | ||
data: { permission }, | ||
} = await octokit.rest.repos.getCollaboratorPermissionLevel({ | ||
owner, | ||
repo, | ||
username, | ||
}); | ||
|
||
return permission === 'read' || permission === 'none'; | ||
}; | ||
|
||
module.exports = { | ||
isCommunityContributor, | ||
}; |