From bce02d3264589ce6dc891f17a303a3361c2146e5 Mon Sep 17 00:00:00 2001 From: Kalibh Halford <kalibh.halford@stfc.ac.uk> Date: Tue, 24 Sep 2024 13:01:42 +0100 Subject: [PATCH] BUG: Fixes /prs command. --- .gitignore | 1 + cloud-chatops/requirements.txt | 1 + cloud-chatops/src/features/commands.py | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62c8935 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/cloud-chatops/requirements.txt b/cloud-chatops/requirements.txt index b51826d..59fd58e 100644 --- a/cloud-chatops/requirements.txt +++ b/cloud-chatops/requirements.txt @@ -3,6 +3,7 @@ schedule slack-bolt aiohttp requests +python-dateutil pytest pytest-cov pylint diff --git a/cloud-chatops/src/features/commands.py b/cloud-chatops/src/features/commands.py index 1fb8dc3..050b1a1 100644 --- a/cloud-chatops/src/features/commands.py +++ b/cloud-chatops/src/features/commands.py @@ -2,6 +2,7 @@ from typing import List from datetime import datetime, timedelta +from dateutil import parser as datetime_parser from slack_sdk import WebClient from slack_sdk.errors import SlackApiError from enum_states import PRsFoundState @@ -64,7 +65,9 @@ def post_thread_messages(self, prs: List[PrData], post_all: bool) -> None: prs_posted = PRsFoundState.NONE_FOUND for pr in prs: checked_pr = self.check_pr(pr) - prs_posted = self.filter_thread_message(checked_pr, post_all) + post_status = self.filter_thread_message(checked_pr, post_all) + if post_status == PRsFoundState.PRS_FOUND: + prs_posted = PRsFoundState.PRS_FOUND if prs_posted == PRsFoundState.NONE_FOUND: self.send_no_prs() @@ -110,7 +113,8 @@ def check_pr(self, info: PrData) -> PrData: info.user = DEFAULT_AUTHOR else: info.user = self._github_to_slack_username(info.user) - opened_date = datetime.fromisoformat(info.created_at).replace(tzinfo=None) + print(info.created_at) + opened_date = datetime_parser.parse(info.created_at).replace(tzinfo=None) datetime_now = datetime.now().replace(tzinfo=None) time_cutoff = datetime_now - timedelta(days=30 * 6) if opened_date < time_cutoff: