Skip to content

Commit

Permalink
feat(better prompts for mainstream commands): user will be prompted f…
Browse files Browse the repository at this point in the history
…or mandatory inputs if none
  • Loading branch information
psadi committed Nov 9, 2022
1 parent d87abd2 commit 8a6e19f
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 59 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,5 @@ cython_debug/
.idea/
__pycache__
__PYCACHE__
node_modules
package*.json
2 changes: 1 addition & 1 deletion bb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
bb: A command line utility to manage pull requests in bitbucket
"""
__version__ = "0.4.4"
__version__ = "0.4.5"
__author__ = "P S, Adithya (psadi) ([email protected])"
__license__ = "MIT"
__doc__ = f"VERSION: {__version__} \nAUTHOR: {__author__} \nLICENSE: {__license__}"
58 changes: 41 additions & 17 deletions bb/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,22 @@ def version_callback(value: bool):

def error_tip():
console.print(
f"💻 Try running 'bb --verbose [OPTIONS] COMMAND [ARGS]' to debug",
f"\n💻 Try running 'bb --verbose [OPTIONS] COMMAND [ARGS]' to debug",
style="dim white",
)


def validate_input(input: any, expected: str, error: str) -> str:
if not input:
input: str = typer.prompt(f"? {expected}")

if input == None or input.lower() == "none":
console.print(f"{error}", style="red")
raise (typer.Exit(code=1))

return input


@app.callback()
def callback(
verbose: bool = False,
Expand All @@ -68,14 +79,14 @@ def create(
):
"""- create new pull request"""
try:
if is_git_repo() is not True:
if not is_git_repo():
console.print("Not a git repository", style="red")
raise typer.Exit(code=1)

if not target:
target = typer.prompt("Target Branch")
target = validate_input(target, "Target branch", "Target branch cannot be none")

create_pull_request(target, yes, diff, rebase)

except Exception:
error_tip()
if state["verbose"]:
Expand All @@ -84,20 +95,24 @@ def create(

@app.command()
def delete(
id: Optional[List[int]] = typer.Option(
None, help="pull request number(s) to delete"
),
id: str = typer.Option("", help="pull request number(s) to delete"),
yes: bool = typer.Option(False, help="skip confirmation prompt"),
diff: bool = typer.Option(False, help="show diff before deleting pull request"),
):
"""- delete pull request's by id's"""
try:
if is_git_repo() is not True:
if not is_git_repo():
console.print("Not a git repository", style="red")
raise typer.Exit(code=1)
if not id:
id = typer.prompt("Pull request number(s)").split(",")

id = validate_input(
False,
"Pull request id(s) to delete\n? ex: id (or) id1, id2",
"Id's cannot be empty",
).split(",")

delete_pull_request(id, yes, diff)

except Exception:
error_tip()
if state["verbose"]:
Expand All @@ -120,11 +135,12 @@ def show(
):
"""- show pull request's authored & reviewing"""
try:
if is_git_repo() is not True:
if not is_git_repo():
console.print("Not a git repository", style="red")
raise typer.Exit(code=1)

show_pull_request(role.value, all)

except Exception:
error_tip()
if state["verbose"]:
Expand Down Expand Up @@ -154,16 +170,21 @@ class Action(str, Enum):

@app.command()
def review(
id: int = typer.Option("", help="pull request number to review"),
id: str = typer.Option("", help="pull request number to review"),
action: Action = Action.none.value,
):
"""- review Pull Request by ID"""
try:
if action.value == "none":
console.print("Action cannot be none", style="red")
raise (typer.Exit(code=1))

review_pull_request(id, action.value)
id = validate_input(id, "Pull request id to review", "id cannot be none")
action = validate_input(
False if action.value is "none" else action.value,
"Action [approve|unapprove|needs_work]",
"action cannot be none",
)

review_pull_request(id, action)

except Exception:
error_tip()
if state["verbose"]:
Expand All @@ -172,7 +193,7 @@ def review(

@app.command()
def merge(
id: int = typer.Option("", help="pull request number to merge"),
id: str = typer.Option("", help="pull request number to merge"),
delete_source_branch: bool = typer.Option(
False, help="deletes source branch after merge"
),
Expand All @@ -183,6 +204,8 @@ def merge(
):
"""- merge pull request by id"""
try:

id = validate_input(id, "Pull request id to merge", "id cannot be none")
merge_pull_request(id, delete_source_branch, rebase, yes)
except Exception:
error_tip()
Expand All @@ -196,6 +219,7 @@ def diff(
):
"""- view diff in pull request (file only)"""
try:
id = validate_input(id, "Pull request number to show diff", "id cannot be none")
show_diff(id)
except Exception:
error_tip()
Expand Down
Empty file modified bb/pr/copy.py
100644 → 100755
Empty file.
8 changes: 1 addition & 7 deletions bb/pr/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,7 @@ def create_pull_request(target: str, yes: bool, diff: bool, rebase: bool) -> Non
richprint.console.print("Source & target cannot be the same", style="bold red")
raise Exit(code=1)

if (
rebase
or prompt(f"? Do you want rebase '{from_branch}' branch from '{target}' [y/n]")
.lower()
.strip()
== "y"
):
if rebase:
with richprint.live_progress(
f"Rebasing {from_branch} with {target} ... "
) as live:
Expand Down
16 changes: 11 additions & 5 deletions bb/utils/cmnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ def git_rebase(target_branch: str) -> None:
try:
subprocess_run(f"git pull --rebase origin {target_branch}")
subprocess_run(f"git push --force-with-lease")
except Exception:
str_print(
"Try running `git diff --diff-filter=U --relative` to know more on local conflicts",
"dim white",
)
except Exception as ex:
error_code = int(str(ex).split(" ")[-1].replace(".", ""))
error_message = {
128: "cannot pull with rebase, you have unstaged/uncommitted changes\nplease commit or stash them.",
1: "Try running `git diff --diff-filter=U --relative` to know more on local conflicts",
}
if error_code in error_message.keys():
str_print(
error_message[error_code],
"dim white",
)
raise Exit(code=1)
Empty file modified bb/utils/cp.py
100644 → 100755
Empty file.
Empty file modified img/bb.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 24 additions & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bb"
version = "0.4.4"
version = "0.4.5"
description = "cli to manage bitbucket pull requests"
authors = ["psadi <[email protected]>"]
readme = "README.md"
Expand All @@ -19,9 +19,9 @@ bb = "bb.main:app"
[tool.poetry.dependencies]
python = ">=3.7,<4.0.0"
typer = {extras = ["all"], version = "^0.4.0"}
requests = "^2.27.1"
rich = "^11.1.0"
pyperclip = "^1.8.2"
requests = ">=2.27.1"
rich = ">=11.1.0"
pyperclip = ">=1.8.2"

[tool.poetry.dev-dependencies]
pytest = "^5.2"
Expand Down

0 comments on commit 8a6e19f

Please sign in to comment.