Skip to content

Automatic PR number detection by using GH CLI #89

@nbali

Description

@nbali

I have seen manual PR number configuration has been added for workflow_dispatch, but it's actually not needed as gh cli can provide that number easily.

$ gh pr status --json 'number,title,url' --jq '.currentBranch'
{
  "number": 123,
  "title": "Dummy PR title",
  "url": "https://github.com/ORG/REPO/pull/123"
}

So this should give back what we need:

$ gh pr status --json 'number' --jq '.currentBranch.number'
123

I'm not sure if/when I will have time to contribute this.

ps.: This works as well.

$ gh pr view --json 'number,title,url'
{
  "number": 123,
  "title": "Dummy PR title",
  "url": "https://github.com/ORG/REPO/pull/123"
}

So

$ gh pr view --json 'number' --jq '.number'
123

BTW this won't provide it only for on: workflow_dispatch, but even on: push can be used now as well. Also pull_request and pull_request_target checks can be replaced, because we can have all the values we have there with push and workflow_dispatch as well.

$ gh pr view --json 'number,headRefOid,headRefName'
{
  "headRefName": "dummy_branch_name",
  "headRefOid": "559d819bfa003066d812151a61ce1ff4ee559c9a",
  "number": 123
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions