From 194bc237867ceb8feb1f01e1c2a2e0a4a3fedae5 Mon Sep 17 00:00:00 2001 From: Hasan Wan Date: Mon, 13 Aug 2012 16:16:36 +0800 Subject: [PATCH] push accepted tag back, fix some email addr issues Change-Id: I016acddfee8b7b2d6ef123023b289bc035454a31 Signed-off-by: Hasan Wan --- common/git.py | 9 +++++ request.py | 26 +++++++------ requests/mailer.py | 111 ++++++++--------------------------------------------- 3 files changed, 39 insertions(+), 107 deletions(-) diff --git a/common/git.py b/common/git.py index 75a647c..6049e9d 100644 --- a/common/git.py +++ b/common/git.py @@ -344,6 +344,15 @@ class Git: else: return None + def push(self, *args): + + with Workdir(self.path): + ret, outs = self._exec_git('push', list(args)) + if not ret: + return outs.splitlines() + else: + return None + def fetch(self, *args): """Download objects and refs from another repository """ diff --git a/request.py b/request.py index 5653e36..e152543 100644 --- a/request.py +++ b/request.py @@ -60,8 +60,6 @@ def OBS_Git_data(event_fields): ret_data = {} for key in obs_fields_mapping.keys(): - print key, ' = ', event_fields[key], '**', obs_fields_mapping[key] - ret_data[obs_fields_mapping[key]] = event_fields[key] desp_list = [] @@ -112,7 +110,12 @@ def request_accepted(data, gerrit, gitprj): gitprj.create_tag(accepted_tag, "Accepted by %s" %(data['reviewer']), data['commitid']) -def request_rejected(data, gerrit, gitprj) + args = [] + args.append('ssh://%s@%s:%s/%s' %(gerrit.username, gerrit.host, gerrit.port, data['git_project'])) + args.append('%s --tag' %(accepted_tag)) + gitprj.push(' '.join(args)) + +def request_rejected(data, gerrit, gitprj): print '====request rejected====================================' message = 'The SR (Submit Request) has been rejected to OBS %s project.\n' \ @@ -151,12 +154,13 @@ def request_created(data, gerrit, gitprj): #gerrit.review(commit = data['commitid'], message = message) -def notify_submiter(event_fields, desp): +def notify_submiter(event_fields, data): print '====Notify the tag owner====================================' mail_to = [] - for entry in desp: - mail_to.append(entry['auth_email']) + mail_to.append(data['author_email']) + for entry in data['descriptions']: + mail_to.append(entry['author_email']) status = True @@ -165,8 +169,8 @@ def notify_submiter(event_fields, desp): # email notification to mailing list if MAILINGLIST: status = mailer(event_fields, bs, event_fields, NOREPLY_EMAIL_SENDER, - MAILINGLIST, BCC_MAILS, SR_ENABLE_USER, EMAIL_TEMPLATES_DIR) - + MAILINGLIST, BCC_MAILS, data, SR_ENABLE_USER, EMAIL_TEMPLATES_DIR) + print status if status: with open('%s.env' %(BUILD_TAG),'w') as f: for a in status.keys(): @@ -180,16 +184,14 @@ if not event_fields: print 'Invalid OBS event: %s' %(OBS_EVENT_STRING) sys.exit(-1) -notify_submiter(event_fields, desp) - data = OBS_Git_data(event_fields) +notify_submiter(event_fields, data) + gerrit = Gerrit(GERRIT_HOSTNAME, GERRIT_USERNAME, GERRIT_SSHPORT) gitprj = git.Git('%s/%s' %(GIT_CACHE_DIR, data['git_project'])) -gitprj.ls_files() - if event_fields['type'] == 'OBS_SRCSRV_REQUEST_STATECHANGE': pass elif event_fields['type'] == 'OBS_SRCSRV_REQUEST_CREATE': diff --git a/requests/mailer.py b/requests/mailer.py index 1a737cf..add3bda 100644 --- a/requests/mailer.py +++ b/requests/mailer.py @@ -263,48 +263,6 @@ def _get_reqinfo(bs, rid, details): logger('error', str(e)) return '' -def _get_userinfo(bs, uid): - try: - if uid in USERDATA_CACHE: - realname, email = USERDATA_CACHE[uid] - else: - realname, email = bs.getUserData(uid, "realname", "email") - USERDATA_CACHE[uid] = (realname, email) - if realname == '-': - realname = uid - return realname, '%s <%s>' % (realname, email) - except: - return uid, '' - -def _expand_addr(bs, req, mails, ml): - expanded = [] - - for m in set(mails): - if m == 'mailinglist': - expanded.append(ml) - elif m == 'bugowners': - bugowners = bs.getPackagePersons(req['targetproject'], req['targetpackage'], 'bugowner') - for bugowner in bugowners: - expanded.append(_get_userinfo(bs, bugowner)[1]) - elif m == 'devels': - devel = bs.getPackageDevel(req['targetproject'], req['targetpackage']) - - if not devel: - devel = bs.getProjectDevel(req['targetproject']) - - if devel: - maintainers = bs.getProjectPersons(devel[0], 'maintainer') - for maintainer in maintainers: - expanded.append(_get_userinfo(bs, maintainer)[1]) - elif m in req: - expanded.append(_get_userinfo(bs, req[m])[1]) - else: - # some real mailaddrs - expanded.append(m) - - # uniquy -> filter out empty -> list - return [i for i in set(expanded) if i] - def _is_valid_submitter(temp, author, enabled_users): if temp in ('obs_request_newpkg', 'obs_request_create'): if enabled_users: @@ -313,11 +271,13 @@ def _is_valid_submitter(temp, author, enabled_users): return True -def mailer(request, bs, wi, noreply_sender, ml, bccs, +def mailer(request, bs, wi, noreply_sender, ml, bccs, request_data, sr_enabled_users = None, templates_dir = '.'): """ Sending mail to mailing list for different kinds of reqs """ + return_dict = {} + if request['type'] not in MAIL_TRIGGERS.keys(): return False @@ -348,70 +308,32 @@ def mailer(request, bs, wi, noreply_sender, ml, bccs, ccs = copy.copy(tri['cc']) reqinfo = _get_reqinfo(bs, rid, tri['detail?']) - wi['reqinfo'] = reqinfo - - if tgtprj.startswith('devel:'): - for alist in (tos, ccs): - maintainers = bs.getProjectPersons(tgtprj, 'maintainer') - if 'mailinglist' in alist: - # if submitter is a maintainer, only send to other maintainers - if request['author'] in maintainers: - alist.remove('mailinglist') - maintainers.remove(request['author']) - - for maintainer in maintainers: - alist.append(_get_userinfo(bs, maintainer)[1]) - - mailto_list = _expand_addr(bs, request, tos, ml) - mailcc_list = _expand_addr(bs, request, ccs, ml) - - has_noreply = False - for alist in (mailto_list, mailcc_list): - for pair in alist: - if noreply_sender in pair: - alist.remove(pair) - has_noreply = True - - if has_noreply: - if ml in mailcc_list: - mailcc_list.remove(ml) - if ml not in mailto_list: - mailto_list.insert(0, ml) - - wi['To'] = mailto_list - wi['Cc'] = mailcc_list + return_dict['reqinfo'] = reqinfo + return_dict['To'] = request_data['author_email'] + return_dict['Cc'] = ml + return_dict['realname'] = request_data['author'] if bccs: - wi['Bcc'] = bccs - - if tri['from']: - realname = _get_userinfo(bs, request[tri['from']])[0] - else: - realname = 'Tizen OBS' - wi['realname'] = realname - wi['From'] = '%s <%s>' % (realname, noreply_sender) + return_dict['Bcc'] = bccs + return_dict['From'] = '%s <%s>' % (return_dict['realname'], noreply_sender) first_to = tos[0] if first_to == 'mailinglist': - wi['receipt'] = 'List' - else: - wi['receipt'] = _get_userinfo(bs, request[first_to])[0] + return_dict['receipt'] = 'List' - wi['realname'] = realname - - wi['template'] = tri['temp'] + return_dict['template'] = tri['temp'] from string import Template - wi['subject'] = Template(tri['sub']).safe_substitute(request, reqid=str(rid)) + return_dict['subject'] = Template(tri['sub']).safe_substitute(request, reqid=str(rid)) # other items from obs_event for var in tri['fields']: - wi[var] = request[var] + return_dict[var] = request[var] break if 'template' in wi.keys(): - template_str = file(os.path.join(templates_dir, wi['template'])).read() + template_str = file(os.path.join(templates_dir, return_dict['template'])).read() msg = [] try: from Cheetah.Template import Template @@ -422,8 +344,7 @@ def mailer(request, bs, wi, noreply_sender, ml, bccs, from string import Template template = Template(template_str) body = template.safe_substitute(wi, msg="\n".join(msg)) - wi['body'] = body.replace('\n','\\n') - + return_dict['body'] = body.replace('\n','\\n') - return wi + return return_dict -- 2.7.4