A bash script that helps create your PRs. It normalizes the PR title, description, assignee by default, and initial label based on your branch name.
- GitHub requires https://cli.github.com/
- GitLab requires https://docs.gitlab.com/ee/editor_extensions/gitlab_cli/
These are needed to access your client via the terminal, and they are independent of this script.
Any additional argument will be passed to gh
or glab
tool.
# Create a draft PR
./create-pr --draft
# Create a draft PR with an overridden title
./create-pr --draft --title="Custom Title"
- GitHub: https://cli.github.com/manual/gh_pr_create
- GitLab: https://gitlab.com/gitlab-org/cli/-/blob/main/docs/source/mr/create.md
You can download the latest single executable script
on the Releases page or build it yourself.
If you download the executable file from a release's GitHub project, you can check the file's checksum to validate that it was not altered. The checksum for each release is on each release on GitHub.
To build the project yourself, execute the script ./build.sh
and move the resulting bin/create-pr
script wherever you want.
The script is customizable via .env
variables. See .env.example.
Define the path to locate the PR template. See template example.
PR_TEMPLATE_PATH=.github/PULL_REQUEST_TEMPLATE.md
{{ TICKET_LINK }}
- Uses
PR_TICKET_LINK_PREFIX
appending the ticket key and number to form the full URL
- Uses
{{ BACKGROUND }}
- if the link is found:
Details in the ticket
- if the link is not found:
Provide some context to the reviewer before jumping in the code
- if the link is found:
- You can define them inside a comment (to avoid rendering the placeholders when creating a PR without this script)
- eg
<!-- {{ TICKET_LINK }} -->
- eg
Text to display if the link does not contain a TICKET_KEY
.
Branch name: feat/27-my-branch-name
PR_TICKET_LINK_PREFIX="https://github.com/Chemaclass/create-pr/issues/"
PR_LINK_PREFIX_TEXT="Closes: "
- Result:
Closes: https://github.com/Chemaclass/create-pr/issues/27
Enable custom PR title with placeholders:
{{TICKET_NUMBER}}
{{TICKET_KEY}}
{{PR_TITLE}}
PR_TITLE_TEMPLATE="{{TICKET_KEY}}-{{TICKET_NUMBER}} {{PR_TITLE}}"
Alias: LABEL
Define a label for the PR.
PR_LABEL=enhancement
If empty, extract the label from the branch's prefix - see PR_LABEL_MAPPING
.
Define a mapping from prefix branches to GitHub label.
PR_LABEL_MAPPING="docs:documentation; fix|bug|bugfix|hotfix:bug; default:enhancement"
- eg
docs/your-branch
->documentation
label - eg
fix/your-branch
->bug
label - eg
bug/your-branch
->bug
label - eg
unknown/your-branch
->enhancement
label
Alias: ASSIGNEE
PR_ASSIGNEE
or@me
by default
BASE_BRANCH
ormain
by default
- Add to your composer, npm or similar a script pointing to the
create-pr
- You can use the PULL_REQUEST_TEMPLATE from this project as example
Suggestions, ideas and PRs are more than welcome here! Please, Check out our CONTRIBUTING.md guidelines.