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 <teodor.dutu@gmail.com>
  • Loading branch information
teodutu committed Jan 23, 2023
1 parent 12c3b42 commit 75fa935
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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:
- all: ['!content/chapters/**/*']
43 changes: 43 additions & 0 deletions .github/scripts/add-labels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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)
}
}

function createLabelsForPR(github, context) {
getPRFileData(github, context).then((data) => {
var labels = []

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, labels) {
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 ({github, context}) => {
addLabelsToPR(github, context, 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"
}
26 changes: 26 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Pull Request Labeler"
on:
- pull_request_target
on: push

jobs:
triage:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v4
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
sync-labels: true
add-kind-labels:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/github-script@v6
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
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 75fa935

Please sign in to comment.