Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic PR labelling action #109

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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/**/*'

area/assignment:
- assignments/**/*
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"
}
25 changes: 25 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "Pull Request Labeler"

on:
schedule:
- cron: "*/5 * * * *"

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