From e5658d9ac7a15789425c3fc090ead3eb66f01d4d Mon Sep 17 00:00:00 2001
From: seylu <98249191+seyLu@users.noreply.github.com>
Date: Sat, 9 Sep 2023 01:18:38 +0800
Subject: [PATCH 1/5] docs: remove duplicate '#'
---
README.md | 2 +-
ghlabel.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index d5b6af6..d6ef249 100644
--- a/README.md
+++ b/README.md
@@ -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'}]"
```
diff --git a/ghlabel.md b/ghlabel.md
index de368d0..45c2afb 100644
--- a/ghlabel.md
+++ b/ghlabel.md
@@ -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'}]"
```
From 5cc29e76bf1eae9264694835d384684054fdb495 Mon Sep 17 00:00:00 2001
From: seylu <98249191+seyLu@users.noreply.github.com>
Date: Sat, 9 Sep 2023 01:31:12 +0800
Subject: [PATCH 2/5] docs: replace ssh clone url with https
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index d6ef249..eb181fa 100644
--- a/README.md
+++ b/README.md
@@ -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
From 763ae03d0ade26f360da764d5f82355d37320443 Mon Sep 17 00:00:00 2001
From: seylu <98249191+seyLu@users.noreply.github.com>
Date: Sun, 22 Oct 2023 08:35:47 +0800
Subject: [PATCH 3/5] WIP: add tests
---
.idea/.gitignore | 8 ++++
.../inspectionProfiles/profiles_settings.xml | 6 +++
.idea/misc.xml | 4 ++
.idea/modules.xml | 8 ++++
.idea/setup-issue-label-cli.iml | 17 ++++++++
.idea/vcs.xml | 6 +++
cli.py | 7 +++-
requirements.txt | 5 +++
tests/__init__.py | 0
tests/test_dump_label.py | 40 ++++++++++++++++++
tests/test_setup_github_label.py | 41 +++++++++++++++++++
11 files changed, 141 insertions(+), 1 deletion(-)
create mode 100644 .idea/.gitignore
create mode 100644 .idea/inspectionProfiles/profiles_settings.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/setup-issue-label-cli.iml
create mode 100644 .idea/vcs.xml
create mode 100644 tests/__init__.py
create mode 100644 tests/test_dump_label.py
create mode 100644 tests/test_setup_github_label.py
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..cc5462d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..bd590cf
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..99ef63a
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/.idea/setup-issue-label-cli.iml b/.idea/setup-issue-label-cli.iml
new file mode 100644
index 0000000..cee5dbe
--- /dev/null
+++ b/.idea/setup-issue-label-cli.iml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..dcb6b8c
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/cli.py b/cli.py
index 9e0b741..2cddbb1 100644
--- a/cli.py
+++ b/cli.py
@@ -60,7 +60,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]
diff --git a/requirements.txt b/requirements.txt
index 3be70c8..0d3cbab 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -7,12 +7,17 @@ distlib==0.3.7
filelock==3.12.3
identify==2.5.27
idna==3.4
+iniconfig==2.0.0
markdown-it-py==3.0.0
mdurl==0.1.2
nodeenv==1.8.0
+packaging==23.1
platformdirs==3.10.0
+pluggy==1.3.0
pre-commit==3.4.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
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/test_dump_label.py b/tests/test_dump_label.py
new file mode 100644
index 0000000..dd8002a
--- /dev/null
+++ b/tests/test_dump_label.py
@@ -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()
diff --git a/tests/test_setup_github_label.py b/tests/test_setup_github_label.py
new file mode 100644
index 0000000..4120fab
--- /dev/null
+++ b/tests/test_setup_github_label.py
@@ -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
From cc2ab9a9d9ea6d90919ef6ac15285caa566ea56b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E3=82=BB=E3=82=A4=E3=83=AB=20=C2=B7=20MJ=20Sabit?=
<98249191+seyLu@users.noreply.github.com>
Date: Sun, 22 Oct 2023 08:37:33 +0800
Subject: [PATCH 4/5] feat: delete .idea directory
---
.idea/.gitignore | 8 --------
.idea/inspectionProfiles/profiles_settings.xml | 6 ------
.idea/misc.xml | 4 ----
.idea/modules.xml | 8 --------
.idea/setup-issue-label-cli.iml | 17 -----------------
.idea/vcs.xml | 6 ------
6 files changed, 49 deletions(-)
delete mode 100644 .idea/.gitignore
delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml
delete mode 100644 .idea/misc.xml
delete mode 100644 .idea/modules.xml
delete mode 100644 .idea/setup-issue-label-cli.iml
delete mode 100644 .idea/vcs.xml
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 13566b8..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
deleted file mode 100644
index cc5462d..0000000
--- a/.idea/inspectionProfiles/profiles_settings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index bd590cf..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 99ef63a..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/.idea/setup-issue-label-cli.iml b/.idea/setup-issue-label-cli.iml
deleted file mode 100644
index cee5dbe..0000000
--- a/.idea/setup-issue-label-cli.iml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index dcb6b8c..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
From f1e58e73c26f346e1b3439cef3cdf2882fa2ad58 Mon Sep 17 00:00:00 2001
From: seylu <98249191+seyLu@users.noreply.github.com>
Date: Sun, 22 Oct 2023 08:40:10 +0800
Subject: [PATCH 5/5] chore: ignore .idea/
---
.gitignore | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 4e9e45c..4162d20 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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/