Skip to content

Commit

Permalink
refactor: move source code to src directory
Browse files Browse the repository at this point in the history
  • Loading branch information
tomassebestik committed Feb 9, 2024
1 parent eccb8f9 commit bbed778
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 16 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ RUN pip3 install --no-cache-dir -r /tmp/requirements.txt
RUN npm i -g @shogobg/[email protected]

# 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"]
Empty file added src/__init__.py
Empty file.
File renamed without changes.
1 change: 0 additions & 1 deletion sync_pr.py → src/sync_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import os

from github import Github

from sync_issue import _create_jira_issue
from sync_issue import _find_jira_issue

Expand Down
1 change: 0 additions & 1 deletion sync_to_jira.py → src/sync_to_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/test_sync_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_sync_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/test_sync_to_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()

0 comments on commit bbed778

Please sign in to comment.