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

GitCommitBear: Refactor issue regexes #2459

Merged
merged 1 commit into from May 4, 2018

Conversation

virresh
Copy link
Member

@virresh virresh commented Apr 30, 2018

Increased modularity by delegating the task of selecting issue
regex to another function

Closes #2396

For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!

Checklist

  • I read the commit guidelines and I've followed
    them.
  • I ran coala over my code locally. (All commits have to pass
    individually.
    It is not sufficient to have "fixup commits" on your PR,
    our bot will still report the issues for the previous commit.) You will
    likely receive a lot of bot comments and build failures if coala does not
    pass on every single commit!

After you submit your pull request, DO NOT click the 'Update Branch' button.
When asked for a rebase, consult coala.io/rebase
instead.

Please consider helping us by reviewing other peoples pull requests as well:

The more you review, the more your score will grow at coala.io and we will
review your PRs faster!

@jayvdb
Copy link
Member

jayvdb commented May 1, 2018

@gitmate-bot rebase

@gitmate-bot
Copy link
Collaborator

Hey! I'm GitMate.io! This pull request is being rebased automatically. Please DO NOT push while rebase is in progress or your changes would be lost permanently ⚠️

@gitmate-bot
Copy link
Collaborator

Automated rebase with GitMate.io was successful! 🎉

result_info = 'issue'
issue_ref_regex = r'(?:\w+/\w+)?#(\S+)'
self.initialise_issue_ref_regex(body_close_issue_full_url,
result_message,
Copy link
Member

Choose a reason for hiding this comment

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

ewww, you have a return value being put in result_message

The current repository's host
"""
if body_close_issue_full_url:
self.ISSUE_TYPE = 'full issue'
Copy link
Member

Choose a reason for hiding this comment

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

these are instance variables, not class variables like the issue requested.

you should have one class variable which is a regex with named groups which tells you everything you need to know.

Issue type can be derived from the result match data.

Copy link
Member

Choose a reason for hiding this comment

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

The class variable will need to be like SUPPORTED_HOST_KEYWORD_REGEX, being a dictionary with an entry for each hoster.

I think the scope of this patch needs to be "GitCommitBear: Add BitBucket support" , which would dovetail with HgCommit bear which would add Hg-on-BitBucket support.

This is roughly #1134

Copy link
Member Author

Choose a reason for hiding this comment

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

Does this mean that we have regex entries for each host and each type ?
Like

{
    'github' : {
                     'issue' : r(some regex),
                     'full issue' : r(some regex)
                   },
    'some other hoster' :{ ... }
}

r'https?://{}\S+/issues/(\S+)'.format(re.escape(host)))
else:
self.ISSUE_TYPE = 'issue'
self.ISSUE_REF_REGEX = r'(?:\w+/\w+)?#(\S+)'
Copy link
Member

Choose a reason for hiding this comment

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

The difference between this and 'hg' URLs, is not actually related to hg at all.

These URLs, and the differences, are a property of the hoster, not the vcs software being used.

see #2310 (review)

@virresh
Copy link
Member Author

virresh commented May 3, 2018

Also once Git Commit bear supports bitbucket, we need to have an extra check around if body_close_fullissue_url to ensure that full issue is indeed supported by the host (since bitbucket doesn't support that)

Copy link
Member

@jayvdb jayvdb left a comment

Choose a reason for hiding this comment

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

Getting very close.

@@ -25,6 +25,16 @@ class GitCommitBear(GlobalBear):
LICENSE = 'AGPL-3.0'
ASCIINEMA_URL = 'https://asciinema.org/a/e146c9739ojhr8396wedsvf0d'
CAN_DETECT = {'Formatting'}
ISSUE_INFO = {
'github': {
'issue': r'(?:\w+/\w+)?#(\S+)',
Copy link
Member

Choose a reason for hiding this comment

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

'issue' should be indented four spaces from 'github', i.e. appearing under hub..

ISSUE_INFO = {
'github': {
'issue': r'(?:\w+/\w+)?#(\S+)',
'full issue': r'https?://github\S+/issues/(\S+)'
Copy link
Member

Choose a reason for hiding this comment

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

trailing comma

'github': {
'issue': r'(?:\w+/\w+)?#(\S+)',
'full issue': r'https?://github\S+/issues/(\S+)'
},
Copy link
Member

Choose a reason for hiding this comment

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

closing bracket should be at the same level as 'github'

'gitlab': {
'issue': r'(?:\w+/\w+)?#(\S+)',
'full issue': r'https?://gitlab\S+/issues/(\S+)'
}
Copy link
Member

Choose a reason for hiding this comment

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

add trailing commas (everywhere)

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I put them in the SUPPORTED_HOST_KEYWORD_REGEX as well ?
(or that be left for a newcomer issue ?)

return

if body_close_issue_full_url:
self.ISSUE_INFO['type'] = 'full issue'
Copy link
Member

Choose a reason for hiding this comment

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

dont modify the class constant self.ISSUE_INFO.

It stops being a constant.

use an instance variable.

return

if body_close_issue_full_url:
self.issueType = 'full issue'
Copy link
Member

Choose a reason for hiding this comment

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

issueType -> issue_type . pep8 compliant naming

result_info = 'full issue'
issue_ref_regex = (
r'https?://{}\S+/issues/(\S+)'.format(re.escape(host)))
result_message = ('Body of HEAD commit does not contain any '
Copy link
Member

Choose a reason for hiding this comment

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

if you keep {} ' at the end of this line, it wont be modified, making your diff much smaller.

Also you dont need to change either of the result_message = ... statements.

You can just add below

    result_message = result_message.format(self.issue_type)

@@ -359,7 +369,8 @@ def check_issue_reference(self, body,
reference = compiled_issue_ref_regex.fullmatch(issue)
if not reference:
yield Result(self, 'Invalid {} reference: '
'{}'.format(result_info, issue))
'{}'.format(
self.issueType, issue))
Copy link
Member

Choose a reason for hiding this comment

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

either put .format on this line, or intend this line another 3 spaces. pycodestyle isnt perfect - it will accept a lot of non-pep8 compliant indentations because it is quite a difficult problem to know the correct indentation level needed. But the fact you have a one space indentation here should be a clue that it is wrong even if pycodestyle accepts it.

Increased modularity by delegating the task of selecting issue
regex to a new class variable

Closes coala#2396
@jayvdb
Copy link
Member

jayvdb commented May 4, 2018

ack 97e9890

@jayvdb
Copy link
Member

jayvdb commented May 4, 2018

@gitmate-bot ff

@gitmate-bot
Copy link
Collaborator

Hey! I'm GitMate.io! This pull request is being fastforwarded automatically. Please DO NOT push while fastforward is in progress or your changes would be lost permanently ⚠️

@gitmate-bot
Copy link
Collaborator

Automated fastforward with GitMate.io was successful! 🎉

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

Successfully merging this pull request may close these issues.

Refactor issue Regexes in GitCommitBear
3 participants