Skip to content

Commit

Permalink
GitCommitBear: Support bitbucket
Browse files Browse the repository at this point in the history
Require the issue reference to be valid in accordance with the hoster.
For e.g disallow full issue reference for bitbucket

Closes coala#1134
  • Loading branch information
virresh committed May 6, 2018
1 parent 3773249 commit de28f74
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 4 deletions.
14 changes: 13 additions & 1 deletion bears/vcs/git/GitCommitBear.py
Expand Up @@ -34,14 +34,21 @@ 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)?'),
}
CONCATENATION_KEYWORDS = [r',', r'\sand\s']

Expand Down Expand Up @@ -324,6 +331,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
75 changes: 72 additions & 3 deletions tests/vcs/git/GitCommitBearTest.py
Expand Up @@ -298,16 +298,85 @@ 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'
'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 de28f74

Please sign in to comment.