forked from TheWrightServer/ProxmoxVE
Add autolabeler github workflow (#247)
This commit is contained in:
parent
e3345f6d7b
commit
f12b97c383
71
.github/autolabeler-config.json
vendored
Normal file
71
.github/autolabeler-config.json
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
|
||||
{
|
||||
"breaking change": [
|
||||
{
|
||||
"fileStatus": "renamed",
|
||||
"includeGlobs": ["ct/**", "install/**", "misc/**", "turnkey/**", "vm/**"],
|
||||
"excludeGlobs": []
|
||||
},
|
||||
{
|
||||
"fileStatus": "removed",
|
||||
"includeGlobs": ["ct/**", "install/**", "misc/**", "turnkey/**", "vm/**"],
|
||||
"excludeGlobs": []
|
||||
}
|
||||
],
|
||||
"new script": [
|
||||
{
|
||||
"fileStatus": "added",
|
||||
"includeGlobs": ["ct/**", "install/**", "misc/**", "turnkey/**", "vm/**"],
|
||||
"excludeGlobs": []
|
||||
}
|
||||
],
|
||||
"update script": [
|
||||
{
|
||||
"fileStatus": "modified",
|
||||
"includeGlobs": ["ct/**", "install/**", "misc/**", "turnkey/**", "vm/**"],
|
||||
"excludeGlobs": ["misc/build.func", "misc/install.func"]
|
||||
}
|
||||
],
|
||||
"delete script": [
|
||||
{
|
||||
"fileStatus": "removed",
|
||||
"includeGlobs": ["ct/**", "install/**", "misc/**", "turnkey/**", "vm/**"],
|
||||
"excludeGlobs": []
|
||||
}
|
||||
],
|
||||
"rename script": [
|
||||
{
|
||||
"fileStatus": "renamed",
|
||||
"includeGlobs": ["ct/**", "install/**", "misc/**", "turnkey/**", "vm/**"],
|
||||
"excludeGlobs": []
|
||||
}
|
||||
],
|
||||
"frontend": [
|
||||
{
|
||||
"fileStatus": null,
|
||||
"includeGlobs": ["frontend/**"],
|
||||
"excludeGlobs": []
|
||||
}
|
||||
],
|
||||
"documentation": [
|
||||
{
|
||||
"fileStatus": null,
|
||||
"includeGlobs": ["json/**"],
|
||||
"excludeGlobs": []
|
||||
}
|
||||
],
|
||||
"maintenance": [
|
||||
{
|
||||
"fileStatus": null,
|
||||
"includeGlobs": ["*.md", ".github/**"],
|
||||
"excludeGlobs": []
|
||||
}
|
||||
],
|
||||
"high risk": [
|
||||
{
|
||||
"fileStatus": null,
|
||||
"includeGlobs": ["misc/build.func", "misc/install.func"],
|
||||
"excludeGlobs": []
|
||||
}
|
||||
]
|
||||
}
|
65
.github/workflows/autolabeler.yml
vendored
Normal file
65
.github/workflows/autolabeler.yml
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
name: Auto Label Pull Requests
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
branches: ["main"]
|
||||
types: [opened, synchronize, reopened, edited]
|
||||
|
||||
jobs:
|
||||
autolabeler:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: write
|
||||
env:
|
||||
CONFIG_PATH: .github/autolabeler-config.json
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install minimatch
|
||||
run: npm install minimatch
|
||||
|
||||
- name: Label PR based on config rules
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs').promises;
|
||||
const path = require('path');
|
||||
const { minimatch } = require('minimatch');
|
||||
|
||||
const configPath = path.resolve(process.env.CONFIG_PATH);
|
||||
const fileContent = await fs.readFile(configPath, 'utf-8');
|
||||
const autolabelerConfig = JSON.parse(fileContent);
|
||||
|
||||
const prNumber = context.payload.pull_request.number;
|
||||
const prListFilesResponse = await github.rest.pulls.listFiles({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: prNumber,
|
||||
});
|
||||
const prFiles = prListFilesResponse.data;
|
||||
|
||||
for (const [label, rules] of Object.entries(autolabelerConfig)) {
|
||||
const shouldAddLabel = prFiles.some((prFile) => {
|
||||
return rules.some((rule) => {
|
||||
const isFileStatusMatch = rule.fileStatus ? rule.fileStatus === prFile.status : true;
|
||||
const isIncludeGlobMatch = rule.includeGlobs.some((glob) => minimatch(prFile.filename, glob));
|
||||
const isExcludeGlobMatch = rule.excludeGlobs.some((glob) => minimatch(prFile.filename, glob));
|
||||
|
||||
return isFileStatusMatch && isIncludeGlobMatch && !isExcludeGlobMatch;
|
||||
});
|
||||
});
|
||||
|
||||
if (shouldAddLabel) {
|
||||
console.log(`Adding label ${label} to PR ${prNumber}`);
|
||||
await github.rest.issues.addLabels({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: prNumber,
|
||||
labels: [label],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user