skip to Main Content

I’m using github and github actions.
With the actions Create Issue Branch, it’s possible to automatically generate a branch when a user is assigned to the issue/ticket.

This works perfectly! When I have the standard file from the documentation: .github/workflows/create_branch.yml:

on:
  # The issue.opened event below is only needed for the "immediate" mode.
  # The issue.assigned event below is only needed for the default ("auto") mode.
  issues:
    types: [ opened, assigned ]
  # The issue_comment.created event below is only needed for the ChatOps mode.
  issue_comment:
    types: [ created ]
  # The pull_request events below are only needed for pull-request related features.
  pull_request:
    types: [ opened, closed ]

jobs:
  create_issue_branch_job:
    runs-on: ubuntu-latest
    steps:
      - name: Create Issue Branch
      uses: robvanderleek/create-issue-branch@main
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

However I need to pass in the setting branchName: '${issue.number}-${issue.title}' to make a custom branchName .. So far I havn’t been able to find out where.. And in my attempt to pass in the setting, I broke the action.

Where should I put the variable branchName in the `.yml’ file?

2

Answers


  1. Given your current workflow file, to add a custom branchName, I believe you need to modify the Create Issue Branch step to include a with section where you define branchName like this:

    jobs:
      create_issue_branch_job:
        runs-on: ubuntu-latest
        steps:
          - name: Create Issue Branch
            uses: robvanderleek/create-issue-branch@main
            with:
              branchName: '${issue.number}-${issue.title}'
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    

    In a similar setup I have, ${issue.number} and ${issue.title} dynamically insert the issue number and title into the branch name.

    Login or Signup to reply.
  2. This action doesn’t take any inputs provided with with (see their action.yml file).

    Instead, if you want to modify default behaviour, the action checks for a file .github/issue-branch.yml, and that is where you can set the branch name convention like

    branchName: '${issue.number}-${issue.title}'
    

    Notice that you have the indentation wrong in your snippet: uses must not be less indented than name for a step.

    And, not to take away from the creator of the action, but creating a branch seems to be simple enough to do it directly in a run step, something like

    name: Create branch on assignment
    
    on:
      issues:
        types:
          - assigned
    
    jobs:
      createbranch:
        runs-on: ubuntu-22.04
        permissions:
          contents: write
        steps:
          - name: Check out repository
            uses: actions/[email protected]
    
          - name: Create issue branch
            env:
              number: ${{ github.event.issue.number }}
              title: ${{ github.event.issue.title }}
            run: |
              title=${title// /-}
              branchname=$number-${title,,}
              git switch -c "$branchname"
              git config --global user.name 'github-actions'
              git config --global user.email 
                  '41898282+github-actions[bot]@users.noreply.github.com'
              git push -u origin "$branchname"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search