def create( reviewers: List[str] = [], workspace: str = get_workspace(), slug: str = get_slug(), title: str = get_last_commit_msg(), src_branch: str = get_current_branch(), dst_branch: str = None, body: str = None, close: bool = True, ): """Create new PR""" data = { "title": title, "source": {"branch": {"name": src_branch}}, "close_source_branch": close, } if dst_branch: data["destination"] = {"branch": {"name": dst_branch}} if reviewers: data["reviewers"] = [{"uuid": r} for r in reviewers] if body: data["description"] = body console = Console() with console.status("[bold green]Loading..."): run_cmd(["git", "push", "origin", src_branch]) resp = post(prs_url.format(workspace=workspace, slug=slug), data) handle_error(resp) table = generate_prs_table([resp]) console.print(table) print(resp["links"]["html"]["href"])
def comments( id: str, workspace: str = get_workspace(), slug: str = get_slug(), ): """View comments for PR by ID""" url = comments_url.format(workspace=workspace, slug=slug, id=id) console = Console() with console.status("[bold green]Loading..."): resp = get(url) handle_error(resp) for comment in resp["values"]: user = comment["user"]["display_name"] updated = parse_dt(comment["updated_on"]) path = comment["inline"]["path"] # _from = comment["inline"]["from"] or "" to = comment["inline"]["to"] or "" line = f":{to}" if to else "" deleted = "(Deleted)" if comment["deleted"] else "" console.print( f"[bold]{user}[/bold] {path}{line} [dim]{updated}[/dim] {deleted}" ) markdown = comment["content"]["raw"] console.print(Padding(Markdown(markdown, code_theme=config.THEME), 1))
def list( workspace: str = get_workspace(), ): """ List repositories in current workspace """ console = Console() with console.status("[bold green]Loading..."): resp = get(repo_url.format(workspace=workspace)) table = generate_repo_table(resp["values"]) console.print(table)
def request_changes( id: str, workspace: str = get_workspace(), slug: str = get_slug(), ): """Request changes for PR by ID""" url = request_changes_url.format(workspace=workspace, slug=slug, id=id) console = Console() with console.status("[bold green]Loading..."): resp = post(url) handle_error(resp) print(resp["state"].title())
def decline( id: str, workspace: str = get_workspace(), slug: str = get_slug(), ): """Decline PR by ID""" url = decline_url.format(workspace=workspace, slug=slug, id=id) console = Console() with console.status("[bold green]Loading..."): resp = post(url) handle_error(resp) print(resp["state"].title())
def checkout( id: str, workspace: str = get_workspace(), slug: str = get_slug(), ): """Checkout PR by ID""" url = pr_url.format(workspace=workspace, slug=slug, id=id) console = Console() with console.status("[bold green]Loading..."): resp = get(url) branch_name = resp["source"]["branch"]["name"] run_cmd(["git", "checkout", "-b", branch_name]) run_cmd(["git", "pull", "origin", branch_name])
def list( workspace: str = get_workspace(), slug: str = get_slug(), state: State = State.OPEN, extra: bool = True ): """List all PRs""" console = Console() with console.status("[bold green]Loading..."): response = get( prs_url.format(workspace=workspace, slug=slug), {"state": state} ) table = generate_prs_table(response["values"], extra=extra) console.print(table)
def merge( id: str, workspace: str = get_workspace(), slug: str = get_slug(), delete_branch: bool = True, ): """Merge PR by ID""" url = merge_url.format(workspace=workspace, slug=slug, id=id) resp = post(url) handle_error(resp) print(resp["state"].title()) if delete_branch: dst_branch = resp["destination"]["branch"]["name"] run_cmd(["git", "checkout", dst_branch]) src_branch = resp["source"]["branch"]["name"] run_cmd(["git", "branch", "-D", src_branch])
def diff( id: str, workspace: str = get_workspace(), slug: str = get_slug(), ): """Show diff by PR ID""" url = diff_url.format( workspace=workspace, slug=slug, id=id, ) console = Console() with console.status("[bold green]Loading..."): diff = get_text(url) syntax = Syntax( diff, "diff", theme=config.THEME, background_color=config.BG_COLOR ) console.print(syntax)
def commits( id: str, workspace: str = get_workspace(), slug: str = get_slug(), ): """View commits of PR by ID""" url = commits_url.format(workspace=workspace, slug=slug, id=id) console = Console() with console.status("[bold green]Loading..."): resp = get(url) handle_error(resp) for commit in resp["values"]: hash = commit["hash"] author = commit["author"]["raw"] date = commit["date"] message = commit["message"] console.print(f"[bold]commit {hash}[/bold]") console.print(f"[cyan]Author: {author}") console.print(f"[cyan]Date: {date}") console.print(Padding(message.strip(), (1, 4)))