diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2018-12-04 16:18:49 -0500 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2018-12-04 16:18:49 -0500 |
commit | 5b04e804bbef8ccf6912f0a39d97c11df607f89f (patch) | |
tree | 135c82459c77ebf19f96aca1a7651d7d0c9a0ef6 | |
parent | 221fe109320b9e5e066cc20350f9f152e376a4a4 (diff) | |
download | korg-helpers-5b04e804bbef8ccf6912f0a39d97c11df607f89f.tar.gz |
Deal with multipart-signed pull requests
And, really, multipart-html requests, even though we won't see them on a
VGER list.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rwxr-xr-x | git-patchwork-bot.py | 3 | ||||
-rwxr-xr-x | pr-tracker-bot.py | 28 |
2 files changed, 21 insertions, 10 deletions
diff --git a/git-patchwork-bot.py b/git-patchwork-bot.py index 4ff1f3b..af1acec 100755 --- a/git-patchwork-bot.py +++ b/git-patchwork-bot.py @@ -33,7 +33,7 @@ import datetime from email.mime.text import MIMEText from email.header import Header -from email.utils import make_msgid, formatdate, getaddresses +from email.utils import make_msgid, formatdate # Send all email 8-bit, this is not 1999 from email import charset @@ -56,6 +56,7 @@ _project_cache = None logger = logging.getLogger('gitpwcron') + # Lifted from patchwork pwclient class Transport(xmlrpclib.SafeTransport): diff --git a/pr-tracker-bot.py b/pr-tracker-bot.py index 37147c5..3f54b26 100755 --- a/pr-tracker-bot.py +++ b/pr-tracker-bot.py @@ -193,12 +193,11 @@ def get_remote_ref_from_body(body): def record_pr_data(msg_commit_id, msg, c): - pr_commit_id = None - body = msg.get_payload(decode=True) + body = get_plain_part(msg) if body is None: return False - body = body.decode('utf-8', errors='replace') + pr_commit_id = None for cid_re in PULL_BODY_WITH_COMMIT_ID_RE: matches = cid_re.search(body) if matches: @@ -214,7 +213,6 @@ def record_pr_data(msg_commit_id, msg, c): return False logger.debug('pr_commit_id=%s', pr_commit_id) - msg_id = msg['Message-Id'] received = time.strftime('%Y-%m-%dT%H:%M:%S%z') @@ -448,6 +446,21 @@ def get_all_prs(pirepo, cutoffdays=30): return rows +def get_plain_part(msg): + # walk until we find the first text/plain part + body = None + for part in msg.walk(): + if part.get_content_type().find('text/plain') < 0: + continue + body = part.get_payload(decode=True) + if body is None: + continue + + body = body.decode('utf-8', errors='replace') + + return body + + def get_all_new_prs(c, refname, prs, cutoffdays=30): sent_prs = get_all_thanked_prs(c, refname, cutoffdays) new_prs = list() @@ -467,12 +480,10 @@ def to_or_cc_contains(tocc, addrs): def mail_thanks_for_pr(refname, commit_id, merge_id, pirepo, msg_commit_id, config, nomail): orig = git_get_message_from_pi(pirepo, msg_commit_id) - origbody = orig.get_payload(decode=True) + origbody = get_plain_part(orig) if origbody is None: return None - origbody = origbody.decode('utf-8', errors='replace') - if 'notifinbody' in config: # Don't send anything if we find a certain string in the body # e.g. 'pr-tracker-no-ack' @@ -741,11 +752,10 @@ def show_unapplied(repo, pitopdir, cmdconfig, use_json): if not to_or_cc_contains(targets, settings['onlyifto']): continue - origbody = orig.get_payload(decode=True) + origbody = get_plain_part(orig) if origbody is None: continue - origbody = origbody.decode('utf-8', errors='replace') remoterepo, remoteref = get_remote_ref_from_body(origbody) values = { |