Streamline your workflow with a CLI tool that integrates Git and Jira. Quickly create, name, and delete branches using the Issue Key, ensuring consistency and efficiency in branch management.
- Seamless Branch Creation: Easily create new Git branches by simply passing the Issue Key into the CLI.
- Integration with Git and Jira: Leverages the Git and Jira APIs to streamline your workflow.
- Automated Branch Naming: Automatically generates branch names based on Jira Ticket Summary, ensuring consistent and meaningful branch names.
- Branch Deletion: Conveniently delete branches directly from the CLI for efficient repository management.
Preferably, start from the step 6 and use the twig-init command to set up your configuration.
- Configure your Jira API and VCS settings in the
twig/config/twig.toml
file.
[project]
host = "example.atlassian.net"
auth = "basic"
email = "[email protected]"
token = "api_token"
NOTE: for
Bearer
auth usebearer
key for auth property!
- Define mappings for your Jira issue types in the configuration the
twig.toml
file. Use zero if you want to ignore a specific type.
[mapping]
build = ["0"]
chore = ["0"]
ci = ["0"]
docs = ["0"]
feat = ["0"]
fix = ["0"]
pref = ["0"]
refactor = ["0"]
revert = ["0"]
style = ["0"]
test = ["0"]
If you have multiple IDs of the same type, separate them with a comma.
[mapping]
build = ["10001", "10002", "10003"]
You can curl
available issuetype
s from Jira.
curl \
-D- \
-X GET \
-u "[email protected]:token" \
-H "Content-Type: application/json" \
https://{host}/rest/api/2/issuetype
or
curl \
-D- \
-X GET \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
https://{host}/rest/api/2/issuetype
- Specify the
default
which will serve as the base when checking out before deleting local branches. Specify theorigin
to be able to delete branches alongside their corresponding local branches. This ensures consistency and avoids issues during cleanup operations.
[branch]
default = "development"
origin = "origin"
- Specify any exclusion phrases to be removed from the branch name, if applicable.
[branch]
exclude = ["front","mobile","android","ios","be","web","spike","eval"]
- Copy
twig/config/twig.toml
file into~/.config/twig/
folder.
mkdir -p ~/.config/twig/ && \
cp twig.toml ~/.config/twig/
- Compile the tool into an executable file or download compiled executable.
NOTE: you might need to apply
chmod +x
to the executable if you've downloaded the precompiled version.
go build
# or produce a smaller binary with ldflags
go build -ldflags="-s -w"
- Move the executable into
/usr/local/bin
for easy global access.
mv twig /usr/local/bin
twig [-h | --help] [-v | --version] [--config <path>]
twig clean local [-a <assignee> | --assignee <assignee>] [--any]
twig clean all [-a <assignee> | --assignee <assignee>] [--any]
Deletes branches which have Jira tickets in 'Done' state.
Note: Remote branches can only be deleted if a corresponding local branch exists.
-a
--assignee
- (optional) Specifies the username (from the email) to verify that the Jira issue matches the provided assignee before allowing remote or local branch deletion. Defaults to project.email
username from the configuration file.
--any
- (optional) Allows you to bypass assignee verification to check whether the Jira issue is assigned before permitting remote or local branch deletion.
Note: the assignee
option is disregarded when this flag is used.
twig clean local
twig clean all -a example.user
twig config list
twig config get <name>
twig config set <name> <value>
You can query/set/replace options with this command. The name is the section and the key separated by a dot.
twig config list
twig config get project.token
twig config set project.token pat_n7rt64i
twig create <issue-key> [-p | --push] [-t <type> | --type <type>]
Creates the branch using Jira Issue Key as prefix after branch type.
-p
--push
- (optional) Pushes the local branch to the remote when it's created.
-t
--type
- (optional) Overrides the type of branch to create, allowing the branch name ignore mapped Jira issue types. Branches are named according to the standard.
Available branch types
build
,b
- Changes that affect the build system or external dependencies (example scopes: gradle, npm)chore
,ch
- Routine tasks that don't affect the functionality or user-facing aspects of a projectci
- Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)docs
,d
- Documentation only changesfeat
,ft
- A new featurefix
,fx
- A bug fixperf
,p
- A code change that improves performancerefactor
,rf
- A code change that neither fixes a bug nor adds a featurerevert
,rv
- A code that restors to a previous or default conditionstyle
,s
- Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)test
,t
- Adding missing tests or correcting existing tests
twig create XX-111
twig help <command>
Displays help information for all available commands and options in the CLI tool providing usage instructions and examples. Use this command to understand how to use the tool effectively.
twig help create
twig init
Creates a config file and folders (if they don't exist), prompts you with questions to set up the configuration interactively.
twig init
In case you want to experiment with custom branch formatting or extend existing methods go to branch.go
file.
func BuildName(bt Type, jiraIssue network.JiraIssue, excludePhrases string) string {
...
return "branchType/jiraIssue.Key_summary"
}
~% twig create XX-111
~% branch created: task/XX-111_jira-issue-name
~% twig create XX-111 -p
~% branch created: task/XX-111_jira-issue-name
~% remote branch created: task/XX-111_jira-issue-name
~% twig create XX-111 -t fx
~% branch created: fix/XX-111_jira-issue-name
~% twig clean local
~% branch deleted: fix/XX-111_jira-issue-name
~% twig clean all
~% branch deleted: fix/XX-111_jira-issue-name
~% remote branch deleted: origin/fix/XX-111_jira-issue-name
~% twig clean all --assignee example.user
~% branch deleted: fix/XX-111_jira-issue-name
~% remote branch deleted: origin/fix/XX-111_jira-issue-name
~% twig clean local --any
~% branch deleted: fix/XX-111_jira-issue-name