Created
November 6, 2018 07:03
-
-
Save j3k0/4658374fa1500624bedcf69ffc124242 to your computer and use it in GitHub Desktop.
mutt script that creates github issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
## About | |
# Use the content of an email to create a github issue | |
# | |
## Usage | |
# add this to your .muttrc: | |
# macro index,pager \ei "<pipe-message>~/path/to/mutt2issue.py<enter>" | |
# | |
# Requires the `hub` CLI tool: https://hub.github.com/ | |
# import libraries | |
import sys | |
import time | |
import email | |
import os | |
from email.header import decode_header | |
from subprocess import call, Popen, PIPE | |
import re | |
# read from stdin and parse subject | |
message = sys.stdin.read() | |
message = email.message_from_string(message) | |
body = None | |
for part in message.walk(): | |
if part.get_content_type() == "text/plain": | |
if body is None: | |
body = "" | |
charset = part.get_content_charset() | |
if charset is None: | |
charset = 'ASCII' | |
body += unicode( | |
part.get_payload(decode=True), | |
charset, 'replace' | |
).encode('utf8','replace') | |
message = message['Subject'] | |
# decode internationalized subject and transform ascii into utf8 | |
message = decode_header(message) | |
message = ' '.join([ unicode(t[0], t[1] or 'ASCII' ) for t in message ]) | |
message = message.encode('utf8') | |
message = '%s\n%s' % (message, body) | |
if 'my-project-id' in message or 'some-other-string' in message: | |
print 'Project X detected' | |
os.chdir('/path/to/my/project') | |
else: | |
print 'Cannot recognize the project in email...' | |
time.sleep(1) | |
print message | |
time.sleep(2) | |
sys.exit() | |
call(['hub', 'issue', 'create', '--edit', '-m', message]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment