Ask Your Question
4

How can I obtain the pathway that caused a pull request in GitHub Workflow?

asked 2021-10-16 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-02-18 15:00:00 +0000

qstack gravatar image

To obtain the pathway that caused a pull request in GitHub Workflow, you need to use the context of the pull request event. This context contains information about the pull request, including the branch that the pull request was made against.

Here is an example of how to obtain the branch name of the pull request in a GitHub Workflow:

name: My Workflow

on:
  pull_request:
    branches:
      - main

jobs:
  my-job:

    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2
      with:
        ref: ${{ github.event.pull_request.head.ref }}

    - name: Print branch name
      run: echo "Branch name is ${{ github.event.pull_request.head.ref }}"

In this example, the pull_request event is used as a trigger for the workflow. The ref parameter is used to checkout the branch of the pull request, and the github.event.pull_request.head.ref context variable is used to obtain the branch name. This branch name can then be used in subsequent steps of the workflow.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-10-16 11:00:00 +0000

Seen: 2 times

Last updated: Feb 18 '22