Skip to content

Commit

Permalink
Fix PRs without a head URL
Browse files Browse the repository at this point in the history
PRs miss a head ref when the underlying branch or repo has been deleted.
But we are already not relying on the head repo anymore but instead use
the "magical" refs containing the PR commits that GitHub automatically
creates in the base repo. Switch the last remnants of head-url over to
base-url and remove head-url completely.
  • Loading branch information
patrickbkr committed Apr 21, 2023
1 parent d640e23 commit f577910
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
1 change: 0 additions & 1 deletion lib/DB.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ model GitHubPR is rw is table<github_pr> {
has UInt $.number is column;
has DB::Project $.project is column;
has Str $.base-url is column;
has Str $.head-url is column;
has Str $.head-branch is column;
has Str $.user-url is column;
has DB::PRStatus $.status is column;
Expand Down
8 changes: 4 additions & 4 deletions lib/GitHubCITestRequester.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class PRTask {
has $.title is required;
has PRState $.state is required;
has $.base-url is required;
has $.head-url is required;
has $.head-branch is required;
has $.user-url is required;
has PRCommentTask @.comments;
Expand Down Expand Up @@ -88,7 +87,6 @@ method !process-pr-task(PRTask $pr) {
project => self!repo-to-db-project($pr.repo),
number => $pr.number,
base-url => $pr.base-url,
head-url => $pr.head-url,
head-branch => $pr.head-branch,
user-url => $pr.user-url,
status => DB::OPEN,
Expand Down Expand Up @@ -118,7 +116,7 @@ method !process-pr-commit-task(PRCommitTask $commit) {
DB::CITestSet.^create:
event-type => DB::PR,
:$project,
git-url => $pr.head-url,
git-url => $pr.base-url,
commit-sha => $commit.commit-sha,
user-url => $commit.user-url,
:$pr,
Expand Down Expand Up @@ -276,6 +274,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 @@ -333,7 +333,7 @@ method !determine-source-spec(:$project!, :$git-url!, :$commit-sha!, :$pr --> So
$rakudo-commit-sha, $nqp-commit-sha, $moar-commit-sha);
my $did-things = False;
with $pr {
my %head-data = self!github-url-to-project-repo($pr.head-url);
my %head-data = self!github-url-to-project-repo($pr.base-url);
if $project == DB::RAKUDO && %head-data<repo> eq config.projects.rakudo.repo ||
$project == DB::NQP && %head-data<repo> eq config.projects.nqp.repo ||
$project == DB::MOAR && %head-data<repo> eq config.projects.moar.repo {
Expand Down
2 changes: 0 additions & 2 deletions lib/GitHubInterface.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ method parse-hook-request($event, %json) {
if %json<action> eq 'synchronize'|'opened' {
$!processor.add-task: GitHubCITestRequester::PRTask.new(
repo => %json<pull_request><base><repo><name>,
head-url => %json<pull_request><head><repo><clone_url>,
base-url => %json<pull_request><base><repo><clone_url>,
head-branch => %json<pull_request><head><ref>,
number => %json<pull_request><number>,
Expand Down Expand Up @@ -284,7 +283,6 @@ method retrieve-pulls($project, $repo, :$last-cursor is copy) {
GitHubCITestRequester::PRTask.new:
:$repo,
base-url => %pull-data<baseRepository><url> ~ '.git',
head-url => %pull-data<headRepository><url> ~ '.git',
head-branch => %pull-data<headRefName>,
number => %pull-data<number>,
title => %pull-data<title>,
Expand Down

0 comments on commit f577910

Please sign in to comment.