Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST-1] WIP #83

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ python==3.11
#### 1. Clone the repo

```bash
git clone git@github.com:seyLu/setup-github-label-cli.git
git clone https://github.com/seyLu/setup-github-label-cli.git
```

#### 2. Install dependencies
Expand Down Expand Up @@ -186,7 +186,7 @@ ghlabel setup -r "Type: Feature Request, Type: Bug"
```bash
# -a [valid json string]
# will be parsed as list[dict[str, str]]
ghlabel setup -a "[{'name': 'wontfix', 'color': '##ffffff'}, {'name': 'bug', 'color': '#d73a4a', 'description': 'Something isn't working'}]"
ghlabel setup -a "[{'name': 'wontfix', 'color': '#ffffff'}, {'name': 'bug', 'color': '#d73a4a', 'description': 'Something isn't working'}]"
```

<br>
Expand Down
7 changes: 6 additions & 1 deletion cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ class RemoveAllChoices(str, Enum):
silent = "silent"


app = typer.Typer(add_completion=False)
app = typer.Typer(
add_completion=False,
context_settings={
"help_option_names": ["-h", "--help"],
},
)


@app.command("setup", help="Add/Remove Github labels from config files.") # type: ignore[misc]
Expand Down
2 changes: 1 addition & 1 deletion ghlabel.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,5 @@ ghlabel setup -r "Type: Feature Request, Type: Bug"
```bash
# -a [valid json string]
# will be parsed as list[dict[str, str]]
ghlabel setup -a "[{'name': 'wontfix', 'color': '##ffffff'}, {'name': 'bug', 'color': '#d73a4a', 'description': 'Something isn't working'}]"
ghlabel setup -a "[{'name': 'wontfix', 'color': '#ffffff'}, {'name': 'bug', 'color': '#d73a4a', 'description': 'Something isn't working'}]"
```
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ distlib==0.3.7
filelock==3.12.4
identify==2.5.30
idna==3.4
iniconfig==2.0.0
markdown-it-py==3.0.0
mdurl==0.1.2
nodeenv==1.8.0
packaging==23.1
pluggy==1.3.0
platformdirs==3.11.0
pre-commit==3.5.0
Pygments==2.16.1
pytest==7.4.2
pytest-mock==3.11.1
python-dotenv==1.0.0
PyYAML==6.0.1
requests==2.31.0
Expand Down
Empty file added tests/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions tests/test_dump_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import logging
import shutil
from pathlib import Path

import pytest

from scripts.dump_label import DumpLabel

logger = logging.getLogger("root")
logger.setLevel(logging.ERROR)


@pytest.fixture
def tmp_dir(tmp_path: str) -> Path:
_tmp_dir: Path = Path(tmp_path, "tmp_labels")
_tmp_dir.mkdir()
yield _tmp_dir
shutil.rmtree(_tmp_dir)


def test_init_dir(tmp_dir: Path) -> None:
dir: Path = tmp_dir

tmp_file: Path = Path(dir, "tmp_file.txt")
tmp_file.touch()

DumpLabel._init_dir(dir=str(dir))

assert len(list(dir.iterdir())) == 0


def test_dump(tmp_dir: Path) -> None:
dir: Path = tmp_dir
new: bool = True
ext: str = "yaml"

DumpLabel.dump(dir=str(dir), new=new, ext=ext)

assert Path(dir, "_remove_labels.yaml").exists()
assert Path(dir, "default_labels.yaml").exists()
41 changes: 41 additions & 0 deletions tests/test_setup_github_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from typing import Any
from unittest.mock import Mock

import pytest

from scripts.setup_github_label import GithubLabel


@pytest.fixture
def mock_github_config(mocker: Any) -> Any:
github_config = Mock()
github_config.REPO_OWNER = "owner"
github_config.REPO_NAME = "repo"
github_config.PERSONAL_ACCESS_TOKEN = "token"
return github_config


@pytest.fixture
def mock_requests(mocker: Any) -> Any:
mock_requests = Mock()
mock_requests.Response.status_code = 200
return mock_requests


def test_init(mock_github_config: Any, mocker: Any) -> None:
mocker.patch("requests.get", return_value=MockResponse)

github_label = GithubLabel(github_config=mock_github_config)
assert github_label.url == "https://api.github.com/repos/owner/repo/labels"
assert github_label.headers["Authorization"] == "token"


class MockResponse:
def json(self) -> list[dict[str, str]]:
return [
{"name": "label1", "color": "#FF0000", "description": "Description 1."},
]

@property
def status_code(self) -> int:
return 200