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 7, 2018
1 parent 3773249 commit aa90c3f
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 8 deletions.
23 changes: 18 additions & 5 deletions 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]?'
'github': (r'(?:[Cc]lose[sd]?'
r'|[Rr]esolve[sd]?'
r'|[Ff]ix(?:e[sd])?'),
'gitlab': (r'[Cc]los(?:e[sd]?|ing)'
r'|[Ff]ix(?:e[sd])?)\s+'),
'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)?)\s+'),
'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]*)?))'),
}
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 All @@ -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,
# eg: fix, closes etc.

r'((?:\S(?!{1}))*\S' # match links/tags
Expand Down
129 changes: 126 additions & 3 deletions tests/vcs/git/GitCommitBearTest.py
Expand Up @@ -298,16 +298,139 @@ 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,
body_enforce_issue_reference=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,
body_enforce_issue_reference=True), [])

self.git_commit('Shortlog\n\n'
'First line, blablablablablabla.\n'
'Another line, blablablablablabla.\n'
'Fixed randomkeyword#1112')
self.assertEqual(self.run_uut(
body_close_issue=True,
body_enforce_issue_reference=True),
['Invalid issue reference: randomkeyword#1112'])

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_enforce_issue_reference=True),
['Body of HEAD commit does not contain any '
'issue reference.'])

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

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,
body_enforce_issue_reference=True),
['Body of HEAD commit does not contain any '
'issue reference.'])

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 aa90c3f

Please sign in to comment.