Skip to content

Commit

Permalink
infra: Add automatic PR labelling action
Browse files Browse the repository at this point in the history
Signed-off-by: Teodor Dutu <[email protected]>
  • Loading branch information
teodutu committed Jan 23, 2023
1 parent 12c3b42 commit 01056c2
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/labeler.yml
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/**/*'
47 changes: 47 additions & 0 deletions .github/scripts/add-labels.js
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))
}
3 changes: 3 additions & 0 deletions .github/scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
37 changes: 37 additions & 0 deletions .github/workflows/labeler.yml
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})
92 changes: 92 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,95 @@ slides.md

# .gif files generated with ffmpeg
*-generated.gif

# JavaScript files

# compiled output
/dist
/tmp
/out-tsc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# IDEs and editors
.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
.sass-cache
connect.lock
typings

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*


# Dependency directories
node_modules/
jspm_packages/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

# Lerna
lerna-debug.log

# System Files
.DS_Store
Thumbs.db

0 comments on commit 01056c2

Please sign in to comment.