Skip to content

Commit

Permalink
Merge pull request #88 from stfc/fix_filtered_prs
Browse files Browse the repository at this point in the history
Fix filtered prs
  • Loading branch information
khalford authored Dec 12, 2024
2 parents 0ce6450 + 0654e67 commit 312999b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cloud-chatops/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cloud-chatops/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
15 changes: 9 additions & 6 deletions cloud-chatops/src/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"))
Expand All @@ -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,
)


Expand Down Expand Up @@ -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."
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cloud-chatops/tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion cloud-chatops/tests/test_read_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion cloud-chatops/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.0
5.0.1

0 comments on commit 312999b

Please sign in to comment.