Skip to content

Commit d1d95b2

Browse files
committed
fix: say so when only part of the pull request could be listed
A local range shorter than the pull request, with no API to fill it in, is still checked -- the commits the clone has are better than HEAD alone -- but no longer in silence: the run is annotated with how many of the commits were listed and that the others were not checked.
1 parent e521f05 commit d1d95b2

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎main.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,16 @@ def get_pr_commit_messages() -> list[Commit]:
531531
total = get_pr_event().get("commits")
532532
if messages and (not total or len(messages) == total):
533533
return messages
534-
return get_messages_from_api() or messages
534+
from_api = get_messages_from_api()
535+
if from_api:
536+
return from_api
537+
if messages:
538+
warn_shallow_checkout(
539+
f"Only {len(messages)} of the pull request's {total} commits "
540+
"could be listed",
541+
"the others were not checked",
542+
)
543+
return messages
535544
except Exception as e:
536545
print(
537546
f"::warning::Failed to retrieve PR commit messages: {e}",

‎main_test.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,12 @@ def test_a_range_cut_short_by_a_shallow_clone_asks_the_api(self):
514514
patch("main.get_messages_from_event_range", return_value=[("b2", "fix")]),
515515
patch("main.get_pr_event", return_value={"commits": 2}),
516516
patch("main.get_messages_from_api", return_value=[]) as api,
517+
patch("main.warn_shallow_checkout") as warn,
517518
):
518-
# The API cannot help either: keep what the clone had.
519+
# The API cannot help either: check what the clone had, and say so.
519520
self.assertEqual(main.get_pr_commit_messages(), [("b2", "fix")])
520521
api.assert_called_once()
522+
self.assertIn("Only 1 of the pull request's 2 commits", warn.call_args[0][0])
521523

522524
def test_asks_the_api_when_the_clone_holds_none_of_them(self):
523525
with (

0 commit comments

Comments
 (0)