Skip to content

Commit

Permalink
ci: Auto Label (#142)
Browse files Browse the repository at this point in the history
* ci: Auto lgtm

* fix: script

* fix: consts

* ci: Auto labeler action

* fix: on

* fix: Added more triggers

* fix: feat trigger

* ci: size labels

* fix: More tests

* docs: remove to add

* docs: Updated labeler

* fix: Added default

* fix: Removed line

* fix: labeler

* fix: prints

* fix: Script

* fix: scri[pt

* ci: Added prints

* ci: More prints

* ci: Added echo 0

* ci: Fixed condition

* fix: condition

* fix: Removed unused lines

* fix: Removed more prints

* ci: Lgtm

* fix: condition
  • Loading branch information
Josephasafg authored Jun 19, 2024
1 parent f2d06fc commit b59407c
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Add 'Documentation' label to any change to .md files within the entire repository
documentation:
- changed-files:
- any-glob-to-any-file: "**/*.md"

# Add 'feature' label to any PR where the head branch name starts with `feature` or has a `feature` section in the name
feature:
- head-branch: ["^feat", "feat:"]

# Add 'release' label to any PR that is opened against the `main` branch
fix:
- head-branch: ["^bugfix", "fix:"]

ci:
- head-branch: ["^ci", "ci:"]
- changed-files:
- any-glob-to-any-file:
- .github/*
90 changes: 90 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: "Pull Request Labeler"
on:
pull_request_review:
types: [submitted]
pull_request_review_comment:
types: [created, deleted]
pull_request:
types: [opened, edited, reopened, synchronize]

jobs:
labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Labeler
uses: actions/labeler@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Fetch all branches
run: git fetch --all

- name: Determine base and head branches
id: branches
run: |
base_branch=$(jq -r '.pull_request.base.ref' "$GITHUB_EVENT_PATH")
head_branch=$(jq -r '.pull_request.head.ref' "$GITHUB_EVENT_PATH")
echo $base_branch
echo $head_branch
echo "base_branch=$base_branch" >> $GITHUB_ENV
echo "head_branch=$head_branch" >> $GITHUB_ENV
- name: Calculate diff size
id: diff
run: |
base_branch=${{ env.base_branch }}
head_branch=${{ env.head_branch }}
echo $base_branch
echo $head_branch
git checkout $head_branch
git fetch origin $base_branch
diff_output=$(git diff --shortstat origin/$base_branch...$head_branch)
echo $diff_output
insertions=$(echo $diff_output | awk '{print ($4 == "" ? 0 : $4)}')
deletions=$(echo $diff_output | awk '{print ($6 == "" ? 0 : $6)}')
changed_lines=$((insertions + deletions))
echo $changed_lines
echo "changed_lines=$changed_lines" >> $GITHUB_ENV
- name: Determine label
id: label
run: |
changed_lines=${{ env.changed_lines }}
if [ "$changed_lines" -le 9 ]; then
label="size:s"
elif [ "$changed_lines" -le 50 ]; then
label="size:m"
elif [ "$changed_lines" -le 100 ]; then
label="size:l"
elif [ "$changed_lines" -le 500 ]; then
label="size:xl"
else
label="size:xxl"
fi
echo "label=$label" >> $GITHUB_ENV
- name: Add label to PR
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.label }}

add_lgtm_label:
runs-on: ubuntu-latest
if: github.event.review.state == 'APPROVED'

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Add LGTM label
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: lgtm

0 comments on commit b59407c

Please sign in to comment.