Skip to content

Commit 3a0702e

Browse files
committed
Fixes python#3: Uses simple string to find the issue-number
1 parent cb5c042 commit 3a0702e

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

bedevere/bpo.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@
44

55

66
router = routing.Router()
7-
re1='(<!--.*?-->)' # HTML Comment 1
8-
re2='.*?' # Non-greedy match on filler
9-
re3='((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))' # HTTP URL 1
10-
re4='.*?' # Non-greedy match on filler
11-
re5='(<!--.*?-->)' # HTML Comment 2
12-
BPO_URL_RE = re.compile(re1+re2+re3+re4+re5,re.IGNORECASE|re.DOTALL)
13-
BPO_MSG = """{0}
14-
<!-- issue number -->
15-
{1}
16-
<!-- /issue number -->"""
7+
TAG_NAME = "issue-number"
8+
CLOSING_TAG = f"<!-- /{TAG_NAME} -->"
9+
1710
ISSUE_RE = re.compile(r"bpo-(?P<issue>\d+)")
1811
STATUS_TEMPLATE = {"context": "bedevere/issue-number"}
1912
FAILURE_STATUS = STATUS_TEMPLATE.copy()
@@ -53,11 +46,14 @@ async def set_status(event, gh, *args, **kwargs):
5346
else:
5447
if "body" in event.data["pull_request"]:
5548
body = event.data["pull_request"]["body"]
56-
bpo_url_found = BPO_URL_RE.search(body)
57-
if not bpo_url_found:
58-
issue_number = issue_number_found.group(1)
59-
bpo_url = f"https://bugs.python.org/issue{issue_number}"
60-
data = {"body": BPO_MSG.format(body, bpo_url)}
49+
if CLOSING_TAG not in body:
50+
issue_number = issue_number_found.group("issue")
51+
BPO_MSG = f"""{body}\n
52+
<!-- {TAG_NAME}: bpo-{issue_number} -->
53+
https://bugs.python.org/issue{issue_number}
54+
{CLOSING_TAG}
55+
"""
56+
data = {"body": BPO_MSG}
6157
await _patch_body(event, gh, data)
6258
status = create_success_status(issue_number_found)
6359
await _post_status(event, gh, status)

tests/test_bpo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ async def test_set_body_failure():
239239
"statuses_url": "https://api.github.com/blah/blah/git-sha",
240240
"url": "https://api.github.com/repos/blah/blah/pulls/1347",
241241
"title": "[3.6] bpo-1234: an issue!",
242-
"body": """The body.\n<!-- issue number -->\n"https://bugs.python.org/issue1234"\n<!-- /issue number -->"""
242+
"body": """The body.\n<!-- issue-number: bpo-1234 -->\n"https://bugs.python.org/issue1234"\n<!-- /issue-number -->"""
243243
},
244244
}
245245
event = sansio.Event(data, event="pull_request", delivery_id="12345")

0 commit comments

Comments
 (0)