Skip to content

Commit

Permalink
feat: remove the change ID from the PR description
Browse files Browse the repository at this point in the history
The change ID is stored in the commit message and in the GitHub HEAD branch name. We can remove it from the pull request description to make it prettier.

Change-Id: I56e44be6d6aff6de89d80e1f649568c2c199406c
  • Loading branch information
DouglasBlackwood committed Feb 24, 2024
1 parent 91450ed commit 44f598e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions mergify_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright © 2021-2023 Mergify SAS
# Copyright © 2021-2024 Mergify SAS
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
Expand Down Expand Up @@ -572,9 +572,7 @@ async def stack(
pulls: list[PullRequest] = []
continue_create_or_update = True
for changeid, commit, title, message in changes:
depends_on = ""
if pulls:
depends_on = f"\n\nDepends-On: #{pulls[-1]['number']}"
depends_on = pulls[-1] if pulls else None
stacked_dest_branch = f"{stack_prefix}/{changeid}"
if continue_create_or_update:
pull, action = await create_or_update_stack(
Expand All @@ -584,7 +582,7 @@ async def stack(
changeid,
commit,
title,
message + depends_on,
format_pull_description(message, depends_on),
known_changeids,
create_as_draft,
)
Expand Down Expand Up @@ -630,6 +628,16 @@ async def stack(
console.log("[green]Finished :tada:[/]")


def format_pull_description(message: str, depends_on: PullRequest | None) -> str:
depends_on_header = ""
if depends_on is not None:
depends_on_header = f"\n\nDepends-On: #{depends_on['number']}"

message = CHANGEID_RE.sub("", message).rstrip("\n")

return message + depends_on_header


def GitHubToken(v: str) -> str:
if not v:
raise ValueError
Expand Down
6 changes: 3 additions & 3 deletions mergify_cli/tests/test_mergify_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async def test_stack_create(
"head": "/current-branch/I29617d37762fd69809c255d7e7073cb11f8fbf50",
"base": "main",
"title": "Title commit 1",
"body": "Message commit 1\n\nChange-Id: I29617d37762fd69809c255d7e7073cb11f8fbf50",
"body": "Message commit 1",
"draft": False,
}

Expand All @@ -177,7 +177,7 @@ async def test_stack_create(
"head": "/current-branch/I29617d37762fd69809c255d7e7073cb11f8fbf51",
"base": "/current-branch/I29617d37762fd69809c255d7e7073cb11f8fbf50",
"title": "Title commit 2",
"body": "Message commit 2\n\nChange-Id: I29617d37762fd69809c255d7e7073cb11f8fbf51\n\nDepends-On: #1",
"body": "Message commit 2\n\nDepends-On: #1",
"draft": False,
}

Expand Down Expand Up @@ -272,7 +272,7 @@ async def test_stack_update(
"head": "/current-branch/I29617d37762fd69809c255d7e7073cb11f8fbf50",
"base": "main",
"title": "Title",
"body": "Message\n\nChange-Id: I29617d37762fd69809c255d7e7073cb11f8fbf50",
"body": "Message",
}


Expand Down

0 comments on commit 44f598e

Please sign in to comment.