Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 3

Labeled action on pull_request

Solved! Go to Solution.

For the life of me I cannot figure this out. What exactly is value of github.event.pull_request.labels? Based on the developer guide, it should be an array of objects, but here, it prints Array, and no matter how I try to loop it in Bash, it prints Array. Is it literally the string "Array"? So how do I find out specific labels that have been applied to a specific pull request? 

 

name: test

on:
  pull_request:
    branches:
      - master
    types: [labeled]

jobs:
  build:
    runs-on: ubuntu-latest
    
    steps:
    - name: current branch
      run: |
        array = ${{ github.event.pull_request.labels }}
        echo "${array[*]}"
2 Replies
Solution
Pilot Lvl 1
Message 2 of 3

Re: Labeled action on pull_request

If you use this step to output the entire github context you can see what the JSON looks like.

      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"

 

I ran it for a PR with two labels and the context output looks like this.

    "labels": [
      {
        "color": "ededed",
        "default": false,
        "id": 1579077344,
        "name": "automated pr",
        "node_id": "MDU6TGFiZWwxNTc5MDc3MzQ0",
        "url": "https://api.github.com/repos/peter-evans/actions-playground/labels/automated%20pr"
      },
      {
        "color": "ededed",
        "default": false,
        "id": 1441562142,
        "name": "report",
        "node_id": "MDU6TGFiZWwxNDQxNTYyMTQy",
        "url": "https://api.github.com/repos/peter-evans/actions-playground/labels/report"
      }
    ],
Copilot Lvl 3
Message 3 of 3

Re: Labeled action on pull_request

Thanks... I've been trying so hard to loop it as is but to no avail. Do I have to run toJSON() to be able to interact with it? Even the normal bash syntax to access the values such as `array[0]` prints `Array[0]`.