Skip to content

Remove autolink to bpo ticket. #196

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

Closed
wants to merge 1 commit into from
Closed
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
65 changes: 0 additions & 65 deletions bedevere/bpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,6 @@ async def removed_label(event, gh, *args, session, **kwargs):
await set_status(event, gh, session=session)


@router.register("issue_comment", action="edited")
@router.register("issue_comment", action="created")
@router.register("commit_comment", action="edited")
@router.register("commit_comment", action="created")
@router.register("pull_request", action="edited")
@router.register("pull_request", action="opened")
async def hyperlink_bpo_text(event, gh, *args, **kwargs):
if "pull_request" in event.data:
event_name = "pull_request"
body_location = "issue_url"
else:
event_name = "comment"
body_location = "url"
if "body" in event.data[event_name] and body_location in event.data[event_name]:
body = event.data[event_name]["body"] or ""
new_body = create_hyperlink_in_comment_body(body)
if new_body != body:
body_data = {"body": new_body}
await gh.patch(event.data[event_name][body_location], data=body_data)


def create_success_status(issue_number):
"""Create a success status for when an issue number was found in the title."""
url = f"https://bugs.python.org/issue{issue_number}"
Expand All @@ -128,50 +107,6 @@ def create_failure_status_no_issue():
target_url=url)


def check_hyperlink(match):
"""The span checking of regex matches takes care of cases like bpo-123 [bpo-123]…"""
issue = match.group("issue")
markdown_link_re = re.compile(r"""
\[[^\]]*bpo-(?P<issue>{issue})[^\]]*\]
\(\s*https://bugs.python.org/issue{issue}\s*\)""".format(issue=issue),
re.VERBOSE)
html_link_re = re.compile(r""" <a
\s*href\s*=\s*[",']\s*
https://bugs.python.org/issue{issue}
\s*[",']\s*>
\s*bpo-(?P<issue>{issue})\s*
</a>""".format(issue=issue),
re.VERBOSE)
for markdown_match in markdown_link_re.finditer(match.string):
if markdown_match.span("issue") == match.span("issue"):
return markdown_match.end()
for html_match in html_link_re.finditer(match.string):
if html_match.span("issue") == match.span("issue"):
return html_match.end()

return False


def create_hyperlink_in_comment_body(body):
"""Uses infinite loop for updating the string being searched dynamically."""
new_body = ""
leftover_body = body
while True:
match = ISSUE_RE.search(leftover_body)
if match is None:
break
presence = check_hyperlink(match)
if presence is False:
new_body = new_body + leftover_body[:match.start()]
leftover_body = leftover_body[match.end():]
new_body = new_body + match.expand(r"[bpo-\g<issue>](https://bugs.python.org/issue\g<issue>)")
else:
new_body = new_body + leftover_body[:presence]
leftover_body = leftover_body[presence:]
new_body = new_body + leftover_body
return new_body


async def _validate_issue_number(issue_number, session):
"""Make sure the issue number exists on bugs.python.org."""
url = f"https://bugs.python.org/issue{issue_number}"
Expand Down