Skip to content
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
24 changes: 9 additions & 15 deletions slapr/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import slack_sdk
from slack_sdk.errors import SlackApiError

PR_URL_PATTERN = r"<(?P<url>.*)>"
PR_URL_PATTERN = r"<(?P<url>https?://[^>|]+)(?:\|[^>]*)?>"


class Message(NamedTuple):
Expand Down Expand Up @@ -111,20 +111,14 @@ def find_timestamp_of_review_requested_message(self, pr_url: str, channel_id: st
messages = self._backend.get_latest_messages(channel_id=channel_id)

for message in messages:
match = re.search(PR_URL_PATTERN, message.text)

if match is None:
continue

# Examples:
# https://github.com/owner/repo/pull/6/files
# https://github.com/owner/repo/pull/6/s
url = match.group("url")

if not url.startswith(pr_url):
continue

return message.timestamp
for match in re.finditer(PR_URL_PATTERN, message.text):
# Examples:
# https://github.com/owner/repo/pull/6/files
# https://github.com/owner/repo/pull/6/s
url = match.group("url")

if url.startswith(pr_url):
return message.timestamp

return None

Expand Down
15 changes: 15 additions & 0 deletions tests/test_slapr.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ def _user(login: str) -> MockUser:
["test_review_started", "test_approved"],
id="approval",
),
pytest.param(
[
Message(
text=(
"<!subteam^S1234> CR Please - "
"<https://github.com/example/repo/pull/42|github.com/example/repo/pull/42>"
),
timestamp="yyyy-mm-dd",
)
],
[Review(state="approved", user=_user("alice"))],
[],
["test_review_started", "test_approved"],
id="approval-with-user-group-mention-before-link",
),
pytest.param(
[Message(text="Need :eyes: <https://github.com/example/repo/pull/42>", timestamp="yyyy-mm-dd")],
[Review(state="changes_requested", user=_user("alice"))],
Expand Down
Loading