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: Support BitBucket's issue reference #2466
Conversation
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 commit shortlog doesnt describe the patch changes very well.
bears/vcs/git/GitCommitBear.py
Outdated
@@ -34,14 +34,21 @@ class GitCommitBear(GlobalBear): | |||
'issue': r'(?:\w+/\w+)?#(\S+)', | |||
'full issue': r'https?://gitlab\S+/issues/(\S+)', | |||
}, | |||
'bitbucket': { | |||
'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.
I think the (?:\w+/\w+)?
here is not supported by bitbucket??
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.
I think bitbucket allows an issue to be referred to using
close #11
or some word in between like close issue #11
or close bug #11
or close ticket #11
So I am not sure how to go about that, I thought the above regex is for scenarios where it matches a word before issue number (possibly a link to the repo), so maybe for bitbucket we can use it to serve to support these words ?
Please correct me, I am very bad at regex.
I have removed the leading link match, although it doesn't support the |
Used an ugly hack: This will work in the current arrangement since we replace SUPPORTED_HOST_KEYWORD_REGEX using a .format() into a template such as |
bears/vcs/git/GitCommitBear.py
Outdated
'bitbucket': (r'[Cc]los(?:e[sd]?|ing)' | ||
r'|[Rr]esolv(?:e[sd]?|ing)' | ||
r'|[Ff]ix(?:e[sd]|ing)?' | ||
r')(?: ?(?:bug|issue|ticket)?'), |
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.
Replace the whitespace with \s, this is because any kind of whitespace is supported during regex joining.
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 whitespace shouldn't be optional either if something is to proceed after the reference type. The regex should rather group the space and descriptor and make it optional (https://regex101.com/r/gJ9oKe/1/).
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.
Thanks @ksdme
But I am not sure if we want to match with a newline or carriage return (since a \n
or \r
do not result in closing of the issue
Though yes thanks for pointing this out, multiple spaces and tabs do need to be accomodated 😅
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.
Updated @ksdme
Please review :)
bears/vcs/git/GitCommitBear.py
Outdated
'bitbucket': (r'[Cc]los(?:e[sd]?|ing)' | ||
r'|[Rr]esolv(?:e[sd]?|ing)' | ||
r'|[Ff]ix(?:e[sd]|ing)?' | ||
r')(?:(?:[ \t]*(?:bug|issue|ticket)?)?'), |
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.
I am not sure about the [ \t]*
, I think you should match the whitespace characters for one or more occurrences (https://regex101.com/r/cBwJ02/1).
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.
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 match for zero or more occurrences of [ \t]
then you would essentially be depending upon https://github.com/virresh/coala-bears/blob/4ff7382a06f48267a290fba41196866052b92226/bears/vcs/git/GitCommitBear.py#L38 to find the issue with the the reference. I don't think this should be the case.
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.
So if I get it correct,
we should not allow fixesbug#11
, but we should allow fixes bug#11
?
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.
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.
Yep
I read the guidelines there, but they don't seem to emphasize on the whitespaces,
As per the guidelines even , fixesbug#11
fixesbug #11
, fixes bug#11
, fixes bug #11
, all three are valid.
So I accomodated all varieties of whitespaces. Not sure if I should limit it to only fixes bug #11
Also made a test repo, just to be sure of the effect of whitespaces 😅
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.
Although the suggested guidelines do not explicitly state anything about whitespaces it does include a space while defining the format as <command> <issue id>
and advertise this behavior in all the examples, also for the case of readability we should take it as an implicit guideline.
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.
Oh
Cool
Thanks @ksdme
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.
Opened https://bitbucket.org/site/master/issues/16240/issue-referencing-on-bitbucket-cloud
And off to support fixes bug#11
and fixes bug #11
bears/vcs/git/GitCommitBear.py
Outdated
'bitbucket': (r'[Cc]los(?:e[sd]?|ing)' | ||
r'|[Rr]esolv(?:e[sd]?|ing)' | ||
r'|[Ff]ix(?:e[sd]|ing)?' | ||
r')(?:(?:[ \t]*(?:bug|issue|ticket)?)?'), |
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 shortlog should say 'Support bitbucket type issue references' or something along those lines since you are specifically aiming to improve those aspects of the bear. The commit message could also be improved by removing the example.
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.
bitbucket->BitBucket
tests/vcs/git/GitCommitBearTest.py
Outdated
'Another line, blablablablablabla.\n' | ||
'Closesticket #1112') | ||
self.assertEqual(self.run_uut( | ||
body_close_issue=True), []) |
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.
this should be an error, yes?
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.
This works as per guidelines 😅
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.
I do not think anyone would have a reason to write it in such a skewed way. Maybe we should have an option for this bear indicating whether to stick to core guidelines or readability guidelines.
bears/vcs/git/GitCommitBear.py
Outdated
@@ -34,14 +34,22 @@ class GitCommitBear(GlobalBear): | |||
'issue': r'(?:\w+/\w+)?#(\S+)', | |||
'full issue': r'https?://gitlab\S+/issues/(\S+)', | |||
}, | |||
'bitbucket': { | |||
'issue': r'#(\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.
https://confluence.atlassian.com/sourcetreekb/link-to-bitbucket-issue-tracker-from-commits-296911608.html seems to indicates that the regex required to match an issue would rather be #(\d+)
.
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.
I think it is very clear from https://confluence.atlassian.com/bitbucket/mark-up-comments-issues-and-commit-messages-321859781.html and https://confluence.atlassian.com/bitbucket/resolve-issues-automatically-when-users-push-code-221451126.html that we should only support the syntax <command> <issue id>
irrespective of what works during commit actions. The command should also maintain readability and thus we should only support references written as fixes bug #11
.
bears/vcs/git/GitCommitBear.py
Outdated
'bitbucket': (r'(?:(?:[Cc]los(?:e[sd]?|ing)' | ||
r'|[Rr]esolv(?:e[sd]?|ing)' | ||
r'|[Ff]ix(?:e[sd]|ing))' | ||
r'(?:\s+(?:(?:bug|issue|ticket)[ \t]*)?))'), |
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 \s+
in r'(?:\s+(?:(?:bug|issue|ticket)[ \t]*)?))'),
should rather be [ \t]+
as an individual reference needs to be a single line.
bears/vcs/git/GitCommitBear.py
Outdated
} | ||
SUPPORTED_HOST_KEYWORD_REGEX = { | ||
'github': (r'[Cc]lose[sd]?' | ||
'github': (r'(?:[Cc]lose[sd]?' |
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.
I do not think changes made to the regex of hosts other than BitBucket are either necessary or in the scope of this 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.
Oh
Okay
Did that to support fixes bug#166
but not fixesbug #11
Will revert 😅
Thanks :D
bears/vcs/git/GitCommitBear.py
Outdated
@@ -337,7 +350,7 @@ def check_issue_reference(self, body, | |||
|
|||
concat_regex = '|'.join(kw for kw in self.CONCATENATION_KEYWORDS) | |||
compiled_joint_regex = re.compile( | |||
r'(?:{0})\s+' # match issue related keywords, | |||
r'(?:{0})' # match issue related keywords, |
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.
This change should be reverted too.
5507287
to
5b240a8
Compare
Supported only the sane version of Please review @ksdme :) |
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.
Everything looks good to me other than,
shortlog -> Support BitBucket type issue references &
hoster -> host in commit message.
Thanks @ksdme |
tests/vcs/git/GitCommitBearTest.py
Outdated
@@ -298,16 +298,140 @@ def test_check_issue_reference(self): | |||
|
|||
# Adding BitBucket remote for testing | |||
self.run_git_command('remote', 'add', 'test', | |||
'https://bitbucket.com/user/repo.git') | |||
'https://user@bitbucket.org/user/gittest.git') |
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.
Is there a specific reason why the test repo url needs to be changed to this?
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.
Oh
I did that to keep the url format consistent with the one suggested by bitbucket on the clone option for a repository
Although the above also redirects fine
Will change that 😅
tests/vcs/git/GitCommitBearTest.py
Outdated
@@ -300,14 +300,138 @@ def test_check_issue_reference(self): | |||
self.run_git_command('remote', 'add', 'test', | |||
'https://bitbucket.com/user/repo.git') | |||
|
|||
# Unsupported Host - Bitbucket | |||
# Unsupported Host and Issue reference combination - Bitbucket |
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 host is now supported.
tests/vcs/git/GitCommitBearTest.py
Outdated
self.run_git_command('remote', 'set-url', 'test', | ||
'git@bitbucket.org:user/repo.git') | ||
|
||
# Unsupported Host and Issue reference combination - Bitbucket |
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.
You left out this instance of the comment.
Add support for BitBucket as a host and support it's limited issue referencing style. Closes coala#1134
ack 33cd9e4 |
@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! 🎉 |
Add support for BitBucket as a hoster and support it's limited issue
referencing style.
Closes #1134
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!