Skip to content

Commit

Permalink
GitCommitBear: Support bitbucket's issue reference
Browse files Browse the repository at this point in the history
Add support for BitBucket as a hoster and support it's limited issue
referencing style.

Closes coala#1134
  • Loading branch information
virresh committed May 6, 2018
1 parent 3773249 commit 0a100a9
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 4 deletions.
15 changes: 14 additions & 1 deletion bears/vcs/git/GitCommitBear.py
Expand Up @@ -34,14 +34,22 @@ class GitCommitBear(GlobalBear):
'issue': r'(?:\w+/\w+)?#(\S+)',
'full issue': r'https?://gitlab\S+/issues/(\S+)',
},
'bitbucket': {
'issue': r'#(\S+)',
'full issue': None,
},
}
SUPPORTED_HOST_KEYWORD_REGEX = {
'github': (r'[Cc]lose[sd]?'
r'|[Rr]esolve[sd]?'
r'|[Ff]ix(?:e[sd])?'),
'gitlab': (r'[Cc]los(?:e[sd]?|ing)'
r'|[Rr]esolv(?:e[sd]?|ing)'
r'|[Ff]ix(?:e[sd]|ing)?')
r'|[Ff]ix(?:e[sd]|ing)?'),
'bitbucket': (r'[Cc]los(?:e[sd]?|ing)'
r'|[Rr]esolv(?:e[sd]?|ing)'
r'|[Ff]ix(?:e[sd]|ing)?'
r')(?:(?:[ \t]*(?:bug|issue|ticket)?)?'),
}
CONCATENATION_KEYWORDS = [r',', r'\sand\s']

Expand Down Expand Up @@ -324,6 +332,11 @@ def check_issue_reference(self, body,
else:
self.issue_type = 'issue'

if self.ISSUE_INFO[host][self.issue_type] is None:
yield Result(self, 'Host {} does not support {} '
'reference.'.format(host, self.issue_type))
return

if body_close_issue_on_last_line:
if body:
body = body.splitlines()[-1]
Expand Down
96 changes: 93 additions & 3 deletions tests/vcs/git/GitCommitBearTest.py
Expand Up @@ -298,16 +298,106 @@ 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')

# Unsupported Host - Bitbucket
# Unsupported Host and Issue reference combination - Bitbucket
self.git_commit('Shortlog\n\n'
'First line, blablablablablabla.\n'
'Another line, blablablablablabla.\n'
'Closes #1112')
self.assertEqual(self.run_uut(
body_close_issue=True,
body_close_issue_full_url=True), [])
body_close_issue_full_url=True),
['Host bitbucket does not support full issue '
'reference.'])

self.git_commit('Shortlog\n\n'
'First line, blablablablablabla.\n'
'Another line, blablablablablabla.\n'
'Closes #1112')
self.assertEqual(self.run_uut(
body_close_issue=True), [])

self.git_commit('Shortlog\n\n'
'First line, blablablablablabla.\n'
'Another line, blablablablablabla.\n'
'Resolves https://bitbucket.org/user/repo/issues/1/')
self.assertEqual(self.run_uut(
body_close_issue=True),
['Invalid issue reference: '
'https://bitbucket.org/user/repo/issues/1/'])

self.git_commit('Shortlog\n\n'
'First line, blablablablablabla.\n'
'Another line, blablablablablabla.\n'
'Resolves https://bitbucket.org/user/repo/issues/1/')
self.assertEqual(self.run_uut(
body_close_issue=True,
body_close_issue_full_url=True),
['Host bitbucket does not support full issue '
'reference.'])

# Adding BitBucket's ssh remote for testing
self.run_git_command('remote', 'set-url', 'test',
'git@bitbucket.org:user/repo.git')

# Unsupported Host and Issue reference combination - Bitbucket
self.git_commit('Shortlog\n\n'
'First line, blablablablablabla.\n'
'Another line, blablablablablabla.\n'
'Closes #1112')
self.assertEqual(self.run_uut(
body_close_issue=True,
body_close_issue_full_url=True),
['Host bitbucket does not support full issue '
'reference.'])

self.git_commit('Shortlog\n\n'
'First line, blablablablablabla.\n'
'Another line, blablablablablabla.\n'
'Closes #1112')
self.assertEqual(self.run_uut(
body_close_issue=True), [])

self.git_commit('Shortlog\n\n'
'First line, blablablablablabla.\n'
'Another line, blablablablablabla.\n'
'Fixes issue #1112')
self.assertEqual(self.run_uut(
body_close_issue=True), [])

self.git_commit('Shortlog\n\n'
'First line, blablablablablabla.\n'
'Another line, blablablablablabla.\n'
'Resolving bug #1112')
self.assertEqual(self.run_uut(
body_close_issue=True), [])

self.git_commit('Shortlog\n\n'
'First line, blablablablablabla.\n'
'Another line, blablablablablabla.\n'
'Closesticket #1112')
self.assertEqual(self.run_uut(
body_close_issue=True), [])

self.git_commit('Shortlog\n\n'
'First line, blablablablablabla.\n'
'Another line, blablablablablabla.\n'
'Resolves https://bitbucket.org/user/repo/issues/1/')
self.assertEqual(self.run_uut(
body_close_issue=True),
['Invalid issue reference: '
'https://bitbucket.org/user/repo/issues/1/'])

self.git_commit('Shortlog\n\n'
'First line, blablablablablabla.\n'
'Another line, blablablablablabla.\n'
'Resolves https://bitbucket.org/user/repo/issues/1/')
self.assertEqual(self.run_uut(
body_close_issue=True,
body_close_issue_full_url=True),
['Host bitbucket does not support full issue '
'reference.'])

# Adding GitHub remote for testing, ssh way :P
self.run_git_command('remote', 'set-url', 'test',
Expand Down

0 comments on commit 0a100a9

Please sign in to comment.