Skip to content

test: pr

test: pr #5

Workflow file for this run

name: "Pull Request Labeler"
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: TEST_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: Fetch current labels
id: fetch_labels
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
return labels.map(label => label.name).join(',');
- name: Remove old size labels
id: remove_labels
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const sizeLabels = ['size:s', 'size:m', 'size:l', 'size:xl', 'size:xxl'];
const currentLabels = '${{ steps.fetch_labels.outputs.result }}'.split(',');
const labelsToRemove = currentLabels.filter(label => sizeLabels.includes(label));
console.log("Current labels:", currentLabels);
console.log("Labels to remove:", labelsToRemove);
for (const label of labelsToRemove) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: label,
});
}
- 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