Use labeler, size-labeler

This commit is contained in:
shamoon 2025-04-19 16:12:10 -07:00
parent 828ef2ca9c
commit e63907cb88
2 changed files with 47 additions and 72 deletions

22
.github/labeler.yml vendored Normal file
View File

@ -0,0 +1,22 @@
backend:
- changed-files:
- any-glob-to-any-file:
- 'src/**'
- 'pyproject.toml'
- 'uv.lock'
- 'requirements.txt'
frontend:
- changed-files:
- any-glob-to-any-file:
- 'src-ui/**'
documentation:
- changed-files:
- any-glob-to-any-file:
- 'docs/**'
ci-cd:
- changed-files:
- any-glob-to-any-file:
- '.github/**'

View File

@ -1,91 +1,44 @@
name: PR Bot name: PR Bot
on: on:
pull_request: pull_request_target:
types: [opened] types: [opened]
permissions: permissions:
contents: read contents: read
pull-requests: write pull-requests: write
issues: write
jobs: jobs:
label-and-comment: pr-bot:
name: Automated PR Bot
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Label by file path
uses: actions/checkout@v3 uses: actions/labeler@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Get PR Diff - name: Label by size
id: diff uses: Gascon1/pr-size-labeler@v1.3.0
run: | with:
curl -sSL -H "Accept: application/vnd.github.v3.diff" \ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
"${{ github.event.pull_request.url }}" > pr.diff xs_label: 'small-change'
xs_diff: '9'
s_label: 'non-trivial'
s_diff: '99999'
fail_if_xl: 'false'
excluded_files: >
/\.lock$/
/\.txt$/
- name: Determine Labels and Comment - name: Welcome comment
id: label-and-comment if: ${{ !contains(github.actor, 'bot') }}
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
script: | script: |
const fs = require('fs'); const pr = context.payload.pull_request;
const diff = fs.readFileSync('pr.diff', 'utf8'); const user = pr.user.login;
const user = context.payload.pull_request.user.login;
const isBot = user.includes('bot');
const labels = new Set();
let changeCount = 0;
// Simple diff parsing
const files = diff.match(/^diff --git a\/(.+?) b\//gm)?.map(line => line.split(' ')[2]) || [];
for (const file of files) {
if (file.startsWith('src/')) labels.add('backend');
if (file.startsWith('pyproject.toml')) labels.add('backend');
if (file.startsWith('src-ui/')) labels.add('frontend');
if (file.startsWith('docs/')) labels.add('documentation');
if (file.startsWith('.github/')) labels.add('ci-cd');
}
// Change size estimate (added lines > 2 chars, non-docs)
const addedLines = diff.match(/^\+[^+]/gm) || [];
for (const line of addedLines) {
const trimmed = line.slice(1).trim();
if (trimmed.length > 2 && !/\.(md|rst|txt|lock)$/.test(line)) {
changeCount++;
}
}
if (changeCount < 10) labels.add('small-change');
else labels.add('non-trivial');
if (user.includes('dependabot')) {
labels.clear();
labels.add('dependencies');
}
if (user.includes('paperlessngx-bot')) {
labels.add('skip-changelog');
labels.add('translation');
}
core.setOutput('labels', JSON.stringify([...labels]));
core.setOutput('should_comment', (!isBot).toString());
core.setOutput('user', user);
- name: Apply Labels
if: steps.label-and-comment.outputs.labels != '[]'
run: |
gh pr edit ${{ github.event.pull_request.number }} \
--add-label $(echo '${{ steps.label-and-comment.outputs.labels }}' | jq -r '. | join(",")')
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Comment on PR
if: steps.label-and-comment.outputs.should_comment == 'true'
uses: actions/github-script@v7
with:
script: |
const user = '${{ steps.label-and-comment.outputs.user }}';
const body = ` const body = `
Hello @${user}, Hello @${user},
@ -95,7 +48,7 @@ jobs:
This is what will happen next: This is what will happen next:
1. CI tests will run against your PR to ensure quality and consistency. 1. CI tests will run against your PR to ensure quality and consistency.
2. Next, human contributors from paperless-ngx review your changes. ${reviewNote} 2. Next, human contributors from paperless-ngx review your changes.
3. Please address any issues that come up during the review as soon as you are able to. 3. Please address any issues that come up during the review as soon as you are able to.
4. If accepted, your pull request will be merged into the \`dev\` branch and changes there will be tested further. 4. If accepted, your pull request will be merged into the \`dev\` branch and changes there will be tested further.
5. Eventually, changes from you and other contributors will be merged into \`main\` and a new release will be made. 5. Eventually, changes from you and other contributors will be merged into \`main\` and a new release will be made.
@ -104,7 +57,7 @@ jobs:
`; `;
await github.rest.issues.createComment({ await github.rest.issues.createComment({
issue_number: context.issue.number, issue_number: pr.number,
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
body, body,