Skip to content

psadi/bbcli

Repository files navigation

Bitbucket CLI (bb)

Work seamlessly with Bitbucket from the command line

Continuous Integration Quality Gate Status Buy Me A Coffee


⚠️ NOTICE !!

This tool is designed to work with Bitbucket Server Edition (Enterprise) and not with Bitbucket Cloud / bitbucket.org

The API Endpoints and the way the tool interacts with the server is different from the cloud version, hence this tool will break if used with the cloud version.


DEMO

asciicast

REQUIREMENTS

  • Git
  • Python3 (3.7 or Higher)
  • Pip3 (latest recommended)
  • A write access token from bitbucket

INSTALLATION

From Source

git clone https://github.com/psadi/bbcli.git
cd bbcli
pip3 install build
python3 -m build .
pip3 install --user dist/bb-<version>.tar.gz

From Releases

Download the latest build from releases page

pip3 install --user bb-<version>.tar.gz

From Docker

A docker image is published to hub.docker.com

docker pull psadi/bbcli:<tag>
docker run -it --rm -v $HOME/.config/bb:$HOME/.config/bb -v $(pwd):/app/. --network host psadi/bbcli [OPTIONS] COMMAND [ARGS]

Example:

docker run -it --rm -v $HOME/.config/bb:$HOME/.config/bb -v $(pwd):/app/. --network host psadi/bbcli pr create --target master

CONFIGURATION

  1. Run the following command to perform initial setup, this will setup a config.ini under $XDG_CONFIG_HOME/bb respective to the OS, make sure to remove the '/` at the end of your bitbucket_host:
bb auth setup
  1. Validate
  • Check the config file status bb auth status

  • If the config file is setup properly, run bb auth test to validate

  • if all went well, you should get a response like this

> bb auth test
⠏ Validating connection with 'https://bitbucket.<company>.com'... OK

HOW-TO?

Create pull request
Command Action
bb pr create --target master creates pull request and asks for confirmation
bb pr create --target master --yes creates pull request without prompt
Show diff of files (ADD/DELETE/MODIFY & RENAME) as an overview
Command Action
bb pr create --target master --yes --diff creates pull request without prompt and shows diff from the PR raised
bb pr delete --id 1 --yes --diff deletes pull request without prompt and shows diff befoew PR is deleted
bb pr diff --id 1 shows diff for the given pull request id
Delete pull request(s)
Command Action
bb pr delete --id 1 deletes the given pull request number with confirmation prompt
bb pr delete --id 1 --yes deletes the given pull request number without prompt
bb pr delete --id 1,2,3 deletes multiple pull requests
Show pull request(s) authored/reviewer
Command Action
bb pr list show pull requests in current repository [Default]
bb pr list --author show pull requests authored in current repository
bb pr list --author --all show pull requests authored in all repositories
bb pr list --reviewer show pull requests that you are a reviewer in current repository
bb pr list --reviewer --all show pull requests that you are a reviewer in all repositories
Review pull request
Command Action
bb pr review --id 1 --action approve marks the pull request as APPROVED
bb pr review --id 1 --action unapprove marks the pull request as UNAPPROVED
bb pr review --id 1 --action needs_work marks the pull request as NEEDS WORK
Merge pull request
Command Action
bb pr merge --id 1 Validates pull request merge conditions and prompts for merge
bb pr merge --id 1 --rebase adds optional rebase [Default: False]
bb pr merge --id 1 --delete-source-branch deletes source branch after merge, [Default: False], If false will prompt for deletion

Points to Ponder

  • This utility is tested with bitbucket enterprise version 6.10.10 and 8.19
  • I have personally tested it in Linux, Windows(Powershell and Command Prompt), MacOS and GIT Bash and it works flawlessly
  • In case if your ID gets locked the token wont work, you may need to reset your ID (Token can remain the same)
  • At times if there are frequent account lockouts, Bitbucket will prompt you to enter CAPTCHA, you may need to relogin with CAPTCHA validation in your broswer once else connection will fail

CREDITS

bbcli wouldn't be possible if not for the awesome open-source tools made avaiable.

A huge thanks to,

LICENSE

This project is licensed under the MIT License - see the LICENSE file for details