Skip to content

Commit 7eebbbc

Browse files
committed
feat: add scopes to CI Job summary
Change-Id: I60d468996a12845f9e5c770f529fd33515242124
1 parent 9b6d25a commit 7eebbbc

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

mergify_cli/ci/scopes/cli.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,25 @@ def maybe_write_github_outputs(
7575
)
7676

7777

78+
def maybe_write_github_step_summary(
79+
base: str,
80+
all_scopes: abc.Iterable[str],
81+
scopes_hit: set[str],
82+
) -> None:
83+
gha = os.environ.get("GITHUB_STEP_SUMMARY")
84+
if not gha:
85+
return
86+
# Build a pretty Markdown table with emojis
87+
markdown = f"## Mergify CI Scope Matching Results for `{base}...HEAD`\n\n"
88+
markdown += "| 🎯 Scope | ✅ Match |\n|:--|:--|\n"
89+
for scope in sorted(all_scopes):
90+
emoji = "✅" if scope in scopes_hit else "❌"
91+
markdown += f"| `{scope}` | {emoji} |\n"
92+
93+
with pathlib.Path(gha).open("a", encoding="utf-8") as fh:
94+
fh.write(markdown)
95+
96+
7897
class InvalidDetectedScopeError(exceptions.ScopesError):
7998
pass
8099

@@ -136,6 +155,7 @@ def detect(config_path: str) -> DetectedScope:
136155
click.echo("No scopes matched.")
137156

138157
maybe_write_github_outputs(all_scopes, scopes_hit)
158+
maybe_write_github_step_summary(base.ref, all_scopes, scopes_hit)
139159
return DetectedScope(base_ref=base.ref, scopes=scopes_hit)
140160

141161

mergify_cli/tests/ci/scopes/test_cli.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,30 @@ def test_maybe_write_github_outputs(
292292
assert """{"backend": "true", "docs": "true", "frontend": "false"}""" in content
293293

294294

295+
def test_maybe_write_github_step_summary(
296+
tmp_path: pathlib.Path,
297+
monkeypatch: pytest.MonkeyPatch,
298+
) -> None:
299+
output_file = tmp_path / "github_step_summary"
300+
monkeypatch.setenv("GITHUB_STEP_SUMMARY", str(output_file))
301+
302+
all_scopes = ["backend", "frontend", "docs"]
303+
scopes_hit = {"backend", "docs"}
304+
305+
cli.maybe_write_github_step_summary("da26838", all_scopes, scopes_hit)
306+
307+
content = output_file.read_text()
308+
expected = """## Mergify CI Scope Matching Results for `da26838...HEAD`
309+
310+
| 🎯 Scope | ✅ Match |
311+
|:--|:--|
312+
| `backend` | ✅ |
313+
| `docs` | ✅ |
314+
| `frontend` | ❌ |
315+
"""
316+
assert content == expected
317+
318+
295319
def test_maybe_write_github_outputs_no_env(
296320
monkeypatch: pytest.MonkeyPatch,
297321
) -> None:

0 commit comments

Comments
 (0)