mirror of
https://github.com/openSUSE/osc.git
synced 2025-09-06 05:08:42 +02:00
Replace hard-coded URL for devel packages mapping with a value from OBS:GitDevelProjectMap attribute
This commit is contained in:
@@ -54,6 +54,7 @@ class ForkCommand(osc.commandline.OscCommand):
|
||||
|
||||
def run(self, args):
|
||||
from osc import conf as osc_conf
|
||||
from osc import core as osc_core
|
||||
from osc import gitea_api
|
||||
from osc import obs_api
|
||||
from osc.git_scm import GitStore
|
||||
@@ -83,27 +84,11 @@ class ForkCommand(osc.commandline.OscCommand):
|
||||
pkg = obs_api.Package.from_api(args.apiurl, project, package)
|
||||
|
||||
if not args.no_devel_project:
|
||||
# devel project is not set in package meta as usual but we parse it from "OBS:RejectBranch" attribute
|
||||
try:
|
||||
attributes = obs_api.Attributes.from_api(args.apiurl, project, package, attr="OBS:RejectBranch").attribute_list
|
||||
except HTTPError as e:
|
||||
if e.code != 404:
|
||||
raise
|
||||
attributes = []
|
||||
except TypeError:
|
||||
# empty <attributes/> element, unable to instantiate Attributes model
|
||||
attributes = []
|
||||
if attributes:
|
||||
attribute = attributes[0].value
|
||||
# the pattern starts with a non-greedy match so we capture the first url
|
||||
match = re.match(r".*?(https://[^ ]+).*", attribute)
|
||||
if match:
|
||||
devel_project_url = match.group(1)
|
||||
build_project = GitStore.get_build_project(devel_project_url)
|
||||
# override the package we're cloning with the one from the devel project
|
||||
use_devel_project = True
|
||||
project = build_project
|
||||
pkg = obs_api.Package.from_api(args.apiurl, project, package)
|
||||
devel_project, devel_package = osc_core.show_devel_project(args.apiurl, project, package)
|
||||
if devel_project:
|
||||
# override the package we're cloning with the one from the devel project
|
||||
pkg = obs_api.Package.from_api(args.apiurl, devel_project, devel_package)
|
||||
use_devel_project = True
|
||||
|
||||
if not pkg.scmsync:
|
||||
print(f"{tty.colorize('ERROR', 'red,bold')}: Forking is possible only with packages managed in Git (the <scmsync> element must be set in the package meta)")
|
||||
|
18
osc/core.py
18
osc/core.py
@@ -100,7 +100,6 @@ DISTURL_RE = re.compile(r"^(?P<bs>.*)://(?P<apiurl>.*?)/(?P<project>.*?)/(?P<rep
|
||||
BUILDLOGURL_RE = re.compile(r"^(?P<apiurl>https?://.*?)/build/(?P<project>.*?)/(?P<repository>.*?)/(?P<arch>.*?)/(?P<package>.*?)/_log$")
|
||||
BUFSIZE = 1024 * 1024
|
||||
|
||||
DEVEL_PACKAGES_URL = "https://src.opensuse.org/openSUSE/Factory/raw/branch/main/pkgs/_meta/devel_packages"
|
||||
|
||||
new_project_templ = """\
|
||||
<project name="%(name)s">
|
||||
@@ -1399,10 +1398,23 @@ def show_devel_project(apiurl, prj, pac):
|
||||
|
||||
package_obj = obs_api.Package.from_api(apiurl, prj, pac)
|
||||
if package_obj.devel is None:
|
||||
if prj == "openSUSE:Factory" or prj == "openSUSE.org:openSUSE:Factory":
|
||||
# devel project is not set in package meta as usual
|
||||
# let's check if OBS:GitDevelProjectMap project attribute exists and points to an URL with the devel project mapping
|
||||
try:
|
||||
attributes = obs_api.Attributes.from_api(apiurl, prj, package=None, attr="OBS:GitDevelProjectMap").attribute_list
|
||||
except HTTPError as e:
|
||||
if e.code != 404:
|
||||
raise
|
||||
attributes = []
|
||||
except TypeError:
|
||||
# empty <attributes/> element, unable to instantiate Attributes model
|
||||
attributes = []
|
||||
devel_packages_url = attributes[0].value if attributes else None
|
||||
|
||||
if devel_packages_url:
|
||||
# If OBS api doesn't return a devel project, query the gitea devel_packages file
|
||||
try:
|
||||
response = http_request("GET", DEVEL_PACKAGES_URL)
|
||||
response = http_request("GET", devel_packages_url)
|
||||
response.auto_close = False
|
||||
except:
|
||||
return None, None
|
||||
|
Reference in New Issue
Block a user