PEP8 clean
This commit is contained in:
parent
e1aff6c4cf
commit
2dfe1f0e9a
15 changed files with 338 additions and 168 deletions
|
|
@ -14,24 +14,30 @@ nemubotversion = 3.4
|
|||
|
||||
from more import Response
|
||||
|
||||
def help_full ():
|
||||
return "!github /repo/: Display information about /repo/.\n!github_user /user/: Display information about /user/."
|
||||
|
||||
def help_full():
|
||||
return ("!github /repo/: Display information about /repo/.\n"
|
||||
"!github_user /user/: Display information about /user/.")
|
||||
|
||||
|
||||
def info_repos(repo):
|
||||
raw = urlopen("https://api.github.com/search/repositories?q=%s" % quote(repo), timeout=10)
|
||||
raw = urlopen("https://api.github.com/search/repositories?q=%s" %
|
||||
quote(repo), timeout=10)
|
||||
return json.loads(raw.read().decode())
|
||||
|
||||
|
||||
def info_user(username):
|
||||
raw = urlopen("https://api.github.com/users/%s" % quote(username), timeout=10)
|
||||
raw = urlopen("https://api.github.com/users/%s" % quote(username),
|
||||
timeout=10)
|
||||
user = json.loads(raw.read().decode())
|
||||
|
||||
raw = urlopen("https://api.github.com/users/%s/repos?sort=updated" % quote(username), timeout=10)
|
||||
raw = urlopen("https://api.github.com/users/%s/repos?sort=updated" %
|
||||
quote(username), timeout=10)
|
||||
user["repos"] = json.loads(raw.read().decode())
|
||||
|
||||
return user
|
||||
|
||||
|
||||
def info_issue(repo, issue=None):
|
||||
rp = info_repos(repo)
|
||||
if rp["items"]:
|
||||
|
|
@ -41,14 +47,17 @@ def info_issue(repo, issue=None):
|
|||
|
||||
try:
|
||||
if issue is not None:
|
||||
raw = urlopen("https://api.github.com/repos/%s/issues/%s" % (quote(fullname), quote(issue)), timeout=10)
|
||||
return [ json.loads(raw.read().decode()) ]
|
||||
raw = urlopen("https://api.github.com/repos/%s/issues/%s" %
|
||||
(quote(fullname), quote(issue)), timeout=10)
|
||||
return [json.loads(raw.read().decode())]
|
||||
else:
|
||||
raw = urlopen("https://api.github.com/repos/%s/issues?sort=updated" % quote(fullname), timeout=10)
|
||||
raw = urlopen("https://api.github.com/repos/%s/issues?sort=updated"
|
||||
% quote(fullname), timeout=10)
|
||||
return json.loads(raw.read().decode())
|
||||
except urllib.error.HTTPError:
|
||||
raise IRCException("Repository not found")
|
||||
|
||||
|
||||
def info_commit(repo, commit=None):
|
||||
rp = info_repos(repo)
|
||||
if rp["items"]:
|
||||
|
|
@ -58,10 +67,12 @@ def info_commit(repo, commit=None):
|
|||
|
||||
try:
|
||||
if commit is not None:
|
||||
raw = urlopen("https://api.github.com/repos/%s/commits/%s" % (quote(fullname), quote(commit)), timeout=10)
|
||||
return [ json.loads(raw.read().decode()) ]
|
||||
raw = urlopen("https://api.github.com/repos/%s/commits/%s" %
|
||||
(quote(fullname), quote(commit)), timeout=10)
|
||||
return [json.loads(raw.read().decode())]
|
||||
else:
|
||||
raw = urlopen("https://api.github.com/repos/%s/commits" % quote(fullname), timeout=10)
|
||||
raw = urlopen("https://api.github.com/repos/%s/commits" %
|
||||
quote(fullname), timeout=10)
|
||||
return json.loads(raw.read().decode())
|
||||
except urllib.error.HTTPError:
|
||||
raise IRCException("Repository not found")
|
||||
|
|
@ -74,16 +85,27 @@ def cmd_github(msg):
|
|||
|
||||
repos = info_repos(" ".join(msg.cmds[1:]))
|
||||
|
||||
res = Response(channel=msg.channel, nomore="No more repository", count=" (%d more repo)")
|
||||
res = Response(channel=msg.channel,
|
||||
nomore="No more repository",
|
||||
count=" (%d more repo)")
|
||||
|
||||
for repo in repos["items"]:
|
||||
homepage = ""
|
||||
if repo["homepage"] is not None:
|
||||
homepage = repo["homepage"] + " - "
|
||||
res.append_message("Repository %s: %s%s Main language: %s; %d forks; %d stars; %d watchers; %d opened_issues; view it at %s" % (repo["full_name"], homepage, repo["description"], repo["language"], repo["forks"], repo["stargazers_count"], repo["watchers_count"], repo["open_issues_count"], repo["html_url"]))
|
||||
res.append_message("Repository %s: %s%s Main language: %s; %d forks; %d stars; %d watchers; %d opened_issues; view it at %s" %
|
||||
(repo["full_name"],
|
||||
homepage,
|
||||
repo["description"],
|
||||
repo["language"], repo["forks"],
|
||||
repo["stargazers_count"],
|
||||
repo["watchers_count"],
|
||||
repo["open_issues_count"],
|
||||
repo["html_url"]))
|
||||
|
||||
return res
|
||||
|
||||
|
||||
@hook("cmd_hook", "github_user")
|
||||
def cmd_github(msg):
|
||||
if len(msg.cmds) < 2:
|
||||
|
|
@ -95,14 +117,22 @@ def cmd_github(msg):
|
|||
|
||||
if "login" in user:
|
||||
if user["repos"]:
|
||||
kf = " Known for: " + ", ".join([repo["name"] for repo in user["repos"]])
|
||||
kf = (" Known for: " +
|
||||
", ".join([repo["name"] for repo in user["repos"]]))
|
||||
else:
|
||||
kf = ""
|
||||
if "name" in user:
|
||||
name = user["name"]
|
||||
else:
|
||||
name = user["login"]
|
||||
res.append_message("User %s: %d public repositories; %d public gists; %d followers; %d following; view it at %s.%s" % (name, user["public_repos"], user["public_gists"], user["followers"], user["following"], user["html_url"], kf))
|
||||
res.append_message("User %s: %d public repositories; %d public gists; %d followers; %d following; view it at %s.%s" %
|
||||
(name,
|
||||
user["public_repos"],
|
||||
user["public_gists"],
|
||||
user["followers"],
|
||||
user["following"],
|
||||
user["html_url"],
|
||||
kf))
|
||||
else:
|
||||
raise IRCException("User not found")
|
||||
|
||||
|
|
@ -166,9 +196,9 @@ def cmd_github(msg):
|
|||
commits = info_commit(repo, commit)
|
||||
|
||||
for commit in commits:
|
||||
res.append_message("Commit %s by %s on %s: %s" % (commit["sha"][:10],
|
||||
commit["commit"]["author"]["name"],
|
||||
commit["commit"]["author"]["date"],
|
||||
commit["commit"]["message"].replace("\n", " ")))
|
||||
|
||||
res.append_message("Commit %s by %s on %s: %s" %
|
||||
(commit["sha"][:10],
|
||||
commit["commit"]["author"]["name"],
|
||||
commit["commit"]["author"]["date"],
|
||||
commit["commit"]["message"].replace("\n", " ")))
|
||||
return res
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue