@@ -42,6 +42,12 @@ const refusedReviewer = {
4242 message : "Resource not accessible by integration" ,
4343 path : [ "repository" , "pullRequest" , "reviewRequests" , "nodes" , 0 , "requestedReviewer" ] ,
4444} ;
45+ // What GitHub answers for a pull request that has no `refs/pull/<number>/head`.
46+ const unresolvedPullRef = {
47+ type : "NOT_FOUND" ,
48+ message : "Could not resolve head ref 'refs/pull/7/head'." ,
49+ path : [ "repository" , "pullRequest" , "baseRef" , "compare" ] ,
50+ } ;
4551const pullRequestInput = { cwd : "/w" , repository : "acme/web" , host : "github.com" , number : 7 } ;
4652type PullRequestRead = (
4753 input : typeof pullRequestInput ,
@@ -2550,6 +2556,23 @@ layer("GitHubPullRequestApi.layer", (it) => {
25502556 } ) ,
25512557 ) ;
25522558
2559+ it . effect . each ( [
2560+ { action : "merge" , mutation : "mergePullRequest(" } ,
2561+ { action : "update-branch" , mutation : "updatePullRequestBranch(" } ,
2562+ ] as const ) ( "runs $action on a pull request GitHub has no pull ref for" , ( { action, mutation } ) =>
2563+ Effect . gen ( function * ( ) {
2564+ route ( [
2565+ "query PullRequestActionState" ,
2566+ { ...actionState ( { baseRef : { compare : null } } ) , errors : [ unresolvedPullRef ] } ,
2567+ ] ) ;
2568+ const cli = yield * GitHubPullRequestApi . GitHubPullRequestApi ;
2569+
2570+ yield * cli . runPullRequestAction ( { ...pullRequestInput , action } ) ;
2571+
2572+ expect ( variablesOf ( mutation ) ) . toHaveLength ( 1 ) ;
2573+ } ) ,
2574+ ) ;
2575+
25532576 it . effect ( "merges at once when auto-merge is asked of a pull request that is ready now" , ( ) =>
25542577 Effect . gen ( function * ( ) {
25552578 route ( [ "query PullRequestActionState" , actionState ( { mergeStateStatus : "CLEAN" } ) ] ) ;
@@ -3461,7 +3484,12 @@ layer("GitHubPullRequestApi.layer", (it) => {
34613484 } ) . pipe ( Effect . asVoid , Effect . flip ) ;
34623485 expect ( error . _tag ) . toBe ( tag ?? "GitHubApiResponseError" ) ;
34633486 if ( error . _tag === "GitHubApiResponseError" )
3464- expect ( error ) . toMatchObject ( { status, githubErrors : errors . map ( ( e ) => e . message ) } ) ;
3487+ expect ( error ) . toMatchObject ( {
3488+ status,
3489+ githubErrors : errors . map ( ( e ) =>
3490+ "path" in e ? `${ e . message } (at ${ e . path . join ( "." ) } )` : e . message ,
3491+ ) ,
3492+ } ) ;
34653493 expect ( mockedExecute ) . toHaveBeenCalledTimes ( index + 1 ) ;
34663494 }
34673495 } ) ,
@@ -3577,6 +3605,91 @@ layer("GitHubPullRequestApi.layer", (it) => {
35773605 } ) ,
35783606 ) ;
35793607
3608+ const unresolvedCore = {
3609+ ...coreResponse ( { baseRef : { compare : null } } ) ,
3610+ errors : [ unresolvedPullRef ] ,
3611+ } ;
3612+ it . effect . each ( [
3613+ { description : "alone" , answers : [ unresolvedCore ] , requestedReviewers : [ 100 ] } ,
3614+ {
3615+ description : "beside a refused reviewer" ,
3616+ answers : [
3617+ { ...unresolvedCore , errors : [ unresolvedPullRef , refusedReviewer ] } ,
3618+ unresolvedCore ,
3619+ ] ,
3620+ requestedReviewers : [ 100 , 0 ] ,
3621+ } ,
3622+ ] ) (
3623+ "reads a pull request without a pull ref, its comparison unknown ($description)" ,
3624+ ( { answers, requestedReviewers } ) =>
3625+ Effect . gen ( function * ( ) {
3626+ for ( const answer of answers )
3627+ mockedExecute . mockReturnValueOnce ( Effect . succeed ( output ( encodeJson ( answer ) ) ) ) ;
3628+ const cli = yield * GitHubPullRequestApi . GitHubPullRequestApi ;
3629+ const detail = yield * cli . getPullRequestDetail ( pullRequestInput ) ;
3630+ expect ( detail . number ) . toBe ( 7 ) ;
3631+ expect ( detail . comparison ) . toBeNull ( ) ;
3632+ expect ( variablesOf ( "PullRequestCore" ) . map ( ( v ) => v [ "requestedReviewers" ] ) ) . toEqual (
3633+ requestedReviewers ,
3634+ ) ;
3635+ } ) ,
3636+ ) ;
3637+
3638+ it . effect ( "fails a missing pull ref beside another error, in GitHub's words" , ( ) =>
3639+ Effect . gen ( function * ( ) {
3640+ const refusedChecks = {
3641+ type : "FORBIDDEN" ,
3642+ message : "Resource not accessible by integration" ,
3643+ path : [ "repository" , "pullRequest" , "commits" , "nodes" , 0 , "commit" , "statusCheckRollup" ] ,
3644+ } ;
3645+ mockedExecute . mockReturnValueOnce (
3646+ Effect . succeed (
3647+ output ( encodeJson ( { ...unresolvedCore , errors : [ unresolvedPullRef , refusedChecks ] } ) ) ,
3648+ ) ,
3649+ ) ;
3650+ const cli = yield * GitHubPullRequestApi . GitHubPullRequestApi ;
3651+ const error = yield * Effect . flip ( cli . getPullRequestDetail ( pullRequestInput ) ) ;
3652+ expect ( error ) . toMatchObject ( {
3653+ _tag : "GitHubApiResponseError" ,
3654+ status : 200 ,
3655+ githubErrors : [
3656+ "Could not resolve head ref 'refs/pull/7/head'. (at repository.pullRequest.baseRef.compare)" ,
3657+ "Resource not accessible by integration (at repository.pullRequest.commits.nodes.0.commit.statusCheckRollup)" ,
3658+ ] ,
3659+ } ) ;
3660+ } ) ,
3661+ ) ;
3662+
3663+ it . effect ( "still reads a pull request GitHub cannot find as missing, in GitHub's words" , ( ) =>
3664+ Effect . gen ( function * ( ) {
3665+ const { data } = coreResponse ( ) ;
3666+ mockedExecute . mockReturnValueOnce (
3667+ Effect . succeed (
3668+ output (
3669+ encodeJson ( {
3670+ data : { repository : { ...data . repository , pullRequest : null } } ,
3671+ errors : [
3672+ {
3673+ type : "NOT_FOUND" ,
3674+ message : "Could not resolve to a PullRequest with the number of 7." ,
3675+ path : [ "repository" , "pullRequest" ] ,
3676+ } ,
3677+ ] ,
3678+ } ) ,
3679+ ) ,
3680+ ) ,
3681+ ) ;
3682+ const cli = yield * GitHubPullRequestApi . GitHubPullRequestApi ;
3683+ const error = yield * Effect . flip ( cli . getPullRequestDetail ( pullRequestInput ) ) ;
3684+ expect ( error ) . toMatchObject ( {
3685+ _tag : "GitHubApiNotFoundError" ,
3686+ githubErrors : [
3687+ "Could not resolve to a PullRequest with the number of 7. (at repository.pullRequest)" ,
3688+ ] ,
3689+ } ) ;
3690+ } ) ,
3691+ ) ;
3692+
35803693 it . effect . each ( [ false , true ] ) (
35813694 "continues after the core check page without reading it twice (reviewer refusal: %s)" ,
35823695 ( refused ) =>
0 commit comments