Add a link to b.p.o as a comment#24
Conversation
Codecov Report
@@ Coverage Diff @@
## master #24 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 6 6
Lines 289 319 +30
Branches 11 13 +2
=====================================
+ Hits 289 319 +30
Continue to review full report at Codecov.
|
| re3='((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))' # HTTP URL 1 | ||
| re4='.*?' # Non-greedy match on filler | ||
| re5='(<!--.*?-->)' # HTML Comment 2 | ||
| BPO_URL_RE = re.compile(re1+re2+re3+re4+re5,re.IGNORECASE|re.DOTALL) |
There was a problem hiding this comment.
If you use re.VERBOSE you can do it as a multi-line string and not have to do the concatenation (https://docs.python.org/3/library/re.html#re.X). (But I have a suggestion below which if it makes sense means you don't need the regex 😃 ).
| else: | ||
| status = FAILURE_STATUS | ||
| else: | ||
| if "body" in event.data["pull_request"]: |
There was a problem hiding this comment.
Is "body" ever not in the pull request?
There was a problem hiding this comment.
Yes, there are edits (iirc) which does not have body, my test instance crashed due to this.
| else: | ||
| if "body" in event.data["pull_request"]: | ||
| body = event.data["pull_request"]["body"] | ||
| bpo_url_found = BPO_URL_RE.search(body) |
There was a problem hiding this comment.
I think I might know of a way to simplify this. If you made the format of the message be:
TAG_NAME = "issue-number
CLOSING_TAG = f"<!-- /{TAG_NAME} -->"
BPO_MSG = f"""{{body}}
<!-- {TAG_NAME}: bpo-{{issue_number}} -->
{{message}}
{CLOSING_TAG}
"""Then you can do:
if CLOSING_TAG not in body:
...That way the search is a straight-forward string search and you leave the re module out of it. And by embedding the issue number in the comment you add a little bit of extra detail that may be useful later (e.g. if someone adds support to detect a change of issue number in the title and wants to update the comment accordingly but doesn't want to worry about any format change in the message itself).
There was a problem hiding this comment.
This is something similar I did at first (personally I don't use re module that much). I will use this msg text now.
| body = event.data["pull_request"]["body"] | ||
| bpo_url_found = BPO_URL_RE.search(body) | ||
| if not bpo_url_found: | ||
| issue_number = issue_number_found.group(1) |
There was a problem hiding this comment.
issue_number_found.group("issue")
| BPO_URL_RE = re.compile(re1+re2+re3+re4+re5,re.IGNORECASE|re.DOTALL) | ||
| BPO_MSG = """{0} | ||
| <!-- issue number --> | ||
| {1} |
There was a problem hiding this comment.
Would it make sense to have a fancier message? E.g. "(Please only discuss the code in this pull request here on GitHub; all other discussion should occur on the issue at bpo-{issue_number}.)"
| bpo_url_found = BPO_URL_RE.search(body) | ||
| if not bpo_url_found: | ||
| issue_number = issue_number_found.group(1) | ||
| bpo_url = f"https://bugs.python.org/issue{issue_number}" |
There was a problem hiding this comment.
You could add this to BPO_MSG so that it's all part of the message template.
brettcannon
left a comment
There was a problem hiding this comment.
Since the changes I'm requesting are minor, I'm approving this now so you can merge once you make the changes!
| gh = FakeGH() | ||
| await bpo.router.dispatch(event, gh) | ||
| assert gh.patchdata is None | ||
| assert gh.patchurl is None No newline at end of file |
There was a problem hiding this comment.
Missing a newline at the end of the file.
| if CLOSING_TAG not in body: | ||
| issue_number = issue_number_found.group("issue") | ||
| BPO_MSG = f"""{body}\n | ||
| <!-- {TAG_NAME}: bpo-{issue_number} --> |
There was a problem hiding this comment.
To make this more readable, you can indent it and then use textwrap.dedent() to strip the leading whitespace.
| body = event.data["pull_request"]["body"] | ||
| if CLOSING_TAG not in body: | ||
| issue_number = issue_number_found.group("issue") | ||
| BPO_MSG = f"""{body}\n |
There was a problem hiding this comment.
Might as well just have an actual newline in the triple-quoted string rather than a newline literal (I actually overlooked it when I was checking that there was a newline separating the body from the link).
|
|
||
| def __init__(self, *, getitem=None): | ||
| self._getitem_return = getitem | ||
| self.patchurl = None |
There was a problem hiding this comment.
Underscores have been used in the rest of the test code, so patch_url and patch_data for consistency.
|
I just wanted to check in and make sure you're not blocked on me (no pressure, I just don't want to be a hold-up for you). |
|
I also had the time to address my own comments, so if you're happy with the resulting patch let me know and I will merge it! |
|
One thing I've noticed while playing with other GitHub stuff is they use |
|
The examples I can see don't have |
|
The commits look good, you can go ahead and merge. I got stuck in something else for the last 2 weeks :( |
| body = event.data["pull_request"]["body"] | ||
| if CLOSING_TAG not in body: | ||
| issue_number = issue_number_found.group("issue") | ||
| BPO_MSG = textwrap.dedent(f"""\ |
There was a problem hiding this comment.
Unfortunately, textwrap.dedent() doesn't work with f-strings (or there is some other reason I don't know) See https://github.com/python/bedevere/pull/27/files/dcc17d64f1c9a9d6b65703abbf697c132d76d785#r127503862 for the previous discussion.
You can see the example in my latest PR: python/cpython#2807
There was a problem hiding this comment.
Already have a fix waiting for travis to clear.
There was a problem hiding this comment.
And it's merged, so once Travis is green for master again it will go live.
And I don't know why textwrap.dedent() isn't working since I don't see how an f-string would influence the outcome in anyway. My guess is the string as being inserted has some unexpected whitespace that's throwing the algorithm off.
There was a problem hiding this comment.
Is this a bug with textwrap.dedent() or f-strings?
Worth opening an issue in b.p.o about this?
There was a problem hiding this comment.
Nope, I see what happened. Berker's body had newlines in it that led to parts of the body not being equally indented like the string literal, so when textwrap.dedent() got it there was whole chunks of text not indented so it assumed there was nothing to dedent. IOW it worked as intended and it just didn't occur to me when doing the code review that the inserted body would have newlines followed by text that wouldn't be indented.
Adds the comment in the body of the PR.