Commit f9bf13f5 authored by Vamshi Krishna's avatar Vamshi Krishna

Fix working of synchronize labels from issues

When changing the referenced issue, remove the labels
of that issue and keep only labels of referenced issue.

Closes #306
parent 83771ce6
Pipeline #21136166 passed with stages
in 7 minutes and 10 seconds
from collections import defaultdict
from django.apps import apps
from IGitt.Interfaces.Actions import IssueActions
from IGitt.Interfaces.Actions import MergeRequestActions
......@@ -26,9 +27,22 @@ def sync_updated_pr_with_issue(pr: MergeRequest,
data = defaultdict(dict)
with lock_igitt_object('label mr', pr):
labels = pr.labels
temp_labels = pr.labels
config = apps.get_app_config('gitmate_pr_size_labeller')
settings = config.get_settings(repo)
size_scheme = settings['size_scheme']
ignore = {size_scheme.format(size=letter)
for letter in ['S', 'XS', 'M', 'L', 'XL', 'XXL']}
config = apps.get_app_config('gitmate_auto_label_pending_or_wip')
settings = config.get_settings(repo)
ignore.add(settings['wip_label'])
ignore.add(settings['pending_review_label'])
config = apps.get_app_config('gitmate_approver')
settings = config.get_settings(repo)
ignore.add(settings['approved_label'])
labels = ignore & temp_labels
for issue in issues:
labels = issue.labels | labels
labels |= issue.labels
pr.labels = labels
if sync_assignees:
......
......@@ -37,7 +37,7 @@ class TestIssuePRSync(GitmateTestCase):
m_cl_iss.return_value = {
GitHubIssue(self.repo.token, self.repo.full_name, 0)}
m_iss_labels.return_value = {'a', 'b'}
m_labels.return_value = set()
m_labels.return_value = {'size/S', 'process/WIP'}
m_iss_assignees.return_value = {self.gh_user}
m_assignees.return_value = set()
......@@ -51,7 +51,7 @@ class TestIssuePRSync(GitmateTestCase):
response = self.simulate_github_webhook_call('pull_request', data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
m_labels.assert_called_with({'a', 'b'})
m_labels.assert_called_with({'a', 'b', 'size/S', 'process/WIP'})
m_assignees.assert_called_with({self.gh_user})
# testing updated issue assignees
......@@ -138,7 +138,7 @@ class TestIssuePRSync(GitmateTestCase):
m_cl_iss.return_value = {
GitLabIssue(self.gl_repo.token, self.gl_repo.full_name, 0)}
m_iss_labels.return_value = {'a', 'b'}
m_labels.return_value = set()
m_labels.return_value = {'size/S', 'process/WIP'}
m_iss_assignees.return_value = {self.gl_user}
m_assignees.return_value = set()
......@@ -154,7 +154,7 @@ class TestIssuePRSync(GitmateTestCase):
'Merge Request Hook', data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
m_labels.assert_called_with({'a', 'b'})
m_labels.assert_called_with({'a', 'b', 'size/S', 'process/WIP'})
m_assignees.assert_called_with({self.gl_user})
# testing updated issue assignees
......
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