def cli(gh, repo): """ List forkers, stargazers, & watchers """ print_json({ "forkers": [f["owner"]["login"] for f in repo.forks.get()], "stargazers": [s["login"] for s in repo.stargazers.get()], "watchers": [w["login"] for w in repo.subscribers.get()], })
def cli(gh, path, method, accept, data): """ Make an arbitrary API request """ headers = {} if accept: headers["Accept"] = '; '.join(accept) ret = gh[path][method](data=data, headers=headers) if ret is not None: print_json(ret)
def cli(gh, description, homepage, private, name, verbose): """ Create a new repository """ data = { "name": name, "private": private, } if description is not None: data["description"] = description if homepage is not None: data["homepage"] = homepage print_json(repo_info(gh.user.repos.post(json=data), verbose))
def cli(gh, description, private, filename, file, verbose): """ Convert a file into a gist """ with open(file) as fp: ### Use `click.open_file` instead? content = fp.read() if filename is None: filename = os.path.basename(file) data = { "files": {filename: {"content": content}}, "public": not private, } if description is not None: data["description"] = description print_json(gist_info(gh.gists.post(json=data), verbose))
def cli(ctx, repo, title, body, label, assignee, milestone, verbose): """ Create a new issue """ ### TODO: Open editor if title isn't given data = { "title": title, "body": body.read() if body is not None else None, "labels": label, "assignees": assignee, } if milestone is not None: try: data["milestone"] = int(milestone) except ValueError: for ms in repo.milestones.get(): if ms["title"] == milestone: data["milestone"] = ms["id"] break else: ctx.fail("Unknown milestone: " + milestone) print_json(issue_info(repo.issues.post(json=data), verbose))
def cli(gh, repos, verbose): """ Show repository details """ if not repos: repos = [gh.repository()] print_json([repo_info(r.get(), verbose) for r in repos])
def cli(gh, issues, verbose): """ Show issue details """ print_json([issue_info(i.get(), verbose) for i in issues])
def cli(gh, gists, verbose): """ Show gist details """ print_json([gist_info(g.get(), verbose) for g in gists])
def cli(repo, verbose): """ Fork a repository """ print_json(repo_info(repo.forks.post(), verbose))