salt/.github/actions/get-pull-number/action.yml
2023-04-26 15:06:51 -05:00

50 lines
1.2 KiB
YAML

---
name: get-pull-number
description: Get Pull Number
inputs:
owner:
type: string
repo:
type: string
sha:
type: string
pull-number:
default: null
outputs:
number:
value: ${{ steps.get-pull-number.outputs.number }}
runs:
using: composite
steps:
- name: Get Pull Number
id: get-pull-number
shell: bash
env:
GITHUB_OWNER: ${{ inputs.owner }}
GITHUB_REPO: ${{ inputs.repo }}
GITHUB_SHA: ${{ inputs.sha }}
GITHUB_PULL_NUMBER: ${{ inputs.pull-number }}
run: |
echo $GITHUB_OWNER
echo $GITHUB_REPO
echo $GITHUB_SHA
echo $GITHUB_PULL_NUMBER
if [ -z "$GITHUB_PULL_NUMBER" ]
then
echo "Searching For Pull Number"
echo $GITHUB_OWNER
echo $GITHUB_REPO
echo $GITHUB_SHA
pulls=$(gh api repos/$GITHUB_OWNER/$GITHUB_REPO/commits/$GITHUB_SHA/pulls)
echo $pulls
full_name=$GITHUB_OWNER/$GITHUB_REPO
number=$(jq -c --arg r "$full_name" '[.[] | select(.url | contains($r))][0].number' <<< $pulls )
else
echo "Given Pull Number"
number=$GITHUB_PULL_NUMBER
fi
echo $number
echo "number=$number" >> "$GITHUB_OUTPUT"