Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pr command #38

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
1 change: 1 addition & 0 deletions cloud-chatops/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ schedule
slack-bolt
aiohttp
requests
python-dateutil
pytest
pytest-cov
pylint
Expand Down
12 changes: 8 additions & 4 deletions cloud-chatops/src/features/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -29,6 +30,7 @@ def __init__(self):
self.prs = GetGitHubPRs(get_repos(), "stfc").run()
self.channel = DEFAULT_CHANNEL
self.thread_ts = None
self.user = None

def run(self, channel: str, post_all: bool) -> None:
"""
Expand All @@ -37,6 +39,7 @@ def run(self, channel: str, post_all: bool) -> None:
:param post_all: To post all PRs found or only ones authored by the user.
"""
self.channel = channel
self.user = channel
self.post_reminder_message()
self.post_thread_messages(self.prs, post_all)

Expand All @@ -62,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()
Expand All @@ -77,11 +82,10 @@ def filter_thread_message(self, info: PrData, post_all: bool) -> PRsFoundState:
:return: Returns an Enum state.
"""
pr_author = info.user
slack_member = self.channel
if post_all:
self.send_thread(info)
return PRsFoundState.PRS_FOUND
if not post_all and pr_author == slack_member:
if not post_all and pr_author == self.user:
self.send_thread(info)
return PRsFoundState.PRS_FOUND
return PRsFoundState.NONE_FOUND
Expand Down Expand Up @@ -109,7 +113,7 @@ 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)
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:
Expand Down
Loading