diff --git a/Dockerfile b/Dockerfile index e026372..fd2443b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,9 @@ 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/ /app/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 94% rename from sync_pr.py rename to src/sync_pr.py index b2ba258..f6502b8 100755 --- a/sync_pr.py +++ b/src/sync_pr.py @@ -18,8 +18,8 @@ from github import Github -from sync_issue import _create_jira_issue -from sync_issue import _find_jira_issue +from src.sync_issue import _create_jira_issue +from src.sync_issue import _find_jira_issue def sync_remain_prs(jira): diff --git a/sync_to_jira.py b/src/sync_to_jira.py similarity index 89% rename from sync_to_jira.py rename to src/sync_to_jira.py index 8ebebdd..c79683c 100755 --- a/sync_to_jira.py +++ b/src/sync_to_jira.py @@ -20,18 +20,18 @@ 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 -from sync_issue import handle_issue_closed -from sync_issue import handle_issue_deleted -from sync_issue import handle_issue_edited -from sync_issue import handle_issue_labeled -from sync_issue import handle_issue_opened -from sync_issue import handle_issue_reopened -from sync_issue import handle_issue_unlabeled -from sync_issue import sync_issues_manually -from sync_pr import sync_remain_prs +from src.sync_issue import handle_comment_created +from src.sync_issue import handle_comment_deleted +from src.sync_issue import handle_comment_edited +from src.sync_issue import handle_issue_closed +from src.sync_issue import handle_issue_deleted +from src.sync_issue import handle_issue_edited +from src.sync_issue import handle_issue_labeled +from src.sync_issue import handle_issue_opened +from src.sync_issue import handle_issue_reopened +from src.sync_issue import handle_issue_unlabeled +from src.sync_issue import sync_issues_manually +from src.sync_pr import sync_remain_prs class _JIRA(JIRA): 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()