Skip to content

Commit 2a33b00

Browse files
Allow PRs to have more than 100 commits for check_dependent_project.sh (#94)
* allow PRs to have more than 100 commits * add missing fetch * fix exit code detection * fix variable usage * better var name
1 parent 1f182c9 commit 2a33b00

File tree

1 file changed

+53
-30
lines changed

1 file changed

+53
-30
lines changed

check_dependent_project.sh

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,44 @@ github_api="https://api.github.com"
5050
github_graphql_api="https://api.github.com/graphql"
5151
org_github_prefix="https://github.com/$org"
5252
org_crates_prefix="git+$org_github_prefix"
53+
# Heuristic: assume the companion PR has a common merge ancestor with master
54+
# in its last N commits.
55+
merge_ancestor_max_depth=256
5356
set +x
5457

58+
merge_remote_ref() {
59+
local remote="$1"
60+
local ref="$2"
61+
local repo="$3"
62+
local pr_number="$4"
63+
local message="$5"
64+
65+
git show-ref "$remote"/"$ref"
66+
67+
local merge_exit_code
68+
git merge \
69+
"$remote"/"$ref" \
70+
--verbose \
71+
--no-edit \
72+
-m "$message" \
73+
|| merge_exit_code=$?
74+
75+
if [ "${merge_exit_code:-0}" != 0 ]; then
76+
echo "
77+
Failed to merge $ref into $repo#$pr_number after fetching its last $merge_ancestor_max_depth commits.
78+
79+
This problem can happen if:
80+
81+
- $repo#$pr_number has conflicts with master. To solve this problem you should merge master into the PR, solve the conflicts and push.
82+
83+
OR
84+
85+
- $repo#$pr_number is ahead of master by more than $merge_ancestor_max_depth commits. To solve this you can merge master into the branch locally and push.
86+
"
87+
exit $merge_exit_code
88+
fi
89+
}
90+
5591
our_crates=()
5692
discover_our_crates() {
5793
# workaround for early exits not being detected in command substitution
@@ -226,10 +262,6 @@ process_pr_description_line() {
226262

227263
companions+=("$repo")
228264

229-
# Heuristic: assume the companion PR has a common merge ancestor with master
230-
# in its last N commits.
231-
local merge_ancestor_max_depth=100
232-
233265
# Clone the default branch of this companion's target repository (assumed to
234266
# be named "master")
235267
git clone \
@@ -246,24 +278,12 @@ process_pr_description_line() {
246278
git fetch --depth=$merge_ancestor_max_depth origin "pull/$pr_number/head:$ref"
247279
git checkout "$ref"
248280

249-
echo "
250-
Attempting to merge $repo#$pr_number with master after fetching its last $merge_ancestor_max_depth commits.
251-
252-
If this step fails, either:
253-
254-
- $repo#$pr_number has conflicts with master
255-
256-
OR
257-
258-
- A common merge ancestor could not be found between master and the last $merge_ancestor_max_depth commits of $repo#$pr_number.
259-
260-
Both cases can be solved by merging master into $repo#$pr_number.
261-
"
262-
git show-ref origin/master
263-
git merge origin/master \
264-
--verbose \
265-
--no-edit \
266-
-m "Merge master of $repo into companion $repo#$pr_number"
281+
merge_remote_ref \
282+
origin \
283+
master \
284+
"$repo" \
285+
"$pr_number" \
286+
"Merge master of $repo into companion $repo#$pr_number"
267287

268288
popd >/dev/null
269289

@@ -457,7 +477,10 @@ patch_and_check_dependent() {
457477
}
458478

459479
main() {
460-
if ! [[ "$CI_COMMIT_REF_NAME" =~ ^[[:digit:]]+$ ]]; then
480+
local this_pr_number
481+
if [[ "$CI_COMMIT_REF_NAME" =~ ^[[:digit:]]+$ ]]; then
482+
this_pr_number="$CI_COMMIT_REF_NAME"
483+
else
461484
die "\"$CI_COMMIT_REF_NAME\" was not recognized as a pull request ref"
462485
fi
463486

@@ -469,7 +492,7 @@ main() {
469492
# process_pr_description calls itself for each companion in the description on
470493
# each detected companion PR, effectively considering all companion references
471494
# on all PRs
472-
process_pr_description "$this_repo" "$CI_COMMIT_REF_NAME"
495+
process_pr_description "$this_repo" "$this_pr_number"
473496

474497
# This PR might be targetting a custom ref (i.e. not master) through companion
475498
# overrides from --companion-overrides or the PR's description, in which case
@@ -618,12 +641,12 @@ main() {
618641
# the same has to be done for all the companions because they might have
619642
# accompanying changes for the code being brought in.
620643
git fetch --force origin master
621-
git show-ref origin/master
622-
echo "Merge master into $this_repo#$CI_COMMIT_REF_NAME"
623-
git merge origin/master \
624-
--verbose \
625-
--no-edit \
626-
-m "Merge master into $this_repo#$CI_COMMIT_REF_NAME"
644+
merge_remote_ref \
645+
origin \
646+
master \
647+
"$this_repo" \
648+
"$this_pr_number" \
649+
"Merge master into $this_repo#$this_pr_number"
627650
fi
628651

629652
discover_our_crates

0 commit comments

Comments
 (0)