Create github issues from mutt

A few month ago, I switched my email workflow to mutt. It’s quite nice to never leave the command line, right?

I’ve been using mutt2task.py quite a lot, to turn emails into taskwarrior tasks.

Now, I’ve seen myself quite often turning email into github issues, so being the typical geek-programmer type, I automated this with a mutt script that convert an emails into a github issue.

It needs a little bit of manual editing to get this working:

  • install hub
  • set GITHUB_TOKEN, or GITHUB_USER and GITHUB_PASSWORD environment variables
  • modify the last part of the script that determines the project from the email content and cd to the project’s directory.

The gist: https://gist.github.com/j3k0/4658374fa1500624bedcf69ffc124242

The code:


#!/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 "~/path/to/mutt2issue.py"
#
# 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])

I’m a consultant and developer for Mobile, Web, Games and Apps projects. I co-founded Fovea 8 years ago.

Posted in Blog