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

Automatically hyperlink bpo- text. (#103) #121

Merged
merged 4 commits into from
Jul 27, 2018

Conversation

storymode7
Copy link
Contributor

@storymode7 storymode7 commented Jul 14, 2018

Hey, This aims to fix #103 .
If anything needs any improvement please hint me, I'll fix it up in the best manner I can 😄
(I added the changes to bpo.py, if you find it inappropriate, please suggest where it'd suite better)

@codecov
Copy link

codecov bot commented Jul 14, 2018

Codecov Report

Merging #121 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #121    +/-   ##
======================================
  Coverage     100%   100%            
======================================
  Files          20     20            
  Lines        1332   1482   +150     
  Branches       72     85    +13     
======================================
+ Hits         1332   1482   +150
Impacted Files Coverage Δ
tests/test_bpo.py 100% <100%> (ø) ⬆️
bedevere/bpo.py 100% <100%> (ø) ⬆️
bedevere/backport.py 100% <0%> (ø) ⬆️
tests/test_backport.py 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44aff09...1840cf4. Read the comment docs.

Copy link
Member

@Mariatta Mariatta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Great start. I have some nitpicky comments.
I also think the hyperlinking should be done when the PR is opened/edited.

data = {
"action": "created",
"comment": {
"url":"https://api.github.com/repos/blah/blah/issues/comments/123456",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after "url":.
Same for the lines 302, 319, 320, 336, 337, 358, 359

@@ -83,10 +83,67 @@
await set_status(event, gh)


@router.register("issue_comment", action="edited")
@router.register("issue_comment", action="created")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking that the hyperlinking should also be done on pull_request opened and edited events.
The body will be event.data["pull_request"]["body"] instead of event.data["comment"]["body"].
And the patch url to be used in line 93 will be event.data["pull_request"]["issue_url"].

Copy link
Contributor Author

@storymode7 storymode7 Jul 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing! 🙂
Just a small question:
Wouldn't it be better if the bot hyperlinks bpo- text in the comment? As

  • the pull request body already contains the link of the issue.
  • Also, few (510 out of 7,525) PRs have bpo- text in the body.

Please correct me if I am wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I meant to do this in both issue_comment and pull_request body.

The PR body already contains the link to the bpo that is mentioned in the PR title, and we should leave that as is.
I just think it would be nice to be also able to refer to other bpo tickets in the PR body.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Thanks!
I get it now 🙂

bedevere/bpo.py Outdated
\s*bpo-(?P<issue>{issue})\s*
</a>""".format(issue=issue),
re.VERBOSE)
# The following approach takes care of cases like bpo-123 [bpo-123]...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the comments here and in line 126 should be part of docstring instead of inline codes.

bedevere/bpo.py Outdated
def create_hyperlink_in_comment_body(body):
new_body = ''
leftover_body = body
# Using infinite while loop as it supports updation of the string being
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer these comments as docstrings.

Copy link
Member

@Mariatta Mariatta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great. Just some other nitpicky things..

bedevere/bpo.py Outdated


def create_hyperlink_in_comment_body(body):
"""Uses infinite loop for updating the string being searched dynamically"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing period at the end of the sentence.

@pytest.mark.asyncio
async def test_set_comment_body_success():
data = {
"action": "opened",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're only testing for the pull_request opened event.
Can you also test for the pull_request edited, issue_comment created, and issue_comment edited events?
Probably you can use pytest.mark.parametrize for it.

And please do the same for the other two tests below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! pytest.mark.parametrize was great!
I've used the changes key in the pull_request event's data for both action opened and edited. It keeps the both the cases to be used from single function. I hope it wont be a problem 🙂

await bpo.router.dispatch(event, gh)
body_data = gh.patch_data
assert body_data["body"].count("[bpo-123](https://www.bugs.python.org/issue123)") == 2
assert '123456' in gh.patch_url
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use double quotes to be consistent with the rest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really sorry for this error. I fixed this, and there was one previous occurence, so I fixed that too.
If the change for previous occurence of single quotes shouldn't have been done, I'll be happy to revert that change 🙂

bedevere/bpo.py Outdated

def check_hyperlink(match):
"""The span checking of regex matches takes care of cases like bpo-123 [bpo-123]…"""
issue = match.group('issue')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use double quotes for your changes.
I know we haven't been consistent in the past, but since this is new code, might as well be more consistent about it. :)

Copy link
Member

@Mariatta Mariatta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I removed a couple extra blank lines, but I think the rest looks great :)

@Mariatta Mariatta merged commit 93a67e3 into python:master Jul 27, 2018
@Mariatta
Copy link
Member

Thanks!! 🌮

if presence is False:
new_body = new_body + leftover_body[:match.start()]
leftover_body = leftover_body[match.end():]
new_body = new_body + match.expand("[bpo-\g<issue>](https://www.bugs.python.org/issue\g<issue>)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See python/core-workflow#292. I think www. is redundant here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's not accurate.

"""Uses infinite loop for updating the string being searched dynamically."""
new_body = ""
leftover_body = body
ISSUE_RE = re.compile(r"bpo-(?P<issue>\d+)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't word boundary anchors \b needed here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably wouldn't hurt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically hyperlink bpo- text
5 participants