-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from nollied/fix-init
Add new functionality for creating merge requests and pull requests with custom titles and descriptions.
- Loading branch information
Showing
10 changed files
with
303 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.3.11" | ||
__version__ = "0.3.12" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import Optional, Tuple | ||
|
||
import click | ||
from mindflow.cli.new_click_cli.util import passthrough_command | ||
from mindflow.core.git.mr import run_mr | ||
|
||
|
||
@click.group() | ||
def mr(): | ||
""" | ||
MR command. | ||
""" | ||
pass | ||
|
||
|
||
@passthrough_command(help="Generate a git pr response by feeding git diff to gpt") | ||
@click.option( | ||
"-t", | ||
"--title", | ||
help="Don't use mindflow to generate a pr title, use this one instead.", | ||
default=None, | ||
) | ||
@click.option( | ||
"-d", | ||
"--description", | ||
help="Don't use mindflow to generate a pr body, use this one instead.", | ||
default=None, | ||
) | ||
def create( | ||
args: Tuple[str], title: Optional[str] = None, description: Optional[str] = None | ||
): | ||
""" | ||
PR command. | ||
""" | ||
if title is not None: | ||
click.echo( | ||
f"Warning: Using message '{title}' instead of mindflow generated message." | ||
) | ||
click.echo("It's recommended that you don't use the -t/--title flag.") | ||
|
||
if description is not None: | ||
click.echo( | ||
f"Warning: Using message '{description}' instead of mindflow generated message." | ||
) | ||
click.echo("It's recommended that you don't use the -d/--description flag.") | ||
|
||
run_mr(args, title=title, description=description) | ||
|
||
|
||
mr.add_command(create) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,48 @@ | ||
import click | ||
from typing import Optional, Tuple | ||
|
||
import click | ||
from mindflow.cli.new_click_cli.util import passthrough_command | ||
from mindflow.core.git.pr import run_pr | ||
|
||
|
||
@click.command(help="Generate a git pr response by feeding git diff to gpt") | ||
@click.group() | ||
def pr(): | ||
""" | ||
PR command. | ||
""" | ||
run_pr() | ||
pass | ||
|
||
|
||
@passthrough_command(help="Generate a git pr response by feeding git diff to gpt") | ||
@click.option( | ||
"-t", | ||
"--title", | ||
help="Don't use mindflow to generate a pr title, use this one instead.", | ||
default=None, | ||
) | ||
@click.option( | ||
"-b", | ||
"--body", | ||
help="Don't use mindflow to generate a pr body, use this one instead.", | ||
default=None, | ||
) | ||
def create(args: Tuple[str], title: Optional[str] = None, body: Optional[str] = None): | ||
""" | ||
PR command. | ||
""" | ||
if title is not None: | ||
click.echo( | ||
f"Warning: Using message '{title}' instead of mindflow generated message." | ||
) | ||
click.echo("It's recommended that you don't use the -t/--title flag.") | ||
|
||
if body is not None: | ||
click.echo( | ||
f"Warning: Using message '{body}' instead of mindflow generated message." | ||
) | ||
click.echo("It's recommended that you don't use the -d/--description flag.") | ||
|
||
run_pr(args, title=title, body=body) | ||
|
||
|
||
pr.add_command(create) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import subprocess | ||
from typing import Optional, Tuple, List | ||
|
||
from mindflow.core.git.pr import create_title_and_body, is_valid_pr | ||
from mindflow.utils.command_parse import get_flag_value | ||
|
||
|
||
def run_mr( | ||
args: Tuple[str], title: Optional[str] = None, description: Optional[str] = None | ||
): | ||
base_branch = get_flag_value(args, ["--target-branch", "-b"]) | ||
head_branch = get_flag_value(args, ["--source-branch", "-s"]) | ||
|
||
if base_branch is None: | ||
# Determine the name of the default branch | ||
base_branch = ( | ||
subprocess.check_output(["git", "symbolic-ref", "refs/remotes/origin/HEAD"]) | ||
.decode() | ||
.strip() | ||
.split("/")[-1] | ||
) | ||
|
||
if head_branch is None: | ||
# Get the name of the current branch | ||
head_branch = ( | ||
subprocess.check_output(["git", "symbolic-ref", "--short", "HEAD"]) | ||
.decode("utf-8") | ||
.strip() | ||
) | ||
|
||
if not is_valid_pr(base_branch, head_branch): | ||
return | ||
|
||
if not title or not description: | ||
title, description = create_title_and_body(base_branch, title, description) | ||
|
||
create_merge_request(args, title, description) | ||
|
||
|
||
def create_merge_request(args: Tuple[str], title: str, description: str): | ||
command: List[str] = ["glab", "mr", "create"] + list(args) + ["--title", title, "--description", description] # type: ignore | ||
pr_result = subprocess.check_output(command).decode("utf-8") | ||
if "https://" in pr_result: | ||
print("Merge request created successfully") | ||
print(pr_result) | ||
else: | ||
print( | ||
"Failed to create pull request. Please raise an issue at: https://github.com/nollied/mindflow-cli/issues" | ||
) | ||
exit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.