create-pull-request icon indicating copy to clipboard operation
create-pull-request copied to clipboard

allow "branch" to be derived from "base"

Open tamird opened this issue 10 months ago • 2 comments

It would be useful to be able to "namespace" generated pull requests to the branch they target.

Consider the case of code generation: I make some code changes, and I want the bots to run the codegen job and open a PR against my changes - and I want this to happen on all branches. This feature would allow me to express that.

tamird avatar Feb 05 '25 11:02 tamird

Hi @tamird

I'm not sure if I understand this correctly, but do you just want to name PR branches based on the base? If that's the case it should be simple to do in a step before the action runs.

peter-evans avatar Feb 19 '25 08:02 peter-evans

Hi @peter-evans. Maybe there's an obvious and simpler solution, but this is the best I could come up with:

jobs:
  example:
    runs-on: ubuntu-latest

    steps:
      - id: determine-target
        run: |
          if [ "${{ github.event_name }}" = "pull_request" ]; then
            echo "target_branch=${{ github.event.pull_request.base.ref }}" >> $GITHUB_OUTPUT
          else # must be push, i guess?
            echo "target_branch=${{ github.ref_name }}" >> $GITHUB_OUTPUT
          fi

      - uses: peter-evans/create-pull-request@v7
        with:
          branch: "${{ steps.determine-target.outputs.target_branch }}-feature-branch"

My thinking in filing this issue was that there must already be this kind of logic that can find the base branch independent of the type of trigger, so it would be easier to add this there than to push it to the user.

tamird avatar Feb 19 '25 14:02 tamird