🏡 index : ~doyle/dave.git

author Jordan Doyle <jordan@doyle.wf> 2017-07-30 7:41:54.0 +01:00:00
committer Jordan Doyle <jordan@doyle.wf> 2017-07-30 7:41:54.0 +01:00:00
commit
d17f6dee4130334d9c986fb87bc528eba09de1b9 [patch]
tree
112855e1b8847b71aa126c74426fb7c424416c0a
parent
684002831f8879546dd3739a88f4eb2fea2e5be4
download
d17f6dee4130334d9c986fb87bc528eba09de1b9.tar.gz

Add shortened git commit url to update msgs



Diff

 dave/dave.py | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/dave/dave.py b/dave/dave.py
index ca00757..deff98d 100644
--- a/dave/dave.py
+++ a/dave/dave.py
@@ -12,6 +12,7 @@
import re
import subprocess
import dave.config as config
import requests
from twisted.internet import reactor, task
from twisted.internet.threads import deferToThread

@@ -129,13 +130,27 @@
        output = subprocess.check_output(args).split(b",")
        log.msg("Pulled latest commit.")

        msg = "{} ({}) authored by {} ({}) {}".format(
        # get a shortened git commit url
        try:
            r = requests.post('https://git.io/', {
                "url": "https://github.com/{}/commit/{}".format(
                    config.config["repo"],
                    str(output[0], 'utf-8')
                )
            }, allow_redirects=False, timeout=3)

            commit = r.headers['Location']
        except:
            commit = ""

        msg = "{} ({}) authored by {} ({}) {} {}".format(
            str(output[1], 'utf-8'),
            str(output[0], 'utf-8'),
            str(output[3], 'utf-8'),
            str(output[4], 'utf-8'),
            naturaltime(datetime.utcnow().timestamp() -
                        float(output[2]))
                        float(output[2])),
            commit
        )

        log.msg("Updated, {}".format(msg))