From bbed7787686c3cff39e477815c6455579f534890 Mon Sep 17 00:00:00 2001 From: Tomas Sebestik Date: Fri, 9 Feb 2024 10:44:48 +0100 Subject: [PATCH] refactor: move source code to src directory --- Dockerfile | 5 ++--- src/__init__.py | 0 sync_issue.py => src/sync_issue.py | 0 sync_pr.py => src/sync_pr.py | 1 - sync_to_jira.py => src/sync_to_jira.py | 1 - tests/test_sync_issue.py | 10 +++++----- tests/test_sync_pr.py | 8 ++++---- tests/test_sync_to_jira.py | 4 ++-- 8 files changed, 13 insertions(+), 16 deletions(-) create mode 100644 src/__init__.py rename sync_issue.py => src/sync_issue.py (100%) rename sync_pr.py => src/sync_pr.py (99%) rename sync_to_jira.py => src/sync_to_jira.py (99%) diff --git a/Dockerfile b/Dockerfile index e026372..7956d91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,8 +22,7 @@ RUN pip3 install --no-cache-dir -r /tmp/requirements.txt RUN npm i -g @shogobg/markdown2confluence@0.1.6 # Copy Python scripts -WORKDIR /app -COPY sync_issue.py sync_pr.py sync_to_jira.py / +COPY src/ /src # Define the entrypoint -ENTRYPOINT ["/usr/bin/python3", "/sync_to_jira.py"] +ENTRYPOINT ["/usr/bin/python3", "/src/sync_to_jira.py"] diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sync_issue.py b/src/sync_issue.py similarity index 100% rename from sync_issue.py rename to src/sync_issue.py diff --git a/sync_pr.py b/src/sync_pr.py similarity index 99% rename from sync_pr.py rename to src/sync_pr.py index b2ba258..1337d8c 100755 --- a/sync_pr.py +++ b/src/sync_pr.py @@ -17,7 +17,6 @@ import os from github import Github - from sync_issue import _create_jira_issue from sync_issue import _find_jira_issue diff --git a/sync_to_jira.py b/src/sync_to_jira.py similarity index 99% rename from sync_to_jira.py rename to src/sync_to_jira.py index 8ebebdd..2457f5d 100755 --- a/sync_to_jira.py +++ b/src/sync_to_jira.py @@ -19,7 +19,6 @@ from github import Github from jira import JIRA - from sync_issue import handle_comment_created from sync_issue import handle_comment_deleted from sync_issue import handle_comment_edited diff --git a/tests/test_sync_issue.py b/tests/test_sync_issue.py index faa22ce..e9e79ae 100644 --- a/tests/test_sync_issue.py +++ b/tests/test_sync_issue.py @@ -30,7 +30,7 @@ def mock_jira_client(): @pytest.fixture def sync_issue_module(github_client_mock): from importlib import reload - import sync_issue + from src import sync_issue reload(sync_issue) # Reload to apply the mocked Github client return sync_issue @@ -52,8 +52,8 @@ def test_handle_issue_opened_creates_jira_issue(sync_issue_module, github_client } } - with patch('sync_issue._find_jira_issue', return_value=None) as mock_find_jira_issue, patch( - 'sync_issue._create_jira_issue' + with patch('src.sync_issue._find_jira_issue', return_value=None) as mock_find_jira_issue, patch( + 'src.sync_issue._create_jira_issue' ) as mock_create_jira_issue: sync_issue_module.handle_issue_opened(mock_jira_client, mock_event) @@ -89,8 +89,8 @@ def update_labels(fields=None): mock_jira_issue.update = MagicMock(side_effect=update_labels) - with patch('sync_issue._find_jira_issue', return_value=mock_jira_issue), patch( - 'sync_issue._get_jira_label', side_effect=lambda x: x['name'] + with patch('src.sync_issue._find_jira_issue', return_value=mock_jira_issue), patch( + 'src.sync_issue._get_jira_label', side_effect=lambda x: x['name'] ): sync_issue_module.handle_issue_labeled(mock_jira_client, mock_event) diff --git a/tests/test_sync_pr.py b/tests/test_sync_pr.py index b616474..1a9fe0d 100644 --- a/tests/test_sync_pr.py +++ b/tests/test_sync_pr.py @@ -33,8 +33,8 @@ def mock_github(): @pytest.fixture def sync_pr_module(mock_github): - # Import the module - import sync_pr + # Import the module from the src directory + from src import sync_pr # Reload the module to ensure the mock is applied importlib.reload(sync_pr) @@ -44,8 +44,8 @@ def sync_pr_module(mock_github): @pytest.fixture def mock_sync_issue(): - with patch('sync_pr._create_jira_issue') as mock_create_jira_issue, patch( - 'sync_pr._find_jira_issue', return_value=None + with patch('src.sync_pr._create_jira_issue') as mock_create_jira_issue, patch( + 'src.sync_pr._find_jira_issue', return_value=None ) as mock_find_jira_issue: yield mock_create_jira_issue, mock_find_jira_issue diff --git a/tests/test_sync_to_jira.py b/tests/test_sync_to_jira.py index 4fb7850..16d1495 100644 --- a/tests/test_sync_to_jira.py +++ b/tests/test_sync_to_jira.py @@ -23,7 +23,7 @@ def sync_to_jira_main(monkeypatch): monkeypatch.setattr('jira.JIRA', MagicMock()) # Import the main function dynamically after applying mocks - from sync_to_jira import main as dynamically_imported_main + from src.sync_to_jira import main as dynamically_imported_main return dynamically_imported_main @@ -56,6 +56,6 @@ def test_handle_issue_opened_event(mock_environment, sync_to_jira_main, monkeypa mock_environment.write_text(json.dumps(event_data)) monkeypatch.setenv('GITHUB_EVENT_NAME', 'issues') - with patch('sync_to_jira.handle_issue_opened') as mock_handle_issue_opened: + with patch('src.sync_to_jira.handle_issue_opened') as mock_handle_issue_opened: sync_to_jira_main() mock_handle_issue_opened.assert_called_once()