Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/cli/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ Add badges to the README file.

Currently supported badges:

- `usethis badge bitbucket` - [![Bitbucket](https://img.shields.io/badge/Bitbucket-0747a6?logo=bitbucket&logoColor=white)](https://bitbucket.org)
- `usethis badge pre-commit` - [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
- `usethis badge pypi` - [![PyPI Version](https://img.shields.io/pypi/v/usethis.svg)](https://pypi.python.org/pypi/usethis)
- `usethis badge ruff` - [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
Expand Down
7 changes: 7 additions & 0 deletions src/usethis/_core/badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ def get_uv_badge() -> Badge:
)


def get_bitbucket_badge() -> Badge:
return Badge(
markdown="[![Bitbucket](https://img.shields.io/badge/Bitbucket-0747a6?logo=bitbucket&logoColor=white)](https://bitbucket.org)"
)


def get_usethis_badge() -> Badge:
return Badge(
markdown="[![usethis](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/usethis-python/usethis-python/main/assets/badge/v1.json)](https://github.com/usethis-python/usethis-python)"
Expand All @@ -94,6 +100,7 @@ def get_badge_order() -> list[Badge]:
get_ty_badge(),
get_pre_commit_badge(),
get_usethis_badge(),
get_bitbucket_badge(),
get_socket_badge(),
]

Expand Down
14 changes: 14 additions & 0 deletions src/usethis/_ui/interface/badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ def usethis(
_badge_effect(get_usethis_badge(), remove=remove, show=show)


@app.command(help="Add a badge for Bitbucket.")
def bitbucket(
remove: bool = remove_opt,
offline: bool = offline_opt,
quiet: bool = quiet_opt,
show: bool = show_opt,
) -> None:
from usethis._config_file import files_manager
from usethis._core.badge import get_bitbucket_badge

with usethis_config.set(offline=offline, quiet=quiet), files_manager():
_badge_effect(get_bitbucket_badge(), remove=remove, show=show)


@app.command(help="Add a badge for the uv package manager.")
def uv(
remove: bool = remove_opt,
Expand Down
1 change: 1 addition & 0 deletions tests/usethis/_core/assets/expected_all_badges.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
[![ty](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ty/main/assets/badge/v0.json)](https://github.com/astral-sh/ty)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![usethis](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/usethis-python/usethis-python/main/assets/badge/v1.json)](https://github.com/usethis-python/usethis-python)
[![Bitbucket](https://img.shields.io/badge/Bitbucket-0747a6?logo=bitbucket&logoColor=white)](https://bitbucket.org)
[![Socket Badge](https://badge.socket.dev/pypi/package/my-project)](https://socket.dev/pypi/package/my-project/overview)
2 changes: 2 additions & 0 deletions tests/usethis/_core/test_core_badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from usethis._core.badge import (
Badge,
add_badge,
get_bitbucket_badge,
get_pre_commit_badge,
get_pypi_badge,
get_ruff_badge,
Expand Down Expand Up @@ -767,6 +768,7 @@ def test_all_badges(self, bare_dir: Path):
add_badge(get_ty_badge())
add_badge(get_pre_commit_badge())
add_badge(get_usethis_badge())
add_badge(get_bitbucket_badge())
add_badge(get_socket_badge())

# Assert
Expand Down
39 changes: 39 additions & 0 deletions tests/usethis/_ui/interface/test_interface_badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,45 @@ def test_show(self, tmp_path: Path):
)


class TestBitbucket:
def test_add(self, tmp_path: Path):
# Act
runner = CliRunner()
with change_cwd(tmp_path):
result = runner.invoke_safe(app, ["bitbucket"])

# Assert
assert result.exit_code == 0, result.output

def test_remove(self, tmp_path: Path):
# Arrange
(tmp_path / "README.md").write_text("")

# Act
runner = CliRunner()
with change_cwd(tmp_path):
result = runner.invoke_safe(app, ["bitbucket", "--remove"])

# Assert
assert result.exit_code == 0, result.output

def test_show(self, tmp_path: Path):
# Arrange
(tmp_path / "README.md").write_text("")

# Act
runner = CliRunner()
with change_cwd(tmp_path):
result = runner.invoke_safe(app, ["bitbucket", "--show"])

# Assert
assert result.exit_code == 0, result.output
assert (
result.output
== "[![Bitbucket](https://img.shields.io/badge/Bitbucket-0747a6?logo=bitbucket&logoColor=white)](https://bitbucket.org)\n"
)


class TestUV:
def test_add(self, tmp_path: Path):
# Act
Expand Down
Loading