Skip to content

Commit

Permalink
Merge pull request #233 from Der-Henning/dev
Browse files Browse the repository at this point in the history
Hotfix: Parsing of newline characters from environment files
  • Loading branch information
Der-Henning committed Jan 5, 2023
2 parents 1678cce + 9c60bf7 commit 168149e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 55 deletions.
16 changes: 2 additions & 14 deletions .github/workflows/tgtg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
run: |
pip install -r requirements.txt
pip install pytest-cov responses
- name: Login
- name: Run tests
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
max_attempts: 10
retry_wait_seconds: 1800
command: |
python ./src/login.py
python -m pytest -m tgtg_api
echo "::add-mask::${{ env.TGTG_ACCESS_TOKEN }}"
echo "::add-mask::${{ env.TGTG_REFRESH_TOKEN }}"
echo "::add-mask::${{ env.TGTG_USER_ID }}"
Expand All @@ -36,18 +36,6 @@ jobs:
TGTG_ACCESS_TOKEN: ${{ secrets.TGTG_ACCESS_TOKEN }}
TGTG_REFRESH_TOKEN: ${{ secrets.TGTG_REFRESH_TOKEN }}
TGTG_USER_ID: ${{ secrets.TGTG_USER_ID }}
- name: Run tests
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
max_attempts: 10
retry_wait_seconds: 1800
command: python -m pytest -m tgtg_api
env:
TGTG_USERNAME: ${{ secrets.TGTG_USERNAME }}
TGTG_ACCESS_TOKEN: ${{ secrets.TGTG_ACCESS_TOKEN }}
TGTG_REFRESH_TOKEN: ${{ secrets.TGTG_REFRESH_TOKEN }}
TGTG_USER_ID: ${{ secrets.TGTG_USER_ID }}
- uses: Der-Henning/actions-set-secret@v2.1.0
with:
name: "TGTG_ACCESS_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ executable:
zip -j dist/scanner.zip dist/*

test:
python -m pytest --cov src/
python -m pytest -m "not tgtg_api" --cov src/

lint:
pre-commit run -a
Expand Down
2 changes: 1 addition & 1 deletion src/_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = "TGTG Scanner"
__description__ = "Provides notifications for TGTG magic bags"
__version__ = "1.14.1"
__version__ = "1.14.2"
__author__ = "Henning Merklinger"
__author_email__ = "henning.merklinger@gmail.com"
__license__ = "GPL"
Expand Down
35 changes: 0 additions & 35 deletions src/login.py

This file was deleted.

7 changes: 5 additions & 2 deletions src/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ def _read_ini(self) -> None:
raise ConfigurationError(err) from err

def _env_get(self, key: str, attr: str) -> None:
self._setattr(attr, environ.get(key, self._getattr(attr)))
value = environ.get(key, None)
if value is not None:
value = value.replace('\\n', '\n')
self._setattr(attr, value)

def _env_get_boolean(self, key: str, attr: str) -> None:
value = environ.get(key, None)
Expand Down Expand Up @@ -307,7 +310,7 @@ def _read_env(self) -> None:
self._env_get("TGTG_ACCESS_TOKEN", "tgtg.access_token")
self._env_get("TGTG_REFRESH_TOKEN", "tgtg.refresh_token")
self._env_get("TGTG_USER_ID", "tgtg.user_id")
self._env_get("TGTG_TIMEOUT", "tgtg.timeout")
self._env_get_int("TGTG_TIMEOUT", "tgtg.timeout")
self._env_get_int("TGTG_ACCESS_TOKEN_LIFETIME",
"tgtg.access_token_lifetime")
self._env_get_int("TGTG_MAX_POLLING_TRIES",
Expand Down
4 changes: 2 additions & 2 deletions src/notifiers/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def __init__(self, config: Config):
self.cron = config.telegram.get("cron")
self.mute = None
self.retries = 0
if self.enabled and not self.token:
raise TelegramConfigurationError("Missing Telegram token")
if self.enabled and (not self.token or not self.body):
raise TelegramConfigurationError()
if self.enabled:
try:
Item.check_mask(self.body)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_tgtg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pathlib
from os import environ

import pytest

Expand All @@ -13,6 +14,8 @@ def test_get_items(item_properties: dict):
else:
config = Config()

env_file = environ.get("GITHUB_ENV", None)

client = TgtgClient(
email=config.tgtg.get("username"),
timeout=config.tgtg.get("timeout"),
Expand All @@ -24,6 +27,15 @@ def test_get_items(item_properties: dict):
user_id=config.tgtg.get("user_id")
)

# get credentials and safe tokens to GITHUB_ENV file
# this enables github workflow to reuse the access_token on sheduled runs
if env_file:
credentials = client.get_credentials()
with open(env_file, "a", encoding="utf-8") as file:
file.write(f"TGTG_ACCESS_TOKEN={credentials['access_token']}\n")
file.write(f"TGTG_REFRESH_TOKEN={credentials['refresh_token']}\n")
file.write(f"TGTG_USER_ID={credentials['user_id']}\n")

# Tests
items = client.get_items(favorites_only=True)
assert len(items) > 0
Expand Down

0 comments on commit 168149e

Please sign in to comment.