Skip to content

Commit 3a458d8

Browse files
authored
Fix bug + restructure (#26)
* new structure and tests * fix lint * additional test * Fix up * Fix up * Fix up
1 parent 511549f commit 3a458d8

File tree

11 files changed

+204
-34
lines changed

11 files changed

+204
-34
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
# Except
55
!/entrypoint.py
66
!/requirements.txt
7+
!/edge_addon/

.github/workflows/main.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,17 @@ jobs:
1717
with:
1818
python-version: '3.13'
1919
- name: Install pip dependencies
20-
run: pip install -r requirements.txt
20+
run: pip install -r requirements-dev.txt
2121
- uses: pre-commit/action@v3.0.1
22+
23+
test:
24+
runs-on: ubuntu-24.04
25+
steps:
26+
- uses: actions/checkout@master
27+
- uses: actions/setup-python@v5
28+
with:
29+
python-version: '3.13'
30+
- name: Install pip dependencies
31+
run: pip install -r requirements-dev.txt
32+
- name: Run tests
33+
run: python -m pytest -v

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/.venv/
22
/.mypy_cache/
3+
__pycache__/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Built using the [Edge Addons API](https://github.com/web-scrobbler/python-edge-a
88

99
```yaml
1010
steps:
11-
- uses: web-scrobbler/edge-addon@v2.0.3
11+
- uses: web-scrobbler/edge-addon@v2.0.4
1212
with:
1313
product_id: ${{ secrets.EDGE_PRODUCT_ID }}
1414
client_id: ${{ secrets.EDGE_CLIENT_ID }}

edge_addon/__init__.py

Whitespace-only changes.

edge_addon/config.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import sys
2+
from dataclasses import dataclass
3+
4+
from edge_addons_api.client import Options as EdgeOptions
5+
6+
7+
@dataclass
8+
class Options:
9+
product_id: str
10+
client_id: str
11+
api_key: str
12+
file_path: str
13+
notes: str
14+
debug: bool
15+
retry_count: int
16+
sleep_seconds: int
17+
18+
def to_edge_options(self) -> EdgeOptions:
19+
return EdgeOptions(
20+
product_id=self.product_id,
21+
client_id=self.client_id,
22+
api_key=self.api_key,
23+
retry_count=self.retry_count,
24+
sleep_seconds=self.sleep_seconds,
25+
)
26+
27+
28+
def create_options() -> Options:
29+
"""
30+
create Options object from system arguments.
31+
32+
Returns:
33+
Options object containing all configuration
34+
"""
35+
if len(sys.argv) < 9:
36+
print("Incorrect number of arguments given. Please check action parameters")
37+
sys.exit(1)
38+
39+
product_id = sys.argv[1]
40+
client_id = sys.argv[2]
41+
api_key = sys.argv[3]
42+
file_path = sys.argv[4]
43+
notes = sys.argv[5]
44+
debug = sys.argv[6].lower() in ["true", "1"]
45+
retry_count = int(sys.argv[7])
46+
sleep_seconds = int(sys.argv[8])
47+
48+
return Options(
49+
product_id=product_id,
50+
client_id=client_id,
51+
api_key=api_key,
52+
file_path=file_path,
53+
notes=notes,
54+
debug=debug,
55+
retry_count=retry_count,
56+
sleep_seconds=sleep_seconds,
57+
)

edge_addon/logging_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import logging
2+
import sys
3+
4+
5+
def setup_logging(debug: bool) -> None:
6+
"""Setup logging configuration."""
7+
logger = logging.getLogger()
8+
handler = logging.StreamHandler(sys.stdout)
9+
logger.addHandler(handler)
10+
11+
if debug:
12+
logger.setLevel(logging.DEBUG)
13+
logging.getLogger("urllib3").setLevel(logging.WARNING)

entrypoint.py

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,22 @@
11
#!/usr/bin/env python
22

3-
import logging
43
import sys
54

6-
from edge_addons_api.client import Client, Options
5+
from edge_addons_api.client import Client
76
from edge_addons_api.exceptions import UploadException
87

9-
if len(sys.argv) < 6:
10-
print("Incorrect number of arguments given. Please check action parameters")
11-
sys.exit(1)
12-
13-
product_id = sys.argv[1]
14-
client_id = sys.argv[2]
15-
api_key = sys.argv[3]
16-
file_path = sys.argv[5]
17-
notes = sys.argv[6]
18-
debug = sys.argv[7].lower() in ["true", "1"]
19-
retry_count = int(sys.argv[8])
20-
sleep_seconds = int(sys.argv[9])
21-
22-
logger = logging.getLogger()
23-
handler = logging.StreamHandler(sys.stdout)
24-
logger.addHandler(handler)
25-
26-
if debug:
27-
logger.setLevel(logging.DEBUG)
28-
logging.getLogger("urllib3").setLevel(logging.WARNING)
29-
8+
from edge_addon.config import create_options
9+
from edge_addon.logging_utils import setup_logging
3010

31-
options = Options(
32-
product_id=product_id,
33-
client_id=client_id,
34-
api_key=api_key,
35-
retry_count=retry_count,
36-
sleep_seconds=sleep_seconds,
37-
)
11+
options = create_options()
12+
setup_logging(options.debug)
3813

39-
client = Client(options)
14+
client = Client(options.to_edge_options())
4015

4116
print("Submitting addon")
4217

4318
try:
44-
operation_id = client.submit(file_path=file_path, notes=notes)
19+
operation_id = client.submit(file_path=options.file_path, notes=options.notes)
4520
client.fetch_publish_status(operation_id)
4621

4722
print("Successfully uploaded addon")

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-r requirements.txt
2+
pytest==7.4.0

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)