From 66b939da37da60e8ddfdfbfe64da71229abad591 Mon Sep 17 00:00:00 2001 From: "Felix T.J. Dietrich" Date: Sun, 11 Aug 2024 20:50:15 +0200 Subject: [PATCH] Add PR workflows for assigning PR author and labeling (#48) --- .github/labeler.yml | 21 +++++++++++ .github/workflows/pr-labeler.yml | 56 ++++++++++++++++++++++++++++++ .github/workflows/pull-request.yml | 11 ++++++ 3 files changed, 88 insertions(+) create mode 100644 .github/labeler.yml create mode 100644 .github/workflows/pr-labeler.yml create mode 100644 .github/workflows/pull-request.yml diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 00000000..34193423 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,21 @@ +documentation: + - changed-files: + - any-glob-to-any-file: docs/** + +client: + - changed-files: + - any-glob-to-any-file: webapp/** + +application-server: + - changed-files: + - any-glob-to-any-file: server/application-server/** + +intelligence-service: + - changed-files: + - any-glob-to-any-file: "server/intelligence-service/**" + +feature: + - head-branch: ['^feature', 'feature', '^feat', 'feat'] + +bug: + - head-branch: ['^fix', 'fix', '^bug', 'bug'] \ No newline at end of file diff --git a/.github/workflows/pr-labeler.yml b/.github/workflows/pr-labeler.yml new file mode 100644 index 00000000..a9915bff --- /dev/null +++ b/.github/workflows/pr-labeler.yml @@ -0,0 +1,56 @@ +name: "Pull Request Labeler" +on: + pull_request_target: + +jobs: + labeler: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/labeler@v5 + with: + configuration-path: .github/labeler.yml + + - name: Calculate the PR size + uses: actions/github-script@v7 + id: calculate-size + with: + script: | + const diff = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + mediaType: { + format: "diff", + }, + }); + + const changedLines = diff.data + .split("\n") + .filter(line => line.startsWith('+') || line.startsWith('-')) + .length; + + let label = ''; + if (changedLines > 1000) label = 'size:XXL'; + else if (changedLines > 499) label = 'size:XL'; + else if (changedLines > 99) label = 'size:L'; + else if (changedLines > 29) label = 'size:M'; + else if (changedLines > 9) label = 'size:S'; + else label = 'size:XS'; + + return label; + + - name: Apply size label + uses: actions/github-script@v7 + if: steps.calculate-size.outputs.result + with: + script: | + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + labels: [ "${{steps.calculate-size.outputs.result}}" ] + }) + diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 00000000..dd87882d --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,11 @@ +on: + pull_request: + types: [opened] +name: Pull Request +jobs: + assignAuthor: + name: Assign author to PR + runs-on: ubuntu-latest + steps: + - name: Assign author to PR + uses: technote-space/assign-author@v1 \ No newline at end of file