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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion bears/vcs/git/GitCommitBear.py
Original file line number Diff line number Diff line change
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'#(\d+)',
'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
126 changes: 124 additions & 2 deletions tests/vcs/git/GitCommitBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,136 @@ def test_check_issue_reference(self):
self.run_git_command('remote', 'add', 'test',
'https://bitbucket.com/user/repo.git')

# Unsupported Host - 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')

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'
'Fix 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),
['Invalid issue reference: bug#1112'])

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'])

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