Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle correctly when body is empty #529

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions mergify_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,13 @@ async def create_or_update_stack( # noqa: PLR0913,PLR0917
"base": change.base_branch,
}
if keep_pull_request_title_and_body:
if change.pull["body"] is None:
msg = "GitHub returned a pull request without body set"
raise RuntimeError(msg)
pull_changes.update(
{"body": format_pull_description(change.pull["body"], depends_on)},
{
"body": format_pull_description(
change.pull["body"] or "",
depends_on,
),
},
)
else:
pull_changes.update(
Expand Down Expand Up @@ -599,12 +601,9 @@ async def get_remote_changes(
user: str,
repo: str,
stack_prefix: str,
author: str,
) -> RemoteChanges:
r_author, r_repo = await asyncio.gather(
client.get("/user"),
client.get(f"/repos/{user}/{repo}"),
)
author = r_author.json()["login"]
r_repo = await client.get(f"/repos/{user}/{repo}")
repository = r_repo.json()

r = await client.get(
Expand Down Expand Up @@ -649,7 +648,7 @@ async def get_remote_changes(

# TODO(charly): fix code to conform to linter (number of arguments, local
# variables, statements, positional arguments, branches)
async def stack_push( # noqa: PLR0913, PLR0915, PLR0917
async def stack_push( # noqa: PLR0912, PLR0913, PLR0915, PLR0917
github_server: str,
token: str,
skip_rebase: bool,
Expand All @@ -660,6 +659,7 @@ async def stack_push( # noqa: PLR0913, PLR0915, PLR0917
create_as_draft: bool = False,
keep_pull_request_title_and_body: bool = False,
only_update_existing_pulls: bool = False,
author: str | None = None,
) -> None:
os.chdir(await git("rev-parse", "--show-toplevel"))
dest_branch = await git_get_branch_name()
Expand Down Expand Up @@ -720,8 +720,18 @@ async def stack_push( # noqa: PLR0913, PLR0915, PLR0917
follow_redirects=True,
timeout=5.0,
) as client:
if author is None:
r_author = await client.get("/user")
author = r_author.json()["login"]

with console.status("Retrieving latest pushed stacks"):
remote_changes = await get_remote_changes(client, user, repo, stack_prefix)
remote_changes = await get_remote_changes(
client,
user,
repo,
stack_prefix,
author,
)

with console.status("Preparing stacked branches..."):
console.log("Stacked pull request plan:", style="green")
Expand Down Expand Up @@ -877,6 +887,7 @@ async def _stack_push(args: argparse.Namespace) -> None:
args.draft,
args.keep_pull_request_title_and_body,
args.only_update_existing_pulls,
args.author,
)


Expand Down Expand Up @@ -951,6 +962,11 @@ async def register_stack_push_parser(
help="Don't update the title and body of already opened pull requests. "
"Default fetched from git config if added with `git config --add mergify-cli.stack-keep-pr-title-body true`",
)
parser.add_argument(
"--author",
help="Set the author of the stack (default: the author of the token)",
)

parser.add_argument(
"--trunk",
"-t",
Expand Down