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
Conversation
@gitmate-bot rebase |
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 |
Automated rebase with GitMate.io was successful! 🎉 |
bears/vcs/git/GitCommitBear.py
Outdated
result_info = 'issue' | ||
issue_ref_regex = r'(?:\w+/\w+)?#(\S+)' | ||
self.initialise_issue_ref_regex(body_close_issue_full_url, | ||
result_message, |
There was a problem hiding this comment.
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
bears/vcs/git/GitCommitBear.py
Outdated
The current repository's host | ||
""" | ||
if body_close_issue_full_url: | ||
self.ISSUE_TYPE = 'full issue' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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' :{ ... }
}
bears/vcs/git/GitCommitBear.py
Outdated
r'https?://{}\S+/issues/(\S+)'.format(re.escape(host))) | ||
else: | ||
self.ISSUE_TYPE = 'issue' | ||
self.ISSUE_REF_REGEX = r'(?:\w+/\w+)?#(\S+)' |
There was a problem hiding this comment.
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)
Also once Git Commit bear supports bitbucket, we need to have an extra check around |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting very close.
bears/vcs/git/GitCommitBear.py
Outdated
@@ -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+)', |
There was a problem hiding this comment.
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..
bears/vcs/git/GitCommitBear.py
Outdated
ISSUE_INFO = { | ||
'github': { | ||
'issue': r'(?:\w+/\w+)?#(\S+)', | ||
'full issue': r'https?://github\S+/issues/(\S+)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing comma
bears/vcs/git/GitCommitBear.py
Outdated
'github': { | ||
'issue': r'(?:\w+/\w+)?#(\S+)', | ||
'full issue': r'https?://github\S+/issues/(\S+)' | ||
}, |
There was a problem hiding this comment.
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'
bears/vcs/git/GitCommitBear.py
Outdated
'gitlab': { | ||
'issue': r'(?:\w+/\w+)?#(\S+)', | ||
'full issue': r'https?://gitlab\S+/issues/(\S+)' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add trailing commas (everywhere)
There was a problem hiding this comment.
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 ?)
bears/vcs/git/GitCommitBear.py
Outdated
return | ||
|
||
if body_close_issue_full_url: | ||
self.ISSUE_INFO['type'] = 'full issue' |
There was a problem hiding this comment.
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.
76164f0
to
9566efc
Compare
bears/vcs/git/GitCommitBear.py
Outdated
return | ||
|
||
if body_close_issue_full_url: | ||
self.issueType = 'full issue' |
There was a problem hiding this comment.
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
bears/vcs/git/GitCommitBear.py
Outdated
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 ' |
There was a problem hiding this comment.
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)
bears/vcs/git/GitCommitBear.py
Outdated
@@ -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)) |
There was a problem hiding this comment.
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
ack 97e9890 |
@gitmate-bot ff |
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 |
Automated fastforward with GitMate.io was successful! 🎉 |
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
them.
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:
corobo mark wip <URL>
to get it outof the review queue.
The more you review, the more your score will grow at coala.io and we will
review your PRs faster!