Skip to content

Commit

Permalink
Merge pull request #212 from wraith2009/github_Workflow
Browse files Browse the repository at this point in the history
GitHub workflow
  • Loading branch information
cb7chaitanya authored Oct 5, 2024
2 parents 8ebdcd8 + ec8886b commit 7baa451
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/pullreq_size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: 'Label PR Based on Size'

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
label-pr-size:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write


steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up jq (for processing JSON)
run: sudo apt-get install jq

- name: Label PR based on size
run: |
XS_LIMIT=10
SM_LIMIT=50
MD_LIMIT=200
LG_LIMIT=500
LABEL_XS="size-xs"
LABEL_SM="size-sm"
LABEL_MD="size-md"
LABEL_LG="size-lg"
LABEL_XL="size-xl"
GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}"
GITHUB_REPOSITORY="${{ github.repository }}"
PR_NUMBER="${{ github.event.pull_request.number }}"
API_URI="https://api.github.com"
API_HEADER="Accept: application/vnd.github.v3+json"
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
# Function to calculate total lines added and deleted
additions=$(curl -sSL -H "$API_HEADER" -H "$AUTH_HEADER" \
"${API_URI}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" | jq '.additions')
deletions=$(curl -sSL -H "$API_HEADER" -H "$AUTH_HEADER" \
"${API_URI}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" | jq '.deletions')
total_modifications=$((additions + deletions))
# Determine the label based on total changes
if [ "$total_modifications" -lt "$XS_LIMIT" ]; then
label="$LABEL_XS"
elif [ "$total_modifications" -lt "$SM_LIMIT" ]; then
label="$LABEL_SM"
elif [ "$total_modifications" -lt "$MD_LIMIT" ]; then
label="$LABEL_MD"
elif [ "$total_modifications" -lt "$LG_LIMIT" ]; then
label="$LABEL_LG"
else
label="$LABEL_XL"
fi
# Apply the label
curl -sSL -H "$API_HEADER" -H "$AUTH_HEADER" -X POST -d "{\"labels\":[\"$label\"]}" \
"${API_URI}/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 7baa451

Please sign in to comment.