Created
April 14, 2019 11:46
-
-
Save goyalmohit/fc8d12031ab53009b7d4785cf5d18f34 to your computer and use it in GitHub Desktop.
Python script for git post-commit hook
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 | |
import smtplib | |
from email.mime.text import MIMEText | |
from subprocess import check_output | |
# Get the git log --stat entry of the new commit | |
log = check_output(['git', 'log', '-1', '--stat', 'HEAD']) | |
# Create a plaintext email message | |
msg = MIMEText("Look, I'm actually doing some work:\n\n%s" % log) | |
msg['Subject'] = 'Git post-commit hook notification' | |
msg['From'] = 'git@example.com' | |
msg['To'] = 'dev-team@example.com' | |
# Send the message | |
SMTP_SERVER = 'smtp.example.com' | |
SMTP_PORT = 587 | |
session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) | |
session.ehlo() | |
session.starttls() | |
session.ehlo() | |
session.login(msg['From'], 'secretPassword') | |
session.sendmail(msg['From'], msg['To'], msg.as_string()) | |
session.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment