.github: Get PR number from sha
Sadly `github.event.workflow_run.pull_requests` is empty if the pull request was opened from another fork. Use the sha to find an open PR, otherwise assume it's a branch.
This commit is contained in:
parent
1c9fd1cf99
commit
706e1ce243
1 changed files with 17 additions and 8 deletions
25
.github/workflows/trigger-gitlab.yml
vendored
25
.github/workflows/trigger-gitlab.yml
vendored
|
|
@ -17,22 +17,31 @@ jobs:
|
||||||
- name: Report status
|
- name: Report status
|
||||||
uses: haya14busa/action-workflow_run-status@v1
|
uses: haya14busa/action-workflow_run-status@v1
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt install -y jq
|
||||||
|
|
||||||
- name: Clone repository
|
- name: Clone repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.workflow_run.head_sha }}
|
ref: ${{ github.event.workflow_run.head_sha }}
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
# If the parent workflow belongs to a PR, create a new PR-# branch
|
- uses: octokit/request-action@v2.x
|
||||||
- name: Checkout branch (PR)
|
id: fetch_pulls
|
||||||
if: ${{ github.event.workflow_run.pull_requests[0] != null }}
|
env:
|
||||||
run: |
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
git checkout -b PR-${{ github.event.workflow_run.pull_requests[0].number }}
|
with:
|
||||||
|
route: GET /repos/${{ github.repository }}/pulls
|
||||||
|
|
||||||
- name: Checkout branch (branch)
|
- name: Checkout branch
|
||||||
if: ${{ github.event.workflow_run.pull_requests[0] == null }}
|
|
||||||
run: |
|
run: |
|
||||||
git checkout ${{ github.event.workflow_run.head_branch }}
|
PR=$(echo '${{ steps.fetch_pulls.outputs.data }}' | jq -rc '.[] | select(.head.sha | contains("${{ github.event.workflow_run.head_sha }}")) | select(.state | contains("open"))' | jq -r .number)
|
||||||
|
if [ ! -z "$PR" ]; then
|
||||||
|
git checkout -b PR-$PR
|
||||||
|
else
|
||||||
|
git checkout ${{ github.event.workflow_run.head_branch }}
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Push to gitlab
|
- name: Push to gitlab
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue