Commit c2f487ed authored by krutam's avatar krutam Check sha after word ack

Closes #330
parent 5f5519fb
Pipeline #18834651 passed with stages
in 3 minutes and 30 seconds
......@@ -14,6 +14,8 @@ from gitmate_config.models import Repository
from gitmate_hooks.utils import ResponderRegistrar
from .models import MergeRequestModel
sha_regex = r'\b[0-9a-f]{5,40}\b'
sha_compiled = re.compile(sha_regex)
def _get_commit_hash(commit: Commit):
......@@ -106,8 +108,12 @@ def gitmate_ack(pr: MergeRequest,
perm_level = pr.repository.get_permission_level(
comment_slices = map_comment_parts_to_keywords(ack_strs, unack_strs, body)
has_commit_sha = any(
for _list in comment_slices.values()
for string in _list)
# return right away if the comment isn't related to ack / unack command
if not any(comment_slices):
if not any(comment_slices) or not has_commit_sha:
elif perm_level.value < AccessLevel.CAN_WRITE.value:
msg = ('Sorry @{}, you do not have the necessary permission '
......@@ -372,6 +372,18 @@ class TestAck(GitmateTestCase):
(Status.SUCCESS, 'review/gitmate/manual'),
(Status.SUCCESS, 'review/gitmate/manual/pr')])
@patch.object(GitLabComment, 'body', new_callable=PropertyMock)
@patch.object(GitLabMergeRequest, 'add_comment')
def test_gitlab_ack_returning_none(
self, m_add_comment, m_body
m_body.return_value = 'Might get ack after this change.'
response = self.simulate_gitlab_webhook_call('Merge Request Hook',
response = self.simulate_gitlab_webhook_call('Note Hook',
@patch.object(GitLabMergeRequest, 'commits', new_callable=PropertyMock)
@patch.object(GitLabComment, 'body', new_callable=PropertyMock)
@patch.object(GitLabComment, 'author', new_callable=PropertyMock)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment