From 0e39653da97fb1606b166beae213bfae090c09ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Tue, 23 Jun 2015 18:08:09 +0200 Subject: [PATCH] Allow multiple message actions on commit --- taiga/hooks/bitbucket/event_hooks.py | 3 +-- taiga/hooks/github/event_hooks.py | 3 +-- taiga/hooks/gitlab/event_hooks.py | 3 +-- tests/integration/test_hooks_github.py | 24 ++++++++++++++++++++++++ tests/integration/test_hooks_gitlab.py | 24 ++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/taiga/hooks/bitbucket/event_hooks.py b/taiga/hooks/bitbucket/event_hooks.py index d8d9c14e..5aa86fde 100644 --- a/taiga/hooks/bitbucket/event_hooks.py +++ b/taiga/hooks/bitbucket/event_hooks.py @@ -54,8 +54,7 @@ class PushEventHook(BaseEventHook): return p = re.compile("tg-(\d+) +#([-\w]+)") - m = p.search(message.lower()) - if m: + for m in p.finditer(message.lower()): ref = m.group(1) status_slug = m.group(2) self._change_status(ref, status_slug, bitbucket_user) diff --git a/taiga/hooks/github/event_hooks.py b/taiga/hooks/github/event_hooks.py index e34c1a2f..3dbd0417 100644 --- a/taiga/hooks/github/event_hooks.py +++ b/taiga/hooks/github/event_hooks.py @@ -56,8 +56,7 @@ class PushEventHook(BaseEventHook): return p = re.compile("tg-(\d+) +#([-\w]+)") - m = p.search(message.lower()) - if m: + for m in p.finditer(message.lower()): ref = m.group(1) status_slug = m.group(2) self._change_status(ref, status_slug, github_user, commit) diff --git a/taiga/hooks/gitlab/event_hooks.py b/taiga/hooks/gitlab/event_hooks.py index 8776d8c7..84079121 100644 --- a/taiga/hooks/gitlab/event_hooks.py +++ b/taiga/hooks/gitlab/event_hooks.py @@ -54,8 +54,7 @@ class PushEventHook(BaseEventHook): return p = re.compile("tg-(\d+) +#([-\w]+)") - m = p.search(message.lower()) - if m: + for m in p.finditer(message.lower()): ref = m.group(1) status_slug = m.group(2) self._change_status(ref, status_slug, gitlab_user) diff --git a/tests/integration/test_hooks_github.py b/tests/integration/test_hooks_github.py index d9861f89..43b092f5 100644 --- a/tests/integration/test_hooks_github.py +++ b/tests/integration/test_hooks_github.py @@ -134,6 +134,30 @@ def test_push_event_user_story_processing(client): assert len(mail.outbox) == 1 +def test_push_event_multiple_actions(client): + creation_status = f.IssueStatusFactory() + role = f.RoleFactory(project=creation_status.project, permissions=["view_issues"]) + f.MembershipFactory(project=creation_status.project, role=role, user=creation_status.project.owner) + new_status = f.IssueStatusFactory(project=creation_status.project) + issue1 = f.IssueFactory.create(status=creation_status, project=creation_status.project, owner=creation_status.project.owner) + issue2 = f.IssueFactory.create(status=creation_status, project=creation_status.project, owner=creation_status.project.owner) + payload = {"commits": [ + {"message": """test message + test TG-%s #%s ok + test TG-%s #%s ok + bye! + """ % (issue1.ref, new_status.slug, issue2.ref, new_status.slug)}, + ]} + mail.outbox = [] + ev_hook1 = event_hooks.PushEventHook(issue1.project, payload) + ev_hook1.process_event() + issue1 = Issue.objects.get(id=issue1.id) + issue2 = Issue.objects.get(id=issue2.id) + assert issue1.status.id == new_status.id + assert issue2.status.id == new_status.id + assert len(mail.outbox) == 2 + + def test_push_event_processing_case_insensitive(client): creation_status = f.TaskStatusFactory() role = f.RoleFactory(project=creation_status.project, permissions=["view_tasks"]) diff --git a/tests/integration/test_hooks_gitlab.py b/tests/integration/test_hooks_gitlab.py index 918c6eac..6849ca49 100644 --- a/tests/integration/test_hooks_gitlab.py +++ b/tests/integration/test_hooks_gitlab.py @@ -199,6 +199,30 @@ def test_push_event_user_story_processing(client): assert len(mail.outbox) == 1 +def test_push_event_multiple_actions(client): + creation_status = f.IssueStatusFactory() + role = f.RoleFactory(project=creation_status.project, permissions=["view_issues"]) + f.MembershipFactory(project=creation_status.project, role=role, user=creation_status.project.owner) + new_status = f.IssueStatusFactory(project=creation_status.project) + issue1 = f.IssueFactory.create(status=creation_status, project=creation_status.project, owner=creation_status.project.owner) + issue2 = f.IssueFactory.create(status=creation_status, project=creation_status.project, owner=creation_status.project.owner) + payload = {"commits": [ + {"message": """test message + test TG-%s #%s ok + test TG-%s #%s ok + bye! + """ % (issue1.ref, new_status.slug, issue2.ref, new_status.slug)}, + ]} + mail.outbox = [] + ev_hook1 = event_hooks.PushEventHook(issue1.project, payload) + ev_hook1.process_event() + issue1 = Issue.objects.get(id=issue1.id) + issue2 = Issue.objects.get(id=issue2.id) + assert issue1.status.id == new_status.id + assert issue2.status.id == new_status.id + assert len(mail.outbox) == 2 + + def test_push_event_processing_case_insensitive(client): creation_status = f.TaskStatusFactory() role = f.RoleFactory(project=creation_status.project, permissions=["view_tasks"])