-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #366 from MartinBasti/mark-PR-size
chore(workflow): mark size of PRs
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Pull request size | ||
on: pull_request_target | ||
|
||
jobs: | ||
size-label: | ||
name: Size label | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Calculate size | ||
run: | | ||
#!/usr/bin/bash | ||
set -euo pipefail | ||
additions=$(curl -s "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" | jq '.additions') | ||
deletions=$(curl -s "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" | jq '.deletions') | ||
size=$((additions + deletions)) | ||
sizelabel=XS | ||
if [ ${size} -gt 500 ]; then | ||
sizelabel="XXL" | ||
elif [ ${size} -gt 200 ]; then | ||
sizelabel="XL" | ||
elif [ ${size} -gt 100 ]; then | ||
sizelabel="L" | ||
elif [ ${size} -gt 50 ]; then | ||
sizelabel="M" | ||
elif [ ${size} -gt 30 ]; then | ||
sizelabel="S" | ||
fi | ||
echo "Adding size: ${sizelabel}" | ||
curl -s --fail-with-body -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \ | ||
-d "[\"size: ${sizelabel}\"]" |