Skip to content

Commit

Permalink
Added automatic labeler system (#2670)
Browse files Browse the repository at this point in the history
* Create pull_request_opened.yml

Add Pull Request Labeler.

* Add Labeler configuratino

* Update labeler.yml

* Update pull_request_opened.yml

* Erm, skill Issue

* Added transpiler detection support.

* Create pull_request_reviewed.yml (#8)

This adds a `approved` label to PRs which have been approved by reviewers.

* bye bye

💥

* Update pull_request_opened.yml

* Update pull_request_opened.yml

---------

Co-authored-by: Nao <[email protected]>
  • Loading branch information
iamalexrouse and NaoUnderscore authored Jul 12, 2024
1 parent b1db1ec commit 68fb494
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Documentation:
- changed-files:
- any-glob-to-any-file: docs/**

NuGet:
- changed-files:
- any-glob-to-any-file: '**/*.nuspec'

Scripts: # Add the 'Scripts' label
- changed-files:
- any-glob-to-any-file: '**/*.ps1' # Windows
- any-glob-to-any-file: '**/*.sh' # Linux

regarding-events: # Add the 'Events' label
- changed-files:
- any-glob-to-any-file: Exiled.Events/** # Any Modifications to events

regarding-api: # Add the 'API' label
- changed-files:
- any-glob-to-any-file: Exiled.API/** # Any modifications to the API

regarding-transpiler: # Add the 'transpiler' label
- changed-files:
- any-glob-to-any-file: Exiled.Events/Patches/**/* # Any modifications to transpiler files

CustomModules: # Add the 'CustomModules' label
- changed-files:
- any-glob-to-any-file: Exiled.CustomModules/** # Any modifications to CustomModules

Installer: # Add the 'Installer' label
- changed-files:
- any-glob-to-any-file: Exiled.Installer/** # Any modifications to the Installer

Localization: # Add the 'Localization' label
- changed-files:
- any-glob-to-any-file: Localization/** # Any modifications to Localization

GitHub_Actions: # Add the 'GitHub' label
- changed-files:
- any-glob-to-any-file: .github/** # Any modifications to github related files

75 changes: 75 additions & 0 deletions .github/workflows/pull_request_opened.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Pull Request Opened

on:
pull_request:
types:
- opened
- labeled
- unlabeled
workflow_dispatch:

jobs:
set-labels:
runs-on: ubuntu-latest
steps:
- name: Labeler
uses: actions/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/labeler.yml
sync-labels: true

update-pr-title:
runs-on: ubuntu-latest
needs: set-labels
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Get PR Info
id: get_pr
uses: octokit/[email protected]
with:
route: GET /repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Update PR Title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_TITLE=$(jq -r '.title' <<<"${{ steps.get_pr.outputs.data }}")
PR_LABELS=$(jq -r '.labels | map(.name) | join(",")' <<<"${{ steps.get_pr.outputs.data }}")
PREFIX=""
if [[ "$PR_LABELS" == *"Documentation"* ]]; then
PREFIX="[Docs]"
elif [[ "$PR_LABELS" == *"NuGet"* ]]; then
PREFIX="[NuGet]"
elif [[ "$PR_LABELS" == *"Scripts"* ]]; then
PREFIX="[Scripts]"
elif [[ "$PR_LABELS" == *"regarding-events"* ]]; then
PREFIX="[Events]"
elif [[ "$PR_LABELS" == *"regarding-api"* ]]; then
PREFIX="[API]"
elif [[ "$PR_LABELS" == *"regarding-transpiler"* ]]; then
PREFIX="[Transpiler]"
elif [[ "$PR_LABELS" == *"CustomModules"* ]]; then
PREFIX="[CustomModules]"
elif [[ "$PR_LABELS" == *"Installer"* ]]; then
PREFIX="[Installer]"
elif [[ "$PR_LABELS" == *"Localization"* ]]; then
PREFIX="[Localization]"
elif [[ "$PR_LABELS" == *"GitHub_Actions"* ]]; then
PREFIX="[GitHub]"
fi
NEW_TITLE="$PREFIX $PR_TITLE"
if [[ "$NEW_TITLE" != "$PR_TITLE" ]]; then
curl -X PATCH \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} \
-d "{\"title\":\"$NEW_TITLE\"}"
fi

0 comments on commit 68fb494

Please sign in to comment.