Skip to content

Commit

Permalink
Make the pagure namespace for 'flatpaks' configurable
Browse files Browse the repository at this point in the history
The previous change to look up Flatpaks under 'flatpaks/' rather than
'modules/' was backwards incompatible - to restore compatibility, make
this a new config setting: pagure_flatpak_namespace.

Signed-off-by: Owen W. Taylor <otaylor@fishsoup.net>
  • Loading branch information
owtaylor authored and bowlofeggs committed Mar 13, 2019
1 parent d08f6e0 commit c49153a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
3 changes: 3 additions & 0 deletions bodhi/server/config.py
Expand Up @@ -531,6 +531,9 @@ class BodhiConfig(dict):
'openid_template': {
'value': '{username}.id.fedoraproject.org',
'validator': str},
'pagure_flatpak_namespace': {
'value': 'modules',
'validator': str},
'pagure_url': {
'value': 'https://src.fedoraproject.org/pagure/',
'validator': _validate_tls_url},
Expand Down
5 changes: 4 additions & 1 deletion bodhi/server/models.py
Expand Up @@ -997,9 +997,12 @@ def get_pkg_committers_from_pagure(self):
"""
pagure_url = config.get('pagure_url')
# Pagure uses plural names for its namespaces such as "rpms" except for
# container. Flatpaks build directly from the 'modules' namespace
# container. Flatpaks were moved from 'modules' to 'flatpaks' - hence
# a config setting.
if self.type.name == 'container':
namespace = self.type.name
elif self.type.name == 'flatpak':
namespace = config.get('pagure_flatpak_namespace')
else:
namespace = self.type.name + 's'
package_pagure_url = '{0}/api/0/{1}/{2}?expand_group=1'.format(
Expand Down
26 changes: 22 additions & 4 deletions bodhi/tests/server/test_models.py
Expand Up @@ -1081,9 +1081,8 @@ class TestFlatpakPackage(ModelTest, unittest.TestCase):
klass = model.FlatpakPackage
attrs = dict(name=u"flatpak-runtime")

@mock.patch('bodhi.server.util.http_session')
def test_get_pkg_committers_from_pagure(self, http_session):
"""Ensure correct return value from get_pkg_committers_from_pagure()."""
def patch_http_session(http_session, namespace):
"""Patch in the correct pagure API result for the particular flatpaks namespace."""
json_output = {
"access_groups": {
"admin": [],
Expand All @@ -1102,7 +1101,7 @@ def test_get_pkg_committers_from_pagure(self, http_session):
"custom_keys": [],
"date_created": "1494947106",
"description": "Flatpak Runtime",
"fullname": "flatpaks/flatpak-runtime",
"fullname": namespace + "/flatpak-runtime",
"group_details": {},
"id": 2,
"milestones": {},
Expand All @@ -1119,6 +1118,25 @@ def test_get_pkg_committers_from_pagure(self, http_session):
http_session.get.return_value.json.return_value = json_output
http_session.get.return_value.status_code = 200

@mock.patch('bodhi.server.util.http_session')
def test_get_pkg_committers_from_pagure_modules(self, http_session):
"""Ensure correct return value from get_pkg_committers_from_pagure()."""
self.patch_http_session(http_session, namespace='modules')

rv = self.obj.get_pkg_committers_from_pagure()

self.assertEqual(rv, (['otaylor'], []))
http_session.get.assert_called_once_with(
('https://src.fedoraproject.org/pagure/api/0/modules/flatpak-runtime'
'?expand_group=1'),
timeout=60)

@mock.patch.dict('bodhi.server.config.config', {'pagure_flatpak_namespace': 'flatpaks'})
@mock.patch('bodhi.server.util.http_session')
def test_get_pkg_committers_from_pagure_flatpaks(self, http_session):
"""Check that the pagure_flatpak_namespace config key works."""
self.patch_http_session(http_session, namespace='flatpaks')

rv = self.obj.get_pkg_committers_from_pagure()

self.assertEqual(rv, (['otaylor'], []))
Expand Down
4 changes: 4 additions & 0 deletions production.ini
Expand Up @@ -367,6 +367,10 @@ use = egg:bodhi-server
##
# pagure_url = https://src.fedoraproject.org/pagure/

# This is the namespace where we expect to find the git sources for a Flatpak.
# The default - 'modules' instead of 'flatpaks' - is for backward compatibility
# pagure_flatpak_namespace = modules

##
## Product Definition Center (PDC)
##
Expand Down

0 comments on commit c49153a

Please sign in to comment.