File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 44
55from mergify_cli import utils
66from mergify_cli .ci import detector
7+ from mergify_cli .ci .git_refs import detector as git_refs_detector
78from mergify_cli .ci .junit_processing import cli as junit_processing_cli
89from mergify_cli .ci .scopes import cli as scopes_cli
910from mergify_cli .ci .scopes import exceptions as scopes_exc
@@ -193,6 +194,17 @@ async def junit_process(
193194 )
194195
195196
197+ @ci .command (
198+ help = """Give the base/head git references of the pull request""" ,
199+ short_help = """Give the base/head git references of the pull request""" ,
200+ )
201+ def git_refs () -> None :
202+ ref = git_refs_detector .detect ()
203+ click .echo (f"Base: { ref .base } " )
204+ click .echo (f"Head: { ref .head } " )
205+ ref .maybe_write_to_github_outputs ()
206+
207+
196208@ci .command (
197209 help = """Give the list scope impacted by changed files""" ,
198210 short_help = """Give the list scope impacted by changed files""" ,
Original file line number Diff line number Diff line change @@ -458,3 +458,28 @@ def test_scopes_send(
458458 assert result .exit_code == 0 , result .output
459459 payload = json .loads (post_mock .calls [0 ].request .content )
460460 assert sorted (payload ["scopes" ]) == ["backend" , "foobar" , "frontend" ]
461+
462+
463+ def test_git_refs (
464+ tmp_path : pathlib .Path ,
465+ monkeypatch : pytest .MonkeyPatch ,
466+ ) -> None :
467+ event_data = {"before" : "abc123" , "after" : "xyz987" }
468+ event_file = tmp_path / "event.json"
469+ event_file .write_text (json .dumps (event_data ))
470+
471+ output_file = tmp_path / "github_output"
472+
473+ monkeypatch .setenv ("GITHUB_OUTPUT" , str (output_file ))
474+ monkeypatch .setenv ("GITHUB_EVENT_NAME" , "push" )
475+ monkeypatch .setenv ("GITHUB_EVENT_PATH" , str (event_file ))
476+
477+ runner = testing .CliRunner ()
478+ result = runner .invoke (ci_cli .git_refs , [])
479+ assert result .exit_code == 0 , result .output
480+
481+ content = output_file .read_text ()
482+ expected = """base=abc123
483+ head=xyz987
484+ """
485+ assert content == expected
You can’t perform that action at this time.
0 commit comments