diff --git a/check_source.py b/check_source.py index 605173b4..157a0bcc 100755 --- a/check_source.py +++ b/check_source.py @@ -11,6 +11,8 @@ try: except ImportError: import cElementTree as ET +from lxml import etree as ETL + import osc.conf import osc.core from osc.util.helper import decode_list @@ -22,7 +24,7 @@ from osclib.core import package_kind from osclib.core import source_file_load from osclib.core import target_archs from osclib.core import create_add_role_request -from osclib.core import maintainers_get +from osc.core import show_project_meta from urllib.error import HTTPError import ReviewBot @@ -348,7 +350,10 @@ class CheckSource(ReviewBot.ReviewBot): ) if not self.required_maintainer: return True - maintainers = maintainers_get(self.apiurl, source_project) + meta = ETL.fromstringlist(show_project_meta(self.apiurl, source_project)) + maintainers = meta.xpath('//person[@role="maintainer"]/@userid') + maintainers += ['group:' + g for g in meta.xpath('//group[@role="maintainer"]/@groupid')] + return self.required_maintainer in maintainers @staticmethod diff --git a/tests/check_source_tests.py b/tests/check_source_tests.py index 853edf15..bd4919c4 100644 --- a/tests/check_source_tests.py +++ b/tests/check_source_tests.py @@ -79,7 +79,7 @@ class TestCheckSource(OBSLocal.TestCase): self.assertReview(req_id, by_user=(self.bot_user, 'accepted')) self.assertReview(req_id, by_group=(REVIEW_TEAM, 'new')) - def test_source_maintainer(self): + def test_no_source_maintainer(self): """Declines the request when the 'required_maintainer' is not maintainer of the source project""" self._setup_devel_project() @@ -103,8 +103,26 @@ class TestCheckSource(OBSLocal.TestCase): self.assertEqual(add_role_req.actions[0].tgt_project, SRC_PROJECT) self.assertEqual('Created automatically from request %s' % req_id, add_role_req.description) - def _setup_devel_project(self): - devel_project = self.wf.create_project(SRC_PROJECT) + def test_source_maintainer(self): + """Accepts the request when the 'required_maintainer' is a group and is a maintainer for the project""" + group_name = FACTORY_MAINTAINERS.replace('group:', '') + self.wf.create_group(group_name) + self.wf.remote_config_set({ 'required-source-maintainer': FACTORY_MAINTAINERS }) + + self._setup_devel_project(maintainer={'groups': [group_name]}) + + req_id = self.wf.create_submit_request(SRC_PROJECT, 'blowfish').reqid + + self.assertReview(req_id, by_user=(self.bot_user, 'new')) + + self.review_bot.set_request_ids([req_id]) + self.review_bot.check_requests() + + self.assertReview(req_id, by_user=(self.bot_user, 'accepted')) + self.assertReview(req_id, by_group=(REVIEW_TEAM, 'new')) + + def _setup_devel_project(self, maintainer={}): + devel_project = self.wf.create_project(SRC_PROJECT, maintainer=maintainer) devel_package = OBSLocal.Package('blowfish', project=devel_project) blowfish_spec = os.path.join(FIXTURES, 'packages', 'blowfish', 'blowfish.spec')