A GitHub Composite Action to automatically create a feature branch from an issue using the GitHub API.
sequenceDiagram
participant User
participant GitHub
participant Workflow
participant Developer
User->>GitHub: Create issue
GitHub->>Developer: Assign issue
GitHub->>Workflow: Trigger workflow
alt Issue type = bug
Workflow->>GitHub: Create branch "bug/<issue-number>"
else Issue type = task or sub-task or feature
Workflow->>GitHub: Create branch "feature/<issue-number>"
else Invalid issue type
Workflow->>GitHub: Fail the workflow and print an error in the summary
end
Developer->>GitHub: Unassign issue
GitHub->>NewDeveloper: Assign issue
GitHub->>Workflow: Trigger workflow
alt Valid issue type
Workflow->>GitHub: Create new branch with suffix (e.g., "bug/<issue-number>-AB12")
else Invalid issue type
Workflow->>GitHub: Fail the workflow and print an error in the summary
end
The repository name must follow the pattern:
<Numeric Project Sequence>-<Project Code>-<Short Description>
Example: 001-PORTAL-dark-mode-support
-
Creates a new branch based on an existing GitHub issue.
-
Builds the branch name using project metadata and a truncated, slugified issue title.
-
Posts a comment on the issue with a link to the new branch.
-
Branch naming format:
<Issue Type>/<Project Code>-<Project Sequence>.<Issue Number>-<Truncated Slugified Title>
Name | Description | Required | Default |
---|---|---|---|
base-branch |
The base branch to create the new branch from. | No | main |
title-length |
Number of characters to keep from issue title. | No | 15 |
github-token |
GitHub token with repo access. | Yes | – |
dry-run |
Simulate the process only without creating branch. | Yes | false |
on:
issues:
types: [opened, assigned]
jobs:
create-feature-branch:
runs-on: ubuntu-latest
permissions:
issues: write
contents: write
steps:
- uses: subhamay-bhattacharyya-gha/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
title-length: 20
Note: This action is triggered by issue events. Be sure your workflow listens to events like
opened
orassigned
.
-
Extracts the issue number and title.
-
Builds the branch name in this format:
<Issue Type>/<Project Code>-<Project Sequence>.<Issue Number>-<Truncated Slugified Title>
-
Uses the GitHub API to create the new branch from the base branch.
-
Comments on the issue with a link to the new branch.
Given:
- Repository:
001-PORTAL-dark-mode-support
- Issue: #123 titled
Add support for dark mode
Generated branch:
feature/PORTAL-001.123-add-support
jq
(used internally for parsing JSON)- A GitHub token with
repo
andissues
permissions
MIT