0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-30 19:41:46 +01:00
posthog/.github/actions/get-pr-labels/action.yml

52 lines
1.8 KiB
YAML

name: 'Get merged pull request labels'
shell: bash
description: 'Get the labels of the PR that was merged to create this push event'
inputs:
token:
description: 'GH token'
required: true
outputs:
labels:
description: 'JSON array labels of the PR that was merged (if any)'
value: ${{ steps.labels.outputs.labels }}
runs:
using: 'composite'
steps:
- name: Get PR associated with the last commit
id: pr-info
uses: octokit/request-action@v2.x
with:
route: GET /repos/${{ github.repository }}/commits/${{ github.sha }}/pulls
env:
GITHUB_TOKEN: ${{ inputs.token }}
- name: Extract PR number
shell: bash
if: steps.pr-info.outputs.data
id: extract-pr
continue-on-error: true
run: |
echo "PR_NUMBER=$(cat | jq -r '.[-1].number' <<EOF
${{ toJSON(fromJSON(steps.pr-info.outputs.data)) }}
EOF
)" >> $GITHUB_OUTPUT
- name: Fetch PR Labels
shell: bash
id: labels
run: |
PR_NUMBER=${{ steps.extract-pr.outputs.PR_NUMBER }}
if [ -z "${PR_NUMBER}" ] || [ "${PR_NUMBER}" = "null" ]; then
echo labels="[]" >> $GITHUB_OUTPUT
exit 0
fi
LABELS=$(curl \
-H "Authorization: Bearer ${{ inputs.token }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/$PR_NUMBER/labels | jq -rc '[.[].name]')
echo "Labels of PR #$PR_NUMBER: $LABELS"
echo labels="$LABELS" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ inputs.token }}