#!/usr/bin/python
import os
import subprocess
import urllib2
import json

username = "GITHUB_USERNAME"
url = "http://DOMAIN_URL"

f = open('.git/config')
lines = f.readlines()
f.close()
for line in lines:
  if "url" in line:
    remote = line.split("/")
    owner = remote[len(remote)-2]
    if ":" in owner:
      owner = owner.split(":")
      owner = owner[len(owner)-1]
    remote = str(owner) + "/" + remote[len(remote)-1][:-5]
    break

p = subprocess.Popen('git log -1 --oneline', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
  message = line,
  retval = p.wait()
message = message[0]

data = json.dumps({"username":username, "message":message, "remote": remote})
req = urllib2.Request(url, data, {'Content-Type': 'application/json'})
f = urllib2.urlopen(req)
response = f.read()
f.close()
