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: Support BitBucket's issue reference #2466

Merged
merged 1 commit into from May 7, 2018

Conversation

virresh
Copy link
Member

@virresh virresh commented May 5, 2018

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

  • 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!

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.

The commit shortlog doesnt describe the patch changes very well.

@@ -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+)',
Copy link
Member

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??

Copy link
Member Author

@virresh virresh May 6, 2018

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.

@virresh
Copy link
Member Author

virresh commented May 6, 2018

I have removed the leading link match, although it doesn't support the close issue #11 kind of style in bitbucket,
I tried adding the matching r' ?(?:bug|issue|ticket)? to SUPPORTED_HOST_KEYWORD, but inside the check_issue_reference it always ends up picking issue as the issue reference instead of #11 in case of closes and resolves, but it works for fixes ( example )
And making further non-capture groups breaks the logic for regexes below

@virresh
Copy link
Member Author

virresh commented May 6, 2018

Used an ugly hack:
The SUPPORTED_HOST_KEYWORD_REGEX is no longer a proper regex for bitbucket, instead it needs to be wrapped in a enclosing non-capturing clause.

This will work in the current arrangement since we replace SUPPORTED_HOST_KEYWORD_REGEX using a .format() into a template such as (?:{0})

'bitbucket': (r'[Cc]los(?:e[sd]?|ing)'
r'|[Rr]esolv(?:e[sd]?|ing)'
r'|[Ff]ix(?:e[sd]|ing)?'
r')(?: ?(?:bug|issue|ticket)?'),
Copy link
Member

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.

Copy link
Member

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/).

Copy link
Member Author

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 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated @ksdme
Please review :)

'bitbucket': (r'[Cc]los(?:e[sd]?|ing)'
r'|[Rr]esolv(?:e[sd]?|ing)'
r'|[Ff]ix(?:e[sd]|ing)?'
r')(?:(?:[ \t]*(?:bug|issue|ticket)?)?'),
Copy link
Member

@ksdme ksdme May 6, 2018

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).

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried it for this and this
And no whitespace still works for closing the issue,

So should I go ahead and check that for one or more spaces then ?

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 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.

Copy link
Member Author

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 ?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

@virresh virresh May 6, 2018

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 😅

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh
Cool
Thanks @ksdme

Copy link
Member Author

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

'bitbucket': (r'[Cc]los(?:e[sd]?|ing)'
r'|[Rr]esolv(?:e[sd]?|ing)'
r'|[Ff]ix(?:e[sd]|ing)?'
r')(?:(?:[ \t]*(?:bug|issue|ticket)?)?'),
Copy link
Member

@ksdme ksdme May 6, 2018

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.

@virresh virresh changed the title GitCommitBear: Mandate Valid Issue reference GitCommitBear: Support bitbucket's issue reference May 6, 2018
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.

bitbucket->BitBucket

'Another line, blablablablablabla.\n'
'Closesticket #1112')
self.assertEqual(self.run_uut(
body_close_issue=True), [])
Copy link
Member

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?

Copy link
Member Author

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 😅

Copy link
Member

@ksdme ksdme May 6, 2018

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.

@jayvdb jayvdb changed the title GitCommitBear: Support bitbucket's issue reference GitCommitBear: Support BitBucket's issue reference May 6, 2018
@@ -34,14 +34,22 @@ class GitCommitBear(GlobalBear):
'issue': r'(?:\w+/\w+)?#(\S+)',
'full issue': r'https?://gitlab\S+/issues/(\S+)',
},
'bitbucket': {
'issue': r'#(\S+)',
Copy link
Member

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+).

Copy link
Member

@ksdme ksdme left a 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.

'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]*)?))'),
Copy link
Member

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.

}
SUPPORTED_HOST_KEYWORD_REGEX = {
'github': (r'[Cc]lose[sd]?'
'github': (r'(?:[Cc]lose[sd]?'
Copy link
Member

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.

Copy link
Member Author

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

@@ -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,
Copy link
Member

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.

@virresh virresh force-pushed the virresh/bitbucket branch 2 times, most recently from 5507287 to 5b240a8 Compare May 7, 2018 14:05
@virresh
Copy link
Member Author

virresh commented May 7, 2018

Supported only the sane version of <command> <issue id>

Please review @ksdme :)

Copy link
Member

@ksdme ksdme left a 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.

@virresh
Copy link
Member Author

virresh commented May 7, 2018

Thanks @ksdme
The shortlog was exceeding character limit, so replaced support with add 😅

@@ -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')
Copy link
Member

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?

Copy link
Member Author

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 😅

@@ -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
Copy link
Member

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.

self.run_git_command('remote', 'set-url', 'test',
'git@bitbucket.org:user/repo.git')

# Unsupported Host and Issue reference combination - Bitbucket
Copy link
Member

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
@jayvdb
Copy link
Member

jayvdb commented May 7, 2018

ack 33cd9e4

@jayvdb
Copy link
Member

jayvdb commented May 7, 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.

GitCommitBear: Require the commit message contains a valid issue reference
4 participants