From: ZhuoX Li Date: Fri, 11 Jul 2014 01:58:47 +0000 (+0800) Subject: Modify the data structure for new description info. X-Git-Tag: 1.0~102 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7af95bdc41d16e291da70007128bcbd313c9f057;p=services%2Fjenkins-scripts.git Modify the data structure for new description info. When accept group submission, repa will only list the first one on project name list in the previous. So jenkins can't get complete project name list to update accepted branch on them. Now the latest released repa will list the all projects name. To be compatible the old and the new, so should modify it. As below, the old formate and the new: {"description": "project: platform/upstream/e2fsprogs"} --> {"description": "project: [platform/upstream/e2fsprogs, profile/ivi/meta-ivi]"} Fixes: #2025 Change-Id: I9392d485484383233d43c78faf278c126f26de0f --- diff --git a/job_request.py b/job_request.py index a54676b..a0aaa31 100755 --- a/job_request.py +++ b/job_request.py @@ -75,7 +75,7 @@ def obs_git_data(event_fields): mapping = {"Submitter" : 'GIT_AUTHOR_EMAIL', "Comments" : "GIT_COMMENTS", "Tag" : "GIT_TAG", - "Git project" : "GIT_PROJECT", + "Git project" : "GIT_PROJECTS", "Commit" : "GIT_COMMIT_SUBJ" } @@ -84,37 +84,46 @@ def obs_git_data(event_fields): for key in obs_fields_mapping.keys(): ret_data[obs_fields_mapping[key]] = event_fields.get(key) - desp_list = [] + projects_list = [] description = event_fields['description'] if description: - for section in description.split('\n\n'): - entry = {} - for line in section.split('\n'): - try: - key, value = line.split(':', 1) - mkey = mapping.get(key.strip()) - if not mkey: - continue - if key.strip() in ['Submitter']: - entry[mkey] = unescape(value.strip()) - else: - entry[mkey] = value.strip() - except (AttributeError, ValueError): - print '-------------------------------------' - print 'key:value %s' % line - # FIXME: here is just a temp solution - print 'FATAL: no tag in submit description' - if 'GIT_PROJECT' in entry.keys() and 'GIT_TAG' in entry.keys(): - tag = tag_info(entry['GIT_PROJECT'], entry['GIT_TAG']) - entry.update(tag) - else: - print '-------------------------------------' - print "FATAL ERROR: Invalid rquest info: the request might be"\ - " created by manual" + entry = {} + for line in description.split('\n'): + try: + key, value = line.split(':', 1) + mkey = mapping.get(key.strip()) + if not mkey: + continue + if key.strip() in ['Submitter']: + entry[mkey] = unescape(value.strip()) + else: + entry[mkey] = value.strip() + except (AttributeError, ValueError): print '-------------------------------------' - exit(0) - desp_list.append(entry) + print 'key:value %s' % line + # FIXME: here is just a temp solution + print 'FATAL: no tag in submit description' + if 'GIT_PROJECTS' in entry.keys() and 'GIT_TAG' in entry.keys(): + projects = [] + # To be compatible the one or more + # when entry['GIT_PROJECTS'] is '[***]' executes if, + # when entry['GIT_PROJECTS'] is '***' executes else. + if entry['GIT_PROJECTS'].startswith('[') and \ + entry['GIT_PROJECTS'].endswith(']'): + projects = entry['GIT_PROJECTS'][1:-1].split(',') + else: + projects.append(entry['GIT_PROJECTS']) + for project in projects: + tag = tag_info(project, entry['GIT_TAG']) + tag.update({'GIT_PROJECT': project}) + projects_list.append(tag) + else: + print '-------------------------------------' + print "FATAL ERROR: Invalid rquest info: the request might be"\ + " created by manual" + print '-------------------------------------' + exit(0) else: print '--------------------------------------------------' print 'FATAL: package submited has no description, exit...' @@ -122,23 +131,15 @@ def obs_git_data(event_fields): exit(0) # move the tag info to data, keep the superseded SR in list - new_desp = desp_list.pop(0) - - ret_data['descriptions'] = desp_list - ret_data.update(new_desp) - # Try to set GIT_AUTHOR_EMAIL if it's not set yet - # (No 'Submitter' in description) - if 'GIT_AUTHOR_EMAIL' not in ret_data: - ret_data['GIT_AUTHOR_EMAIL'] = '%s <%s>' % (ret_data['author'], - ret_data['email']) + ret_data.update(entry) # Database records print '########################################' import pprint ppt = pprint.PrettyPrinter(indent=4) print ppt.pprint(ret_data) - return ret_data + return ret_data, projects_list def delete_from_obs(prj, pkg): """ @@ -326,7 +327,7 @@ def main(): return -1 try: - data = obs_git_data(event_fields) + data, projects_data = obs_git_data(event_fields) except GitError, err: print >> sys.stderr, err return -1 @@ -342,38 +343,45 @@ def main(): print 'Skipping processing of REQUEST_CREATE for prerelease project' return 0 - if not (event_type == 'OBS_SRCSRV_REQUEST_REVOKED' or \ - (event_type == 'OBS_SRCSRV_REQUEST_STATECHANGE' and \ - event_fields['state'] == 'revoked')): - notify_submiter(event_fields, data) - gerrit = Gerrit(os.getenv('GERRIT_HOSTNAME'), os.getenv('GERRIT_USERNAME'), os.getenv('GERRIT_SSHPORT'), int(os.getenv('GERRIT_SILENT_MODE'))) - try: - gitprj = Git('%s/%s.git' % (os.getenv('GIT_CACHE_DIR'), - data['GIT_PROJECT'])) - except GitRepositoryError, err: - # clone project to local workspace if it doesn't exist in git cache - if not clone_gitproject(data['GIT_PROJECT'], - os.path.join(os.getenv('WORKSPACE'), data['GIT_PROJECT'])): - return -1 - gitprj = Git('%s/%s' % (os.getenv('WORKSPACE'), data['GIT_PROJECT'])) - - trigger_next(event_type, data) - - if event_type == 'OBS_SRCSRV_REQUEST_STATECHANGE': - if event_fields['state'] == 'declined': - request_rejected(data, gerrit) - - elif event_type == 'OBS_SRCSRV_REQUEST_CREATE': - request_created(data) - - elif event_type == 'OBS_SRCSRV_REQUEST_ACCEPTED': - return request_accepted(data, gerrit, gitprj) - elif event_type == 'OBS_SRCSRV_REQUEST_REVOKED': - request_revoked(data) + for project_data in projects_data: + data.update(project_data) + data.update({'GIT_AUTHOR_EMAIL': '%s <%s>' % \ + (project_data['author'], + project_data['email'])}) + if not (event_type == 'OBS_SRCSRV_REQUEST_REVOKED' or \ + (event_type == 'OBS_SRCSRV_REQUEST_STATECHANGE' and \ + event_fields['state'] == 'revoked')): + notify_submiter(event_fields, data) + + try: + gitprj = Git('%s/%s.git' % (os.getenv('GIT_CACHE_DIR'), + data['GIT_PROJECT'])) + except GitRepositoryError, err: + # clone project to local workspace if it doesn't exist in git cache + if not clone_gitproject(data['GIT_PROJECT'], + os.path.join(os.getenv('WORKSPACE'), + data['GIT_PROJECT'])): + return -1 + gitprj = Git('%s/%s' % (os.getenv('WORKSPACE'), + data['GIT_PROJECT'])) + + trigger_next(event_type, data) + + if event_type == 'OBS_SRCSRV_REQUEST_STATECHANGE': + if event_fields['state'] == 'declined': + request_rejected(data, gerrit) + + elif event_type == 'OBS_SRCSRV_REQUEST_CREATE': + request_created(data) + + elif event_type == 'OBS_SRCSRV_REQUEST_ACCEPTED': + return request_accepted(data, gerrit, gitprj) + elif event_type == 'OBS_SRCSRV_REQUEST_REVOKED': + request_revoked(data) return 0 diff --git a/requests/mailer.py b/requests/mailer.py index 0c3cef6..845bf71 100644 --- a/requests/mailer.py +++ b/requests/mailer.py @@ -323,9 +323,6 @@ def mailer(request, _bs, request_data, sr_enabled_users=None, \ elif isinstance(request_data[_cc], str) or \ isinstance(request_data[_cc], unicode): return_dict['Cc'] += request_data[_cc].split(',') - # CC mailinglist and the author of superseded SRs - for desp in request_data['descriptions']: - return_dict['Cc'].append(desp['GIT_AUTHOR_EMAIL']) return_dict['realname'] = request_data['author'] if request_data['bccs']: