Skip to content

Commit

Permalink
hub: add shortcut to parse dist git url
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyw committed Jun 18, 2024
1 parent 3ccd97d commit ae3c67a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions osh/hub/scan/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
ClientAnalyzer, ETMapping, MockConfig,
Package, Profile, Scan, ScanBinding, Tag)
from osh.hub.scan.service import get_latest_binding
from osh.hub.scan.utils import get_or_fail, is_rebase
from osh.hub.scan.utils import get_or_fail, is_rebase, parse_git_url
from osh.hub.service.processing import task_has_results

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -421,9 +421,10 @@ def determine_result_filename(self, nvr, filename, is_tarball, git_url=None):
if is_tarball:
f = os.path.basename(filename)
return f.rsplit(".", 2 if ".tar." in f else 1)[0]
# FIXME: resolve result_filename later

if git_url is not None:
return None
_, repo_name, commit_hash = parse_git_url(git_url)
return f"{repo_name}-{commit_hash}"

raise RuntimeError("unknown input format of sources")

Expand Down
13 changes: 13 additions & 0 deletions osh/hub/scan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-FileCopyrightText: Copyright contributors to the OpenScanHub project.

import logging
import re

from kobo.rpmlib import parse_nvr

Expand All @@ -22,3 +23,15 @@ def is_rebase(base, target):
base_d = parse_nvr(base)
target_d = parse_nvr(target)
return target_d['version'] != base_d['version']


def parse_git_url(git_url):
match = re.match('^([^:]+://.+/)([^#]+)#(.+)$', git_url)
if not match:
raise ValueError(f"Invalid dist git URL specified: {git_url}")

base_url = match.group(1)
repo_name = match.group(2)
hash = match.group(3)

return (base_url, repo_name, hash)

0 comments on commit ae3c67a

Please sign in to comment.