-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
infra: Add automatic PR labelling action
Signed-off-by: Teodor Dutu <[email protected]>
- Loading branch information
Showing
5 changed files
with
206 additions
and
0 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,27 @@ | ||
topic/software-stack: | ||
- content/chapters/software-stack/**/* | ||
|
||
topic/data: | ||
- content/chapters/data/**/* | ||
|
||
topic/compute: | ||
- content/chapters/compute/**/* | ||
|
||
topic/io: | ||
- content/chapters/io/**/* | ||
|
||
topic/app-interact: | ||
- content/chapters/app-interact/**/* | ||
|
||
area/quiz: | ||
- '**/quiz/*' | ||
|
||
area/content: | ||
- any: ['**/lab/content/*.md', '**/media/**/*', '**/lecture/slides/**/*', | ||
'**/*.mdpp'] | ||
|
||
area/code: | ||
- any: ['**/lab/support/**/*', '**/lab/solution/**/*', '**/lecture/demo/**/*'] | ||
|
||
area/infra: | ||
- '!content/chapters/**/*' |
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,47 @@ | ||
async function getPRFileData(github, context) { | ||
return github.request('GET /repos/{owner}/{repo}/pulls/{pull_number}/files', { | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.issue.number | ||
}) | ||
} | ||
|
||
function addLabelToList(labels, label) { | ||
if (!labels.includes(label)) { | ||
labels.push(label) | ||
} | ||
} | ||
|
||
async function createLabelsForPR(github, context) { | ||
var labels = [] | ||
|
||
await getPRFileData(github, context).then((data) => { | ||
data.data.forEach((file) => { | ||
if (file.status === 'added') { | ||
addLabelToList(labels, 'kind/new') | ||
} | ||
else if (file.status === 'modified' && file.deletions === 0 && file.additions > 0) { | ||
addLabelToList(labels, 'kind/improvement') | ||
} | ||
}) | ||
}) | ||
|
||
return labels | ||
} | ||
|
||
function addLabelsToPR(github, context, labels) { | ||
if (labels.length === 0) { | ||
return | ||
} | ||
|
||
github.request('POST /repos/{owner}/{repo}/issues/{issue_number}/labels', { | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number, | ||
labels: labels | ||
}) | ||
} | ||
|
||
export default async ({github, context}) => { | ||
addLabelsToPR(github, context, await createLabelsForPR(github, context)) | ||
} |
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,3 @@ | ||
{ | ||
"type": "module" | ||
} |
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,37 @@ | ||
name: "Pull Request Labeler" | ||
on: [pull_request] | ||
|
||
permissions: | ||
actions: read|write | ||
checks: read|write | ||
contents: read|write | ||
deployments: read|write | ||
id-token: read|write | ||
issues: read|write | ||
discussions: read|write | ||
packages: read|write | ||
pages: read|write | ||
pull-requests: read|write | ||
repository-projects: read|write | ||
security-events: read|write | ||
statuses: read|write | ||
|
||
jobs: | ||
add-topic-area-labels: | ||
name: Add topic and area labels | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/labeler@v4 | ||
with: | ||
repo-token: "${{ secrets.GITHUB_TOKEN }}" | ||
sync-labels: true | ||
add-kind-labels: | ||
name: Add kind labels | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const { default: addLabelsToPR } = await import('${{ github.workspace }}/.github/scripts/add-labels.js') ; | ||
await addLabelsToPR({github, context}) |
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