1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-08-11 17:54:06 +02:00

Merge pull request #1206 from dmach/set-link-revision-message

setlinkrev: Write a log message on setting a revision
This commit is contained in:
2022-12-19 15:11:33 +01:00
committed by GitHub
2 changed files with 17 additions and 10 deletions

View File

@@ -7383,7 +7383,7 @@ def owner(
return res return res
def set_link_rev(apiurl: str, project: str, package: str, revision="", expand=False): def set_link_rev(apiurl: str, project: str, package: str, revision="", expand=False, msg: str=None):
url = makeurl(apiurl, ["source", project, package, "_link"]) url = makeurl(apiurl, ["source", project, package, "_link"])
try: try:
f = http_GET(url) f = http_GET(url)
@@ -7393,6 +7393,13 @@ def set_link_rev(apiurl: str, project: str, package: str, revision="", expand=Fa
raise raise
revision = _set_link_rev(apiurl, project, package, root, revision, expand=expand) revision = _set_link_rev(apiurl, project, package, root, revision, expand=expand)
l = ET.tostring(root, encoding=ET_ENCODING) l = ET.tostring(root, encoding=ET_ENCODING)
if not msg:
if revision:
msg = f"Set link revision to {revision}"
else:
msg = "Unset link revision"
url = makeurl(apiurl, ["source", project, package, "_link"], {"comment": msg})
http_PUT(url, data=l) http_PUT(url, data=l)
return revision return revision

View File

@@ -23,14 +23,14 @@ class TestSetLinkRev(OscTestCase):
@GET('http://localhost/source/osctest/simple/_link', file='simple_link') @GET('http://localhost/source/osctest/simple/_link', file='simple_link')
@GET('http://localhost/source/srcprj/srcpkg?rev=latest', file='simple_filesremote') @GET('http://localhost/source/srcprj/srcpkg?rev=latest', file='simple_filesremote')
@PUT('http://localhost/source/osctest/simple/_link', @PUT('http://localhost/source/osctest/simple/_link?comment=Set+link+revision+to+42',
exp='<link package="srcpkg" project="srcprj" rev="42" />', text='dummytext') exp='<link package="srcpkg" project="srcprj" rev="42" />', text='dummytext')
def test_simple1(self): def test_simple1(self):
"""a simple set_link_rev call without revision""" """a simple set_link_rev call without revision"""
osc.core.set_link_rev('http://localhost', 'osctest', 'simple') osc.core.set_link_rev('http://localhost', 'osctest', 'simple')
@GET('http://localhost/source/osctest/simple/_link', file='simple_link') @GET('http://localhost/source/osctest/simple/_link', file='simple_link')
@PUT('http://localhost/source/osctest/simple/_link', @PUT('http://localhost/source/osctest/simple/_link?comment=Set+link+revision+to+42',
exp='<link package="srcpkg" project="srcprj" rev="42" />', text='dummytext') exp='<link package="srcpkg" project="srcprj" rev="42" />', text='dummytext')
def test_simple2(self): def test_simple2(self):
"""a simple set_link_rev call with revision""" """a simple set_link_rev call with revision"""
@@ -38,7 +38,7 @@ class TestSetLinkRev(OscTestCase):
@GET('http://localhost/source/osctest/simple/_link', file='noproject_link') @GET('http://localhost/source/osctest/simple/_link', file='noproject_link')
@GET('http://localhost/source/osctest/srcpkg?rev=latest&expand=1', file='expandedsrc_filesremote') @GET('http://localhost/source/osctest/srcpkg?rev=latest&expand=1', file='expandedsrc_filesremote')
@PUT('http://localhost/source/osctest/simple/_link', @PUT('http://localhost/source/osctest/simple/_link?comment=Set+link+revision+to+eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
exp='<link package="srcpkg" rev="eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" vrev="1" />', text='dummytext') exp='<link package="srcpkg" rev="eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" vrev="1" />', text='dummytext')
def test_expandedsrc(self): def test_expandedsrc(self):
"""expand src package""" """expand src package"""
@@ -46,7 +46,7 @@ class TestSetLinkRev(OscTestCase):
@GET('http://localhost/source/osctest/simple/_link', file='link_with_rev') @GET('http://localhost/source/osctest/simple/_link', file='link_with_rev')
@GET('http://localhost/source/srcprj/srcpkg?rev=latest', file='simple_filesremote') @GET('http://localhost/source/srcprj/srcpkg?rev=latest', file='simple_filesremote')
@PUT('http://localhost/source/osctest/simple/_link', @PUT('http://localhost/source/osctest/simple/_link?comment=Set+link+revision+to+42',
exp='<link package="srcpkg" project="srcprj" rev="42" />', text='dummytext') exp='<link package="srcpkg" project="srcprj" rev="42" />', text='dummytext')
def test_existingrev(self): def test_existingrev(self):
"""link already has a rev attribute, update it to current version""" """link already has a rev attribute, update it to current version"""
@@ -55,7 +55,7 @@ class TestSetLinkRev(OscTestCase):
@GET('http://localhost/source/osctest/simple/_link', file='link_with_rev') @GET('http://localhost/source/osctest/simple/_link', file='link_with_rev')
@GET('http://localhost/source/srcprj/srcpkg?rev=latest&expand=1', file='expandedsrc_filesremote') @GET('http://localhost/source/srcprj/srcpkg?rev=latest&expand=1', file='expandedsrc_filesremote')
@PUT('http://localhost/source/osctest/simple/_link', @PUT('http://localhost/source/osctest/simple/_link?comment=Set+link+revision+to+eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
exp='<link package="srcpkg" project="srcprj" rev="eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" vrev="1" />', exp='<link package="srcpkg" project="srcprj" rev="eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" vrev="1" />',
text='dummytext') text='dummytext')
def test_expandexistingrev(self): def test_expandexistingrev(self):
@@ -71,21 +71,21 @@ class TestSetLinkRev(OscTestCase):
self.assertRaises(HTTPError, osc.core.set_link_rev, 'http://localhost', 'osctest', 'simple', expand=True) self.assertRaises(HTTPError, osc.core.set_link_rev, 'http://localhost', 'osctest', 'simple', expand=True)
@GET('http://localhost/source/osctest/simple/_link', file='rev_link') @GET('http://localhost/source/osctest/simple/_link', file='rev_link')
@PUT('http://localhost/source/osctest/simple/_link', @PUT('http://localhost/source/osctest/simple/_link?comment=Unset+link+revision',
exp='<link package="srcpkg" project="srcprj" />', text='dummytext') exp='<link package="srcpkg" project="srcprj" />', text='dummytext')
def test_deleterev(self): def test_deleterev(self):
"""delete rev attribute from link xml""" """delete rev attribute from link xml"""
osc.core.set_link_rev('http://localhost', 'osctest', 'simple', revision=None) osc.core.set_link_rev('http://localhost', 'osctest', 'simple', revision=None)
@GET('http://localhost/source/osctest/simple/_link', file='md5_rev_link') @GET('http://localhost/source/osctest/simple/_link', file='md5_rev_link')
@PUT('http://localhost/source/osctest/simple/_link', @PUT('http://localhost/source/osctest/simple/_link?comment=Unset+link+revision',
exp='<link package="srcpkg" project="srcprj" />', text='dummytext') exp='<link package="srcpkg" project="srcprj" />', text='dummytext')
def test_deleterev(self): def test_deleterev_md5(self):
"""delete rev and vrev attribute from link xml""" """delete rev and vrev attribute from link xml"""
osc.core.set_link_rev('http://localhost', 'osctest', 'simple', revision=None) osc.core.set_link_rev('http://localhost', 'osctest', 'simple', revision=None)
@GET('http://localhost/source/osctest/simple/_link', file='simple_link') @GET('http://localhost/source/osctest/simple/_link', file='simple_link')
@PUT('http://localhost/source/osctest/simple/_link', @PUT('http://localhost/source/osctest/simple/_link?comment=Unset+link+revision',
exp='<link package="srcpkg" project="srcprj" />', text='dummytext') exp='<link package="srcpkg" project="srcprj" />', text='dummytext')
def test_deleterevnonexistent(self): def test_deleterevnonexistent(self):
"""delete non existent rev attribute from link xml""" """delete non existent rev attribute from link xml"""