Fixed formatting.

This commit is contained in:
Fletcher Boyd 2013-09-04 18:30:04 +08:00
parent 146ae3c279
commit 4069dd21a3
89 changed files with 615 additions and 496 deletions

View file

@ -4,58 +4,59 @@ import urllib2
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
if x <= 7:
if out:
out = out + " " + nmsg[x]
else:
out = nmsg[x]
x += 1
if x <= 7:
return out
return out
else:
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]]
else:
repo = args[0]
url = "https://api.github.com/repos/%s/issues" % repo
if args[0] in shortcuts:
repo = shortcuts[args[0]]
else:
repo = args[0]
url = "https://api.github.com/repos/%s/issues" % repo
except IndexError:
return "Invalid syntax. .github issues username/repo [number]"
return "Invalid syntax. .github issues username/repo [number]"
try:
url = url + "/%s" % args[1]
number = True
url += "/%s" % args[1]
number = True
except IndexError:
number = False
number = False
try:
data = json.loads(http.open(url).read())
print url
if not number:
try:
data = data[0]
except IndexError:
print data
return "Repo has no open issues"
data = json.loads(http.open(url).read())
print url
if not number:
try:
data = data[0]
except IndexError:
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))
fmt1 = "Issue: #%s (%s) by %s: %s %s" # (number, state, user.login, title, gitio.gitio(data.url))
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))
fmt1 = "Issue: #%s (%s) by %s: %s %s" # (number, state, user.login, title, gitio.gitio(data.url))
number = data["number"]
if data["state"] == "open":
state = u"\x033\x02OPEN\x02\x0f"
closedby = None
state = u"\x033\x02OPEN\x02\x0f"
else:
state = u"\x034\x02CLOSED\x02\x0f by %s" % data["closed_by"]["login"]
state = u"\x034\x02CLOSED\x02\x0f by %s" % data["closed_by"]["login"]
user = data["user"]["login"]
title = data["title"]
summary = truncate(data["body"])
@ -63,15 +64,15 @@ def ghissues(inp):
if "Failed to get URL" in gitiourl:
gitiourl = gitio(data["html_url"] + " " + repo.split("/")[1] + number)
if summary == "":
return fmt1 % (number, state, user, title, gitiourl)
return fmt1 % (number, state, user, title, gitiourl)
else:
return fmt % (number, state, user, title, summary, gitiourl)
return fmt % (number, state, user, title, summary, gitiourl)
@hook.command
def gitio(inp):
"gitio <url> [code] -- Shorten Github URLs with git.io. [code] is" \
" a optional custom short code."
"""gitio <url> [code] -- Shorten Github URLs with git.io. [code] is
a optional custom short code."""
split = inp.split(" ")
url = split[0]