Skip to content

Commit

Permalink
Fix fetching PRs with deleted head refs
Browse files Browse the repository at this point in the history
Do this by using GitHubs "secret" PR refs in the base repo.
  • Loading branch information
patrickbkr committed Oct 26, 2023
1 parent 7516714 commit 980540c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 23 deletions.
12 changes: 12 additions & 0 deletions lib/DB.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ class SourceSpec {

has Str $.rakudo-git-url = config.projects.rakudo.repo-url;
has SHA1 $.rakudo-commit-sha = 'LATEST';
has Str $.rakudo-fetch-ref;
has Str $.nqp-git-url = config.projects.nqp.repo-url;
has SHA1 $.nqp-commit-sha = 'LATEST';
has Str $.nqp-fetch-ref;
has Str $.moar-git-url = config.projects.moar.repo-url;
has SHA1 $.moar-commit-sha = 'LATEST';
has Str $.moar-fetch-ref;

submethod TWEAK() {
$!rakudo-commit-sha .= uc;
Expand Down Expand Up @@ -157,10 +160,13 @@ model CITestSet is rw is table<citest_set> {

has Str $!rakudo-git-url is column{ :nullable };
has Str $!rakudo-commit-sha is column{ :nullable };
has Str $!rakudo-fetch-ref is column{ :nullable };
has Str $!nqp-git-url is column{ :nullable };
has Str $!nqp-commit-sha is column{ :nullable };
has Str $!nqp-fetch-ref is column{ :nullable };
has Str $!moar-git-url is column{ :nullable };
has Str $!moar-commit-sha is column{ :nullable };
has Str $!moar-fetch-ref is column{ :nullable };

has Str $.source-archive-id is column{ :nullable, :type<text> };
has UInt $.source-retrieval-retries is column = 0;
Expand All @@ -173,19 +179,25 @@ model CITestSet is rw is table<citest_set> {
multi method source-spec($spec) {
$!rakudo-git-url = $spec.rakudo-git-url;
$!rakudo-commit-sha = $spec.rakudo-commit-sha;
$!rakudo-fetch-ref = $spec.rakudo-fetch-ref;
$!nqp-git-url = $spec.nqp-git-url;
$!nqp-commit-sha = $spec.nqp-commit-sha;
$!nqp-fetch-ref = $spec.nqp-fetch-ref;
$!moar-git-url = $spec.moar-git-url;
$!moar-commit-sha = $spec.moar-commit-sha;
$!moar-fetch-ref = $spec.moar-fetch-ref;
}
multi method source-spec() {
SourceSpec.new(
rakudo-git-url => $!rakudo-git-url // "",
rakudo-commit-sha => $!rakudo-commit-sha // "",
rakudo-fetch-ref => $!rakudo-fetch-ref // "",
nqp-git-url => $!nqp-git-url // "",
nqp-commit-sha => $!nqp-commit-sha // "",
nqp-fetch-ref => $!nqp-fetch-ref // "",
moar-git-url => $!moar-git-url // "",
moar-commit-sha => $!moar-commit-sha // "",
moar-fetch-ref => $!moar-fetch-ref // "",
)
}
}
Expand Down
62 changes: 45 additions & 17 deletions lib/GitHubCITestRequester.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ method process-worklist() is serial-dedup {
# NOT the head (the repo where the new commits are).
# Using the head repo will not work, as that's usually a different repo where the RCB is
# not installed on and thus has no permissons to add check_runs.
# In addition it's possible there is no head repo. That is the case when the branch or repo a
# PR is based on has been deleted.
# One would think using the base repo can't work, because the commits are not part of that
# repository. But there is some almost completely undocumented behavior in GitHub that copies
# PR commits to the base repo and even creates merge commits (without the PR being merged!).
Expand Down Expand Up @@ -330,7 +332,8 @@ method process-worklist() is serial-dedup {

method !determine-source-spec(:$project!, :$git-url!, :$commit-sha!, :$pr --> SourceSpec) {
my ($rakudo-git-url, $nqp-git-url, $moar-git-url,
$rakudo-commit-sha, $nqp-commit-sha, $moar-commit-sha);
$rakudo-commit-sha, $nqp-commit-sha, $moar-commit-sha,
$rakudo-fetch-ref, $nqp-fetch-ref, $moar-fetch-ref);
my $did-things = False;
with $pr {
my %head-data = self!github-url-to-project-repo($pr.head-url);
Expand All @@ -354,13 +357,14 @@ method !determine-source-spec(:$project!, :$git-url!, :$commit-sha!, :$pr --> So

my $branch = $pr.head-branch;

for DB::RAKUDO, $rakudo-git-url, $rakudo-commit-sha, $r-proj, $r-repo,
DB::NQP, $nqp-git-url, $nqp-commit-sha, $n-proj, $n-repo,
DB::MOAR, $moar-git-url, $moar-commit-sha, $m-proj, $m-repo
-> $cur-proj, $out-url is rw, $out-commit-sha is rw, $gh-project, $repo {
for DB::RAKUDO, $rakudo-git-url, $rakudo-commit-sha, $rakudo-fetch-ref, $r-proj, $r-repo,
DB::NQP, $nqp-git-url, $nqp-commit-sha, $nqp-fetch-ref, $n-proj, $n-repo,
DB::MOAR, $moar-git-url, $moar-commit-sha, $moar-fetch-ref, $m-proj, $m-repo
-> $cur-proj, $out-url is rw, $out-commit-sha is rw, $out-fetch-ref is rw, $gh-project, $repo {
if $cur-proj == $project {
$out-url = $git-url;
$out-url = $pr.base-url;
$out-commit-sha = $commit-sha;
$out-fetch-ref = "pull/{$pr.number}/head";
}
else {
my $branch-data = $!github-interface.get-branch(:owner($gh-project), :$repo, :$branch);
Expand All @@ -381,29 +385,53 @@ method !determine-source-spec(:$project!, :$git-url!, :$commit-sha!, :$pr --> So
}
}
if !$did-things {
given $project {
when DB::RAKUDO {
$rakudo-git-url = $git-url;
$rakudo-commit-sha = $commit-sha;
}
when DB::NQP {
$nqp-git-url = $git-url;
$nqp-commit-sha = $commit-sha;
with $pr {
given $project {
when DB::RAKUDO {
$rakudo-git-url = $pr.base-url;
$rakudo-commit-sha = $commit-sha;
$rakudo-fetch-ref = "pull/{$pr.number}/head";
}
when DB::NQP {
$nqp-git-url = $pr.base-url;
$nqp-commit-sha = $commit-sha;
$nqp-fetch-ref = "pull/{$pr.number}/head";
}
when DB::MOAR {
$moar-git-url = $pr.base-url;
$moar-commit-sha = $commit-sha;
$moar-fetch-ref = "pull/{$pr.number}/head";
}
}
when DB::MOAR {
$moar-git-url = $git-url;
$moar-commit-sha = $commit-sha;
}
else {
given $project {
when DB::RAKUDO {
$rakudo-git-url = $git-url;
$rakudo-commit-sha = $commit-sha;
}
when DB::NQP {
$nqp-git-url = $git-url;
$nqp-commit-sha = $commit-sha;
}
when DB::MOAR {
$moar-git-url = $git-url;
$moar-commit-sha = $commit-sha;
}
}
}
}

return SourceSpec.new:
|($rakudo-git-url ?? :$rakudo-git-url !! ()),
|($rakudo-commit-sha ?? :$rakudo-commit-sha !! ()),
|($rakudo-fetch-ref ?? :$rakudo-fetch-ref !! ()),
|($nqp-git-url ?? :$nqp-git-url !! ()),
|($nqp-commit-sha ?? :$nqp-commit-sha !! ()),
|($nqp-fetch-ref ?? :$nqp-fetch-ref !! ()),
|($moar-git-url ?? :$moar-git-url !! ()),
|($moar-commit-sha ?? :$moar-commit-sha !! ()),
|($moar-fetch-ref ?? :$moar-fetch-ref !! ()),
}

method !github-url-to-project-repo($url) {
Expand Down
11 changes: 5 additions & 6 deletions lib/SourceArchiveCreator.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ method create-archive(DB::CITestSet $test-set) {
}

my @shas;
for $!rakudo-dir, $source-spec.rakudo-git-url, $source-spec.rakudo-commit-sha, config.projects.rakudo.main,
$!nqp-dir, $source-spec.nqp-git-url, $source-spec.nqp-commit-sha, config.projects.nqp.main,
$!moar-dir, $source-spec.moar-git-url, $source-spec.moar-commit-sha, config.projects.moar.main
-> $repo-dir, $remote, $commit, $main {
for $!rakudo-dir, $source-spec.rakudo-git-url, $source-spec.rakudo-commit-sha, $source-spec.rakudo-fetch-ref, config.projects.rakudo.main,
$!nqp-dir, $source-spec.nqp-git-url, $source-spec.nqp-commit-sha, $source-spec.nqp-fetch-ref, config.projects.nqp.main,
$!moar-dir, $source-spec.moar-git-url, $source-spec.moar-commit-sha, $source-spec.moar-fetch-ref, config.projects.moar.main
-> $repo-dir, $remote, $commit, $fetch-ref, $main {
debug "SourceArchiveCreator: working on " ~ $remote ~ " " ~ $commit;
my $tmp-branch = 'tmp-branch';

Expand All @@ -121,8 +121,7 @@ method create-archive(DB::CITestSet $test-set) {
validate run qw|git remote add|, $tmp-branch, $remote,
:cwd($repo-dir), :merge;

#validate run qw|git fetch|, $tmp-branch, |($.fetch-ref ?? ("+refs/" ~ $.fetch-ref ~ ":refs/remotes/" ~ $.fetch-ref,) !! ()),
validate run qw|git fetch|, $tmp-branch,
validate run qw|git fetch|, $tmp-branch, |($fetch-ref ?? ("+refs/" ~ $fetch-ref ~ ":refs/remotes/" ~ $fetch-ref,) !! ()),
:cwd($repo-dir), :merge;

my $ref = $commit eq 'LATEST' ?? "$tmp-branch/$main" !! $commit;
Expand Down

0 comments on commit 980540c

Please sign in to comment.