from util import hook, http
import json
import gitio
shortcuts = {"cloudbot": "ClouDev/CloudBot"}
def truncate(msg):
nmsg = msg.split(" ")
out = None
x = 0
for i in nmsg:
if x <= 7:
if out:
out = out + " " + nmsg[x]
else:
out = nmsg[x]
x = x + 1
return out
return out + "..."
@hook.command
def ghissues(inp):
"""ghissues username/repo [number] - Get specified issue summary, or open issue count """
args = inp.split(" ")
try:
if args[0] in shortcuts:
repo = shortcuts[args[0]]
repo = args[0]
url = "https://api.github.com/repos/%s/issues" % repo
except IndexError:
return "Invalid syntax. .github issues username/repo [number]"
url = url + "/%s" % args[1]
number = True
number = False
data = json.loads(http.open(url).read())
print url
if not number:
data = data[0]
print data
return "Repo has no open issues"
except ValueError:
return "Invalid data returned. Check arguments (.github issues username/repo [number]"
fmt = "Issue: #%s (%s) by %s: %s | %s %s" # (number, state, user.login, title, truncate(body), gitio.gitio(data.url))
number = data["number"]
if data["state"] == "open":
state = u"\x033\x02OPEN\x02\x0f"
closedby = None
state = u"\x034\x02CLOSED\x02\x0f by %s" % data["closed_by"]["login"]
user = data["user"]["login"]
title = data["title"]
summary = truncate(data["body"])
gitiourl = gitio.gitio(data["html_url"])
return fmt % (number, state, user, title, summary, gitiourl)