From 25f8fb1cd7ddf8179573fdbead19944a92f9369a Mon Sep 17 00:00:00 2001 From: Yonghee Han Date: Tue, 13 Dec 2016 17:59:46 -0800 Subject: [PATCH] Revert "Verify that the SR was created on the correct branch" This reverts commit 13fe3c9941a07d74ed6980e055950f45e879107f. Change-Id: Ia816a153b1b9d4a537992dec6aade65e5ae5e674 --- common/mapping.py | 101 ------------------------------------------------------ job_submit.py | 31 ++++------------- 2 files changed, 6 insertions(+), 126 deletions(-) mode change 100755 => 100644 common/mapping.py diff --git a/common/mapping.py b/common/mapping.py old mode 100755 new mode 100644 index 9687255..e6343e2 --- a/common/mapping.py +++ b/common/mapping.py @@ -117,38 +117,6 @@ class Mapping(object): return self.__get_mapping(path, branch) or [] return [] - def get_contains_branch_mapping(self, project, branch=None): - """ Get contains branch mapping """ - branchs = [] - - if self.mapping_obj.project: - for prj in self.mapping_obj.project: - if prj.name == project or prj.name == '/' + project: - branchs.append(prj.branch) - - if self.mapping_obj.default: - # Search in path list - prj_path = project - while True: - # parent directory of project/directory - prj_path = os.path.dirname(os.path.join('/', prj_path)) - - if prj_path == '/': - for path in self.mapping_obj.default.path: - if path.name == '/': - if branch == path.branch: - return branchs.append(path.branch) or [] - return [] - - # Search path - for path in self.mapping_obj.default.path: - # path match - if os.path.dirname(os.path.join('/', path.name) + - '/') == prj_path: - if branch == path.branch: - return branchs.append(path.branch) or [] - return [] - return [] class MappingV2(object): """A class to handle mapping xml file """ @@ -194,23 +162,6 @@ class MappingV2(object): return mapping - def get_contains_branch_mapping(self, project, branch=None): - """ Get contains branch mapping """ - branchs = [] - if self.mapping_obj.configure: - # if configure.enable is false then return [] - if self.mapping_obj.configure.enable == 'false': - return branchs - - if self.mapping_obj.branch: - for brch in self.mapping_obj.branch: - for prj in brch.project: - if (prj.name == project or prj.name == '/' + project) and (branch in brch.name.split(",") ): - for b in brch.name.split(","): - branchs.append(b) - - return branchs - def git_obs_map(gerrit_prj, gerrit_branch=None, gitcache=None): """ Find an OBS project[s correspondent to Gerrit project and branch @@ -290,55 +241,3 @@ def git_ref_map(prjdir=None, mapping_file=None, base_project=None): found.append([item.name, item.OBS_project, item.OBS_staging_project]) return found -def git_contains_branch_map(gerrit_prj, gerrit_branch=None, gitcache=None, \ - gerrit_hostname=None, gerrit_username=None, gerrit_sshport=None): - """ - Find an branch by parsing git-obs-mapping.xml. - """ - def remove_overlaps(orig_list): - """docstring for make_unique""" - result = [] - [result.append(obj) for obj in orig_list if obj not in result] - return result - - def get_xml_file_list(path): - file_list = [] - for root, dirs, files in os.walk(path): - for file in files: - if file.endswith('.xml'): - file_list.append(os.path.join(path, file)) - return file_list - - if gitcache: - git_cache = gitcache - else: - git_cache = os.getenv("GIT_CACHE_DIR") - - mapping_prj = os.getenv("MAPPING_PRJ") - - git_obs_mapping_path = os.path.join(git_cache, mapping_prj) - mapping_path_v1 = '{0}/git-obs-mapping.xml'.format(git_obs_mapping_path) - - if not os.path.isfile(mapping_path_v1): - print 'Cloning %s' % mapping_prj - if not clone_gitproject(mapping_prj, \ - os.path.join(git_cache, mapping_prj), \ - gerrit_hostname=gerrit_hostname, gerrit_username=gerrit_username, gerrit_sshport=gerrit_sshport): - raise MappingError('Error cloning %s' % mapping_prj) - - # get mappings v1 - mymapping = Mapping(mapping_path_v1) - branchs = mymapping.get_contains_branch_mapping(gerrit_prj, gerrit_branch) - - # get v2 mapping files list - mapping_path_v2 = '{0}/profiles/'.format(git_obs_mapping_path) - mapping_v2_file_lists = get_xml_file_list(mapping_path_v2) - - # get mappings v2 - for file in mapping_v2_file_lists: - mymapping_v2 = MappingV2(file) - branchs.extend(mymapping_v2.get_contains_branch_mapping(gerrit_prj, - gerrit_branch)) - branchs = remove_overlaps(branchs) - return branchs - diff --git a/job_submit.py b/job_submit.py index fdaf492..ba3155a 100755 --- a/job_submit.py +++ b/job_submit.py @@ -36,7 +36,7 @@ from osc import core from gitbuildsys.errors import ObsError from common import utils -from common.mapping import git_obs_map, git_contains_branch_map +from common.mapping import git_obs_map from common.git import Git, clone_gitproject from common.upload_service import upload_obs_service, UploadError from common.gerrit import is_ref_deleted @@ -65,11 +65,7 @@ WRONG_COMMIT_MSG = '- The commit %s tag attached does NOT exist in git tree or'\ 'then re-submit tag.' UNKNOWN_FORMAT_MSG = '- Unknown tag format,\n please follow the format '\ - 'submit/{branch}/{date.time}.' - -WRONG_FORMAT_MSG = '- Wrong tag format,\n please follow the format '\ - 'submit/{branch}/{date.time}. \n'\ - 'Your branch : %s. Git-obs-mapping branch: %s' + 'submit/{version}/{date.time}.' NOT_ANNOTATED_MSG = '- Tag should be annotated tag.' @@ -144,7 +140,7 @@ def find_submit_tag(event, mygit): return tag -def check_tag_format(git, mygerrit, event, tag, mappingbranchs): +def check_tag_format(git, mygerrit, event, tag): """check whether tag follow proper format""" branch, date = parse_submit_tag(tag) @@ -171,15 +167,6 @@ def check_tag_format(git, mygerrit, event, tag, mappingbranchs): else: # cannot find tagged commit in git tree or gerrit open change message.append(WRONG_COMMIT_MSG % psr) - - contain = False - containsbranch = git.branch_contains(tag) - for b in containsbranch: - if b in mappingbranchs: - contain = True - if not contain: - # wrong tag format - message.append(WRONG_FORMAT_MSG % (containsbranch,mappingbranchs)) else: # wrong tag format message.append(UNKNOWN_FORMAT_MSG) @@ -191,6 +178,8 @@ def check_tag_format(git, mygerrit, event, tag, mappingbranchs): # post comment to gerrit and send email if check failed if message: + print message + msg = 'The tag %s was pushed, but it was not completed because of '\ 'the following reason(s):\n\n' % tag + '\n'.join(message) @@ -562,16 +551,8 @@ def main(build_type): if gerrit_account_email: submitter += ' <%s>' % gerrit_account_email - mappingbranchs = git_contains_branch_map(os.getenv("GERRIT_PROJECT"), git_branch, \ - gitcache=gerrit_env.gitcache, \ - gerrit_hostname=gerrit_env.hostname, \ - gerrit_username=gerrit_env.username, \ - gerrit_sshport=gerrit_env.sshport - ) - print 'mapping branch = %s ' %(mappingbranchs) - # check whether tag meet format - if not check_tag_format(mygit, mygerrit, event, tag, mappingbranchs): + if not check_tag_format(mygit, mygerrit, event, tag): print 'The check for the tag format is error, exit now\n' return 0 -- 2.7.4