|
- #!/usr/bin/python
-
- '''
- ## Description
-
- A script to get mail from issues@example.com and create github issues
-
- ## Installation Instuctions
-
- * Install the github python API:
- ```
- pip install github3.py
- ```
- * Place the script under */usr/local/sbin/mail2github_issues.py*.
- * Edit */etc/aliases*:
- ```
- issues: "|/usr/local/sbin/mail2github_issues.py"
- ```
- * Run the `newaliases` command.
- '''
-
- import sys
- import email
- import datetime
- import github3
-
- DEBUG = 0
- TOKEN = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
- USER = 'exampledev'
- REPO = 'myrepo'
-
-
- def main():
- '''
- Main function
- '''
-
- raw_msg = ''
-
- for line in sys.stdin:
- raw_msg = raw_msg + line
-
- msg = email.message_from_string(raw_msg)
-
- gh_session = github3.login(token=TOKEN)
-
- issue = {'title': msg['Subject'],
- 'body': msg.get_payload(),
- 'created_at': str(datetime.datetime.now().isoformat() + 'Z')
- }
-
- repository = gh_session.repository(USER, REPO)
- repository.import_issue(**issue)
-
-
- if DEBUG:
- filename = "/tmp/msg.out"
- out = open(filename, 'w')
- out.write(msg['Subject'])
- out.write("\n\n")
- out.write(msg['Date'])
- out.write("\n\n")
- out.write(msg.get_payload())
-
- if __name__ == "__main__":
- main()
|