From 7352046eb8b1b012348f96773f286c6f164784da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84=C2=A0?= Date: Wed, 3 Jun 2020 15:34:00 +0200 Subject: [PATCH 1/2] Fix GitLab merge request merge_status enum --- danger_python/models.py | 5 +++++ scripts/input_schema.json | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/danger_python/models.py b/danger_python/models.py index fec7b02..8dadb8b 100644 --- a/danger_python/models.py +++ b/danger_python/models.py @@ -1399,7 +1399,12 @@ class Config: class GitLabMRMergeStatus(Enum): + UNCHECKED = "unchecked" + CANNOT_BE_MERGED_RECHECK = "cannot_be_merged_recheck" + CHECKING = "checking" + CANNOT_BE_MERGED_RECHECKING = "cannot_be_merged_rechecking" CAN_BE_MERGED = "can_be_merged" + CANNOT_BE_MERGED = "cannot_be_merged" class GitLabMRMilestone(BaseModel): diff --git a/scripts/input_schema.json b/scripts/input_schema.json index dc2988d..2f8fd83 100644 --- a/scripts/input_schema.json +++ b/scripts/input_schema.json @@ -1733,7 +1733,12 @@ }, "merge_status": { "enum": [ - "can_be_merged" + "unchecked", + "cannot_be_merged_recheck", + "checking", + "cannot_be_merged_rechecking", + "can_be_merged", + "cannot_be_merged" ], "type": "string" }, From 849f2cab50666739fe57c850d956719719e6a20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Thu, 26 Jan 2023 19:51:51 +0100 Subject: [PATCH 2/2] Handle invocation from newer Danger JS versions --- danger_python/cli.py | 6 ++++++ tests/test_cli.py | 20 ++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/danger_python/cli.py b/danger_python/cli.py index 2ee2b87..a41c655 100644 --- a/danger_python/cli.py +++ b/danger_python/cli.py @@ -17,6 +17,12 @@ def cli() -> None: @cli.command() def run() -> None: """Runs dangerfile.py as a danger process""" + runner() + + +@danger_command(cli, "runner") +def runner(arguments: List[str]) -> None: + """Runs dangerfile.py as a danger process, ignoring unknown options""" with open("dangerfile.py", "r") as dangerfile: try: execute_dangerfile(dangerfile.read()) diff --git a/tests/test_cli.py b/tests/test_cli.py index 01db4b2..1916387 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -69,29 +69,31 @@ def test_ci_command_invokes_danger_js_passing_arguments(): assert result.output == "The output!\n" +@pytest.mark.parametrize("command", ["run", "runner"]) @pytest.mark.parametrize( "dangerfile", ['print("Hello world")\n' 'print("Goodbye world")'] ) @pytest.mark.usefixtures("danger") -def test_run_command_invokes_dangerfile(): +def test_run_command_invokes_dangerfile(command): """ Test that run command invokes dangerfile.py contents. """ runner = CliRunner() - result = runner.invoke(cli, ["run"]) + result = runner.invoke(cli, [command]) assert result.exit_code == 0 assert result.output.startswith("Hello world\nGoodbye world\n") +@pytest.mark.parametrize("command", ["run", "runner"]) @pytest.mark.parametrize("dangerfile", ["This is not a valid syntax of Python"]) @pytest.mark.usefixtures("danger") -def test_run_command_shows_traceback_when_dangerfile_fails(): +def test_run_command_shows_traceback_when_dangerfile_fails(command): """ Test that run command shows traceback when dangerfile.py fails. """ runner = CliRunner(mix_stderr=False) - result = runner.invoke(cli, ["run"]) + result = runner.invoke(cli, [command]) expected_error = ( "There was an error when executing dangerfile.py:\n" @@ -116,21 +118,23 @@ def test_default_command_invokes_dangerfile(): assert result.output.startswith("Default command\n") +@pytest.mark.parametrize("command", ["run", "runner"]) @pytest.mark.parametrize("modified_files", [["a.py", "b.py"]]) @pytest.mark.parametrize("dangerfile", ["print(danger.git.modified_files)"]) @pytest.mark.usefixtures("danger") -def test_executing_dangerfile_passes_danger_instance_to_the_script(): +def test_executing_dangerfile_passes_danger_instance_to_the_script(command): """ Test that executing run command passes danger instance with parsed input to the Dangerfile locals. """ runner = CliRunner() - result = runner.invoke(cli, ["run"]) + result = runner.invoke(cli, [command]) assert result.exit_code == 0 assert result.output.startswith("['a.py', 'b.py']\n") +@pytest.mark.parametrize("command", ["run", "runner"]) @pytest.mark.parametrize( "dangerfile", [ @@ -141,12 +145,12 @@ def test_executing_dangerfile_passes_danger_instance_to_the_script(): ], ) @pytest.mark.usefixtures("danger") -def test_executing_dangerfile_prints_results_to_stdout(): +def test_executing_dangerfile_prints_results_to_stdout(command): """ Test that executing run command reports results back to output. """ runner = CliRunner() - result = runner.invoke(cli, ["run"]) + result = runner.invoke(cli, [command]) expected_json = { "fails": [{"message": "You are going to fail"}],