diff --git a/cloud-chatops/deployment.yml b/cloud-chatops/deployment.yml index 1fec867..e4028bd 100644 --- a/cloud-chatops/deployment.yml +++ b/cloud-chatops/deployment.yml @@ -19,7 +19,7 @@ spec: spec: containers: - name: cloud-chatops - image: harbor.stfc.ac.uk/stfc-cloud/cloud-chatops:5.0.0 + image: harbor.stfc.ac.uk/stfc-cloud/cloud-chatops:5.0.1 env: - name: HOST_IP valueFrom: diff --git a/cloud-chatops/docker-compose.yaml b/cloud-chatops/docker-compose.yaml index abff682..4d6972f 100644 --- a/cloud-chatops/docker-compose.yaml +++ b/cloud-chatops/docker-compose.yaml @@ -1,6 +1,6 @@ services: cloud_chatops: - image: harbor.stfc.ac.uk/stfc-cloud/cloud-chatops:5.0.0 + image: harbor.stfc.ac.uk/stfc-cloud/cloud-chatops:5.0.1 environment: HOST_IP: ${HOST_IP:?error} volumes: diff --git a/cloud-chatops/src/events.py b/cloud-chatops/src/events.py index 504e8bf..b5e4b20 100644 --- a/cloud-chatops/src/events.py +++ b/cloud-chatops/src/events.py @@ -14,7 +14,7 @@ from read_data import get_config, get_token -def run_global_reminder(channel) -> None: +def run_global_reminder(channel: str) -> None: """This event sends a message to the specified channel with all open PRs.""" unsorted_prs = FindPRs().run(repos=get_config("repos")) prs = FindPRs().sort_by(unsorted_prs, "created_at", False) @@ -24,9 +24,10 @@ def run_global_reminder(channel) -> None: ) -def run_personal_reminder(users: List[User]) -> None: +def run_personal_reminder(users: List[User], message_no_prs: bool = False) -> None: """ This event sends a message to each user in the user map with their open PRs. + :param message_no_prs: Send a message saying there are no PRs open. :param users: Users to send reminders to. """ unsorted_prs = FindPRs().run(repos=get_config("repos")) @@ -37,7 +38,7 @@ def run_personal_reminder(users: List[User]) -> None: PRReminder(client).run( prs=filtered_prs, channel=user.slack_id, - message_no_prs=False, + message_no_prs=message_no_prs, ) @@ -70,8 +71,8 @@ async def slash_prs(ack, respond, command): """ await ack() user_id = command["user_id"] - - if user_id not in [user.slack_id for user in get_config("users")]: + users = get_config("users") + if user_id not in [user.slack_id for user in users]: await respond( f"Could not find your Slack ID {user_id} in the user map. " f"Please contact the service maintainer to fix this." @@ -80,7 +81,9 @@ async def slash_prs(ack, respond, command): if command["text"] == "mine": await respond("Gathering the PRs...") - run_personal_reminder([user_id]) + run_personal_reminder( + [user for user in users if user.slack_id == user_id], message_no_prs=True + ) elif command["text"] == "all": await respond("Gathering the PRs...") run_global_reminder(user_id) diff --git a/cloud-chatops/tests/test_events.py b/cloud-chatops/tests/test_events.py index 277db25..449f0f6 100644 --- a/cloud-chatops/tests/test_events.py +++ b/cloud-chatops/tests/test_events.py @@ -112,7 +112,7 @@ async def test_slash_prs_mine(mock_get_config, mock_run_personal): mock_get_config.assert_called_once_with("users") mock_respond.assert_any_call("Gathering the PRs...") mock_respond.assert_any_call("Check out your DMs.") - mock_run_personal.assert_called_once_with(["mock_slack"]) + mock_run_personal.assert_called_once_with([MOCK_USER], message_no_prs=True) @pytest.mark.asyncio diff --git a/cloud-chatops/tests/test_read_data.py b/cloud-chatops/tests/test_read_data.py index d83d525..eec8264 100644 --- a/cloud-chatops/tests/test_read_data.py +++ b/cloud-chatops/tests/test_read_data.py @@ -120,6 +120,10 @@ def test_validate_required_files_fail_users(mock_get_token, mock_get_config): def test_validate_required_files_fail_channel(mock_get_token, mock_get_config): """Test the validate files function""" mock_get_token.side_effect = ["mock_bot", "mock_app", "mock_github"] - mock_get_config.side_effect = [{"owner1": ["repo1"]}, {"mock_github": "mock_user"}, ""] + mock_get_config.side_effect = [ + {"owner1": ["repo1"]}, + {"mock_github": "mock_user"}, + "", + ] with pytest.raises(ErrorInConfig): validate_required_files() diff --git a/cloud-chatops/version.txt b/cloud-chatops/version.txt index 0062ac9..6b244dc 100644 --- a/cloud-chatops/version.txt +++ b/cloud-chatops/version.txt @@ -1 +1 @@ -5.0.0 +5.0.1