Skip to content

Commit f5e13b6

Browse files
jdclaude
andauthored
feat(stack): improve stack comment design with table layout and branding (#1153)
Redesign the stack comment posted on PRs to use a markdown table instead of a plain numbered list. The current PR is now bolded for better scannability. The header links to Mergify Stacks documentation for branding and discoverability. The comment detection is backward-compatible: old-format comments ("part of a stack:") are still found and updated to the new format on the next push. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1a628af commit f5e13b6

2 files changed

Lines changed: 39 additions & 15 deletions

File tree

mergify_cli/stack/push.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -355,24 +355,33 @@ async def stack_push(
355355
class StackComment:
356356
pulls: list[github_types.PullRequest]
357357

358-
STACK_COMMENT_FIRST_LINE: typing.ClassVar[str] = (
358+
_STACK_COMMENT_OLD_HEADER: typing.ClassVar[str] = (
359359
"This pull request is part of a stack:\n"
360360
)
361361

362+
STACK_COMMENT_HEADER: typing.ClassVar[str] = (
363+
"This pull request is part of a [Mergify stack](https://docs.mergify.com/stacks/):\n"
364+
)
365+
362366
def body(self, current_pull: github_types.PullRequest) -> str:
363-
body = self.STACK_COMMENT_FIRST_LINE
367+
body = self.STACK_COMMENT_HEADER
368+
body += "\n"
369+
body += "| # | Pull Request | |\n"
370+
body += "|--:|---|---|\n"
364371

365-
for pull in self.pulls:
366-
body += f"1. {pull['title']} ([#{pull['number']}]({pull['html_url']}))"
367-
if pull == current_pull:
368-
body += " 👈"
369-
body += "\n"
372+
for i, pull in enumerate(self.pulls, 1):
373+
title = pull["title"].replace("|", "\\|")
374+
entry = f"{title} ([#{pull['number']}]({pull['html_url']}))"
375+
status = "👈" if pull == current_pull else ""
376+
body += f"| {i} | {entry} | {status} |\n"
370377

371378
return body
372379

373380
@staticmethod
374381
def is_stack_comment(comment: github_types.Comment) -> bool:
375-
return comment["body"].startswith(StackComment.STACK_COMMENT_FIRST_LINE)
382+
return comment["body"].startswith(
383+
StackComment.STACK_COMMENT_HEADER,
384+
) or comment["body"].startswith(StackComment._STACK_COMMENT_OLD_HEADER)
376385

377386

378387
async def _update_comment_for_pull(

mergify_cli/tests/stack/test_push.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,25 @@ async def test_stack_create(
155155

156156
# First stack comment is created
157157
assert len(post_comment1_mock.calls) == 1
158-
expected_body = """This pull request is part of a stack:
159-
1. Title commit 1 ([#1](https://github.com/repo/user/pull/1)) 👈
160-
1. Title commit 2 ([#2](https://github.com/repo/user/pull/2))
158+
expected_body = """This pull request is part of a [Mergify stack](https://docs.mergify.com/stacks/):
159+
160+
| # | Pull Request | |
161+
|--:|---|---|
162+
| 1 | Title commit 1 ([#1](https://github.com/repo/user/pull/1)) | 👈 |
163+
| 2 | Title commit 2 ([#2](https://github.com/repo/user/pull/2)) | |
161164
"""
162165
assert json.loads(post_comment1_mock.calls.last.request.content) == {
163166
"body": expected_body,
164167
}
165168

166169
# Second stack comment is created
167170
assert len(post_comment2_mock.calls) == 1
168-
expected_body = """This pull request is part of a stack:
169-
1. Title commit 1 ([#1](https://github.com/repo/user/pull/1))
170-
1. Title commit 2 ([#2](https://github.com/repo/user/pull/2)) 👈
171+
expected_body = """This pull request is part of a [Mergify stack](https://docs.mergify.com/stacks/):
172+
173+
| # | Pull Request | |
174+
|--:|---|---|
175+
| 1 | Title commit 1 ([#1](https://github.com/repo/user/pull/1)) | |
176+
| 2 | Title commit 2 ([#2](https://github.com/repo/user/pull/2)) | 👈 |
171177
"""
172178
assert json.loads(post_comment2_mock.calls.last.request.content) == {
173179
"body": expected_body,
@@ -297,7 +303,9 @@ async def test_stack_update_no_rebase(
297303
},
298304
],
299305
)
300-
respx_mock.patch("/repos/user/repo/issues/comments/456").respond(200)
306+
patch_comment_mock = respx_mock.patch(
307+
"/repos/user/repo/issues/comments/456",
308+
).respond(200)
301309

302310
await push.stack_push(
303311
github_server="https://api.github.com/",
@@ -319,6 +327,13 @@ async def test_stack_update_no_rebase(
319327
"body": "Message",
320328
}
321329

330+
# Old-format stack comment is updated to new table format
331+
assert len(patch_comment_mock.calls) == 1
332+
comment_body = json.loads(patch_comment_mock.calls.last.request.content)["body"]
333+
assert comment_body.startswith(
334+
"This pull request is part of a [Mergify stack]",
335+
)
336+
322337

323338
@pytest.mark.respx(base_url="https://api.github.com/")
324339
async def test_stack_update(

0 commit comments

Comments
 (0)