Skip to content

Commit faee2d2

Browse files
committed
refactor: Load shelve db paths from env
1 parent 8bc37cd commit faee2d2

8 files changed

Lines changed: 23 additions & 10 deletions

File tree

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ GITHUB_PROJECT_NODE_ID=your-github-project-node-id
55
GITHUB_ID_TO_DISCORD_ID_MAPPING_PATH=path-to-github-username-to-discord-id-mapping.json
66
IP_ADDRESS=0.0.0.0
77
PORT=8000
8-
GITHUB_WEBHOOK_SECRET=your-github-webhook-secret
8+
GITHUB_WEBHOOK_SECRET=your-github-webhook-secret
9+
# Shelve databases
10+
ITEM_NAME_TO_NODE_ID_DB_PATH=path-to-item-name-to-node-id.db
11+
POST_ID_DB_PATH=path-to-post-id.db

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ uv run pytest
3434

3535
For deployment follow these steps:
3636
- set all environment variables accordingly,
37-
- setup file_mount for `github_id_to_discord_id_mapping.json` on `/app/github_usernames_to_discord_id_mapping.json`,
37+
- setup file_mount for volumes specified in `docker-compose.yaml` on /app/path_set_in_env,
3838
- set up a webhook in your GitHub repository to point to your server's `/webhook_endpoint` endpoint,
3939
- use Dockerfile to build the image.
4040

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
env_file:
1111
- .env
1212
volumes:
13-
- github_id_to_discord_id_mapping:/app/github_id_to_discord_id_mapping.yaml
13+
- github_id_to_discord_id_mapping:/app/${GITHUB_ID_TO_DISCORD_ID_MAPPING_PATH}
1414

1515
volumes:
1616
github_id_to_discord_id_mapping:

src/tests/test_e2e.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ async def test_e2e(
4242
):
4343
mock_restapp_acquire.return_value = RestClientContextManagerMock(rest_client_mock)
4444
mock_fetch_channel.side_effect = [forum_channel_mock, post_mock]
45-
mock_getenv.side_effect = ["some_token", 1, 2, "some_secret", "fake_project_id", "meow.yaml"]
45+
mock_getenv.side_effect = [
46+
"some_token",
47+
1,
48+
2,
49+
"some_secret",
50+
"fake_project_id",
51+
"db-path.db",
52+
"meow.yaml",
53+
"db-path.db",
54+
]
4655
post_id_shelf = MockShelf({})
4756
mock_shelve_open.side_effect = [MockShelf({"item123": "audacity4"}), post_id_shelf]
4857
mock_fetch_active_threads.return_value = [post_mock]

src/tests/test_integration/test_bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async def test_basic_event_only_creation(
6464
forum_channel_mock,
6565
logger_mock,
6666
):
67-
mock_os_getenv.side_effect = ["some_token", 1, 2, "some_path"]
67+
mock_os_getenv.side_effect = ["some_token", 1, 2, "some_path", "db-path.db"]
6868
mock_restapp_acquire.return_value = RestClientContextManagerMock(rest_client_mock)
6969
mock_fetch_channel.return_value = forum_channel_mock
7070
mock_fetch_active_threads.return_value = []

src/tests/test_integration/test_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_missing_item_node_id(mock_os_getenv):
114114
@patch("shelve.open")
115115
@patch("os.getenv")
116116
def test_could_not_fetch_item_name(mock_os_getenv, mock_shelve_open, mock_post_request):
117-
mock_os_getenv.side_effect = ["some_secret", 123, "some_token"]
117+
mock_os_getenv.side_effect = ["some_secret", 123, "some_token", "db-path.db"]
118118
mock_shelve_open.return_value = MockShelf({})
119119
mock_post_request.return_value = MockResponse({})
120120
signature = generate_signature("some_secret", b'{"projects_v2_item": {"project_node_id": 123, "node_id": "123"}}')
@@ -130,7 +130,7 @@ def test_could_not_fetch_item_name(mock_os_getenv, mock_shelve_open, mock_post_r
130130
@patch("shelve.open")
131131
@patch("os.getenv")
132132
def test_missing_action(mock_os_getenv, mock_shelve_open):
133-
mock_os_getenv.side_effect = ["some_secret", 123]
133+
mock_os_getenv.side_effect = ["some_secret", 123, "db-path.db"]
134134
mock_shelve_open.return_value = MockShelf({"123": "Meow"})
135135
signature = generate_signature("some_secret", b'{"projects_v2_item": {"project_node_id": 123, "node_id": "123"}}')
136136
response = test_client.post(
@@ -152,7 +152,7 @@ def test_edited_action(mock_os_getenv, mock_shelve_open, mock_post_request):
152152
"changes": {"field_value": {"field_type": "title"}},
153153
}
154154
payload: str = json.dumps(payload)
155-
mock_os_getenv.side_effect = ["some_secret", 123, "some_token"]
155+
mock_os_getenv.side_effect = ["some_secret", 123, "some_token", "db-path.db"]
156156
mock_shelve_open.return_value = MockShelf({"123": "Meow"})
157157
mock_post_request.return_value = MockResponse({"data": {"node": {"content": {"title": "Meow"}}}})
158158
signature = generate_signature(

src/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
async def get_item_name(item_node_id: str) -> str | None:
12-
with shelve.open("item_name_to_node_id.db") as db:
12+
with shelve.open(os.getenv("ITEM_NAME_TO_NODE_ID_DB_PATH", "item_name_to_node_id.db")) as db:
1313
try:
1414
item_name: str = db[item_node_id]
1515
except KeyError:

src/utils/discord_rest_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import shelve
23

34
from hikari import ForumTag, GuildForumChannel, GuildThreadChannel
@@ -19,7 +20,7 @@ def get_new_tag(new_tag_name: str, available_tags: list[ForumTag]) -> ForumTag |
1920
async def get_post_id(
2021
name: str, discord_guild_id: int, forum_channel_id: int, rest_client: RESTClientImpl
2122
) -> int | GuildThreadChannel | None:
22-
with shelve.open("post_id.db") as db:
23+
with shelve.open(os.getenv("POST_ID_DB_PATH", "post_id.db")) as db:
2324
try:
2425
post_id: str = db[name]
2526
return int(post_id)

0 commit comments

Comments
 (0)