Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_packages by osp-project to cover non-url strings #172

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion znoyder/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# under the License.
#

import re

from pprint import PrettyPrinter
from urllib.parse import urlparse

Expand Down Expand Up @@ -72,7 +74,11 @@ def get_packages(**kwargs):
if kwargs.get('upstream') in str(package.get('upstream'))]

for package in packages:
package['osp-project'] = urlparse(package['osp-patches']).path[1:]
repo_name = re.search(r'^(.*)\/(.*)$', package['osp-patches']).group(2)
if repo_name.endswith('.git'):
repo_name = repo_name[:-4] # drop the suffix
package['osp-project'] = repo_name

if kwargs.get('osp_project'):
packages = [package for package in packages
if kwargs.get('osp_project') == package.get('osp-project')]
Expand Down
18 changes: 15 additions & 3 deletions znoyder/tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ def test_search_by_name(self):

class TestGetPackages(TestCase):
def test_no_args(self):
project = 'some/project'
project = 'project'

packages = [
{
'osp-name': 'pack_1',
'osp-project': '',
'osp-patches': 'http://localhost:8080/%s' % project
'osp-patches': 'http://localhost:8080/some/%s' % project
}
]

Expand Down Expand Up @@ -222,7 +222,14 @@ def test_search_by_osp_project(self):
'project': 'project_2',
}

packages = [package1, package2]
package3 = {
'name': 'name_3',
'osp-name': 'pack_3',
'osp-patches': 'git@gitlab.com:eng/test/repo_name_3.git',
'project': 'project_3',
}

packages = [package1, package2, package3]

info_call = znoyder.browser.get_distroinfo = Mock()

Expand All @@ -235,6 +242,11 @@ def test_search_by_osp_project(self):
get_packages(osp_project=package1['osp-project'])
)

self.assertEqual(
[package3],
get_packages(osp_project='repo_name_3')
)

def test_search_by_project(self):
package1 = {
'name': 'name_1',
Expand Down