Skip to content

Instantly share code, notes, and snippets.

@3XclusiVe
Created June 24, 2017 21:49
Show Gist options
  • Save 3XclusiVe/8ce38f9b4effda99fa9d575d0a27da1e to your computer and use it in GitHub Desktop.
Save 3XclusiVe/8ce38f9b4effda99fa9d575d0a27da1e to your computer and use it in GitHub Desktop.
import subprocess
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def git(command):
command_to_execute = str.split(command)
output = subprocess.check_output(["git"] + command_to_execute)
return output
def new_version_was_realesed():
list_of_head_tags = git("tag -l --points-at HEAD")
list_of_head_tags = str.splitlines(list_of_head_tags)
new_version_tag_prefix = "v"
for tag in list_of_head_tags:
if(tag.startswith(new_version_tag_prefix)):
return True
return False
class sender(object):
pass
def create_notification_message():
message = MIMEMultipart()
message['Subject'] = "[new version released]"
repository_url = git("config --get remote.origin.url")
repository_url = repository_url[:-5]
list_of_head_tags = git("tag -l --points-at HEAD")
list_of_head_tags = str.splitlines(list_of_head_tags)
new_version_tag_prefix = "v"
for tag in list_of_head_tags:
if (tag.startswith(new_version_tag_prefix)):
new_version = tag
firmware_url = repository_url + "/" + "releases/tag/" + new_version
body = "New version of LXT firmware available at:" \
"\n" + firmware_url + "\n\n" \
"*** This is an automatically generated email, please do not reply ***"
message.attach(MIMEText(body, 'plain'))
return message.as_string()
def send_notification_email(sender, addressees_list):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(sender.email, sender.password)
message = create_notification_message()
for email_address in addressees_list:
server.sendmail(sender.email, email_address , message)
server.quit()
if __name__ == "__main__":
sender = sender()
sender.email = "[email protected]"
sender.password = "pass"
addressees_list = ["reciever1gmail.com", "[email protected]"]
if(new_version_was_realesed()):
send_notification_email(sender, addressees_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment