From: hyokeun Date: Tue, 11 Jul 2017 01:06:53 +0000 (+0900) Subject: Remove _link if _service file exists when accepting SR. X-Git-Tag: submit/trunk/20190927.012743~383 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9cf9b7db0acc91888b14185b5b004a2388effa4c;p=services%2Fjenkins-scripts.git Remove _link if _service file exists when accepting SR. Problem: When accepting packages to multiple-linked project, it branches rather than creating it. This will create _link package which references the original project's. Workaround: Remove _link if exists and set associated comments for history. Change-Id: Ibcddef330ad666405d29bc58812ff7afc723a973 --- diff --git a/common/buildservice.py b/common/buildservice.py index d204f12..8436edd 100755 --- a/common/buildservice.py +++ b/common/buildservice.py @@ -552,6 +552,54 @@ class BuildService(OSC): core.checkout_package(self.apiurl, prj, pkg, rev, prj_dir=prj, \ expand_link=True) + def get_comments(self, project, package=None): + """ + Get comments of the package + """ + + if package is not None: + url = core.makeurl(self.apiurl, ['comments', 'package', project, package]) + else: + url = core.makeurl(self.apiurl, ['comments', 'project', project]) + cmtroot = ElementTree.parse(core.http_GET(url)).getroot() + tag_ids = {} + for headTag in cmtroot.getchildren(): + tag_ids[headTag.attrib['id']] = headTag.text + return tag_ids + + def set_comments(self, project, package=None, comment=''): + """ + Get comments of the package + """ + + if package is not None: + url = core.makeurl(self.apiurl, ['comments', 'package', project, package]) + else: + url = core.makeurl(self.apiurl, ['comments', 'project', project]) + self.core_http(core.http_POST, url, data='%s' % comment) + + def purge_comments(self, project, package=None): + """ + Delete the specific file from package in project + """ + + for t in self.get_comments(project, package): + url = core.makeurl(self.apiurl, ['comment', t]) + self.core_http(core.http_DELETE, url) + + def delete_file(self, project, package, files=[], comment=None, purge_comments=False): + """ + Delete the specific file from package in project + """ + + core.delete_files(self.apiurl, project, package, files) + + if purge_comments == True: + self.purge_comments(project, package) + + if comment is not None: + self.set_comments(project, package, comment) + @staticmethod def find_pac(work_dir='.'): """Get the single Package object for specified dir @@ -1290,7 +1338,7 @@ class BuildService(OSC): print 'get_pkgrev_from_snapshot http_GET(%s) error' % u return None - def get_source_viewinfo(self, prj, parse=0, nofilename=1): + def get_source_viewinfo(self, prj, pkg=None, parse=0, nofilename=1): """ Get source viewinfo of the project """ @@ -1299,7 +1347,10 @@ class BuildService(OSC): query['parse'] = parse query['nofilename'] = nofilename - u = core.makeurl(self.apiurl, ['source', prj], query) + if pkg is not None: + u = core.makeurl(self.apiurl, ['source', prj, pkg], query) + else: + u = core.makeurl(self.apiurl, ['source', prj], query) try: return core.http_GET(u) except (urllib2.URLError, urllib2.HTTPError), e: diff --git a/job_request.py b/job_request.py index e663051..83acd4b 100755 --- a/job_request.py +++ b/job_request.py @@ -37,6 +37,7 @@ import datetime import base64 from time import sleep from xml.sax.saxutils import unescape +import xml.etree.cElementTree as ElementTree # set default char-set endcoding to utf-8 reload(sys) @@ -168,7 +169,7 @@ def obs_git_data(event_fields): print ppt.pprint(ret_data) return ret_data, projects_list -def delete_from_obs(prj, pkg): +def delete_from_obs(prj, pkg, target_project=None, comments=None): """ Delete package from OBS. Delete project if it's prerelease project @@ -178,6 +179,23 @@ def delete_from_obs(prj, pkg): os.getenv('OBS_API_USERNAME'), os.getenv('OBS_API_PASSWD')) + # If selected package have both _link and _service file, delete _link. + if target_project is not None: + try: + viewinfo = _bs.get_source_viewinfo(target_project, pkg, parse=0, nofilename=0) + viewroot = ElementTree.parse(viewinfo).getroot() + if viewroot.find('filename').text.startswith('_service:'): + if viewroot.find('linked') is not None: + print 'Found conflicting LINK %s/%s' % (viewroot.find('linked').get('project'), \ + viewroot.find('linked').get('package')) + _comments = 'revision %d is the same as revision %d w/o link.
\n%s' % \ + (int(viewroot.get('rev')) + 1, int(viewroot.get('rev')), \ + comments.replace('<','<').replace('>','>').replace('\n','
\n')) + _bs.delete_file(target_project, viewroot.get('package'), ['_link'], \ + _comments, purge_comments=True) + except Exception as err: + print repr(err) + try: if 'home:prerelease:' in prj: print 'Removing %s' % prj @@ -262,7 +280,11 @@ def request_accepted(data, gerrit, gitprj): print gre return 1 - delete_from_obs(data['OBS_REQ_PRJ_SRC'], data['OBS_REQ_PKG_SRC']) + additional_comment = 'accepted request %s (%s/request/show/%s)\n\n%s' \ + % (data['OBS_REQ_ID'], os.getenv('OBS_URL'), data['OBS_REQ_ID'], \ + data['OBS_REQ_DESP']) + delete_from_obs(data['OBS_REQ_PRJ_SRC'], data['OBS_REQ_PKG_SRC'], \ + target_project=data['OBS_REQ_PRJ'], comments=additional_comment) # Disable triggerring make_dep_graph. # Code remained to enable it in the future