Skip to content

Commit

Permalink
[trigger_service] Create package instead of branching
Browse files Browse the repository at this point in the history
The noservice parameter does not have effect when branching a package.
So instead we just create a new package if it doesn't exist.
  • Loading branch information
keto committed Feb 15, 2023
1 parent acb0422 commit fe9de37
Showing 1 changed file with 25 additions and 48 deletions.
73 changes: 25 additions & 48 deletions src/participants/trigger_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@

from boss.obs import BuildServiceParticipant
from osc import core
from StringIO import StringIO
from lxml import etree
import urllib2
import re
Expand Down Expand Up @@ -169,54 +168,32 @@ def handle_wi(self, wid):
if f.dumb:
params["dumb"] = f.dumb

# the simple approach doesn't work with project links
# if self.obs.isNewPackage(project, package):
# self.obs.getCreatePackage(str(project), str(package))
# else:
# Create the package if it doesn't exist
pkg_meta_url = core.makeurl(
self.obs.apiurl,
['source', str(project), str(package), "_meta"],
query={'meta': '1'},
)
try:
pkginfo = core.show_files_meta(
self.obs.apiurl, str(project), str(package),
expand=False, meta=True)
if "<entry" not in pkginfo:
# This is a link and it needs branching from the linked project
# so grab the meta and extract the project from the link
self.log.debug("Found %s as a link in %s" % (package, project))
x = etree.fromstring(
"".join(core.show_project_meta(self.obs.apiurl, project)))
link = x.find('link')
if link is None:
raise Exception(
"Expected a <link> in project %s." % project)
self.log.debug("Got a link %s" % link)
linked_project = link.get('project')
self.log.debug("Branching %s to overwrite _service" % package)
query = {
'cmd': 'branch',
'target_project': str(project),
'noservice': '1',
}
u = core.makeurl(
self.obs.apiurl,
['source', linked_project, str(package)],
query=query
)
x = core.http_POST(u)
except Exception as exc:
self.log.warn(
"Doing a metatype pkg add because I caught %s" % exc)
self.log.warn(
"Creating package %s in project %s" % (package, project))
data = core.metatypes['pkg']['template']
data = StringIO(
data % {
"name": str(package),
"user": self.obs.getUserName()}
).readlines()
u = core.makeurl(
self.obs.apiurl,
['source', str(project), str(package), "_meta"])
x = core.http_PUT(u, data="".join(data))
self.log.debug("HTTP PUT result of pkg add : %s" % x)
x = core.http_GET(pkg_meta_url)
self.log.debug("Package exists: %s", x.fp.read())
except urllib2.HTTPError as exc:
if exc.code != 404:
raise

self.log.info(
"Creating package %s in project %s",
package, project,
)
template = core.metatypes['pkg']['template']
pkg_meta = template % {
"name": str(package),
"user": self.obs.getUserName()
}
x = core.http_PUT(pkg_meta_url, data=pkg_meta)
self.log.debug(
"Package created HTTP %s: %s", x.code, x.fp.read()
)

# Start with an empty XML doc
try: # to get any existing _service file.
Expand Down

0 comments on commit fe9de37

Please sign in to comment.