@@ -169,6 +169,8 @@ function clearPreviewMetadataEnvs() {
169169 vi . stubEnv ( "CI_COMMIT_SHA" , "" ) ;
170170 vi . stubEnv ( "CIRCLE_SHA1" , "" ) ;
171171 vi . stubEnv ( "COMMIT_SHA" , "" ) ;
172+ vi . stubEnv ( "CI_MERGE_REQUEST_TITLE" , "" ) ;
173+ vi . stubEnv ( "PULL_REQUEST_TITLE" , "" ) ;
172174}
173175
174176describe ( "wrangler preview" , ( ) => {
@@ -388,10 +390,12 @@ describe("wrangler preview", () => {
388390 "https://git.example.com/acme/worker-project/pulls/13"
389391 ) ;
390392 vi . stubEnv ( "PULL_REQUEST_NUMBER" , "13" ) ;
393+ vi . stubEnv ( "PULL_REQUEST_TITLE" , "Add a cool new feature" ) ;
391394
392395 expect ( getPullRequestMetadata ( ) ) . toEqual ( {
393396 number : "13" ,
394397 url : "https://git.example.com/acme/worker-project/pulls/13" ,
398+ title : "Add a cool new feature" ,
395399 } ) ;
396400 } ) ;
397401
@@ -402,11 +406,45 @@ describe("wrangler preview", () => {
402406 pull_request : {
403407 number : 13 ,
404408 html_url : "https://github.com/acme/worker-project/pull/13" ,
409+ title : "Add a cool new feature" ,
405410 } ,
406411 } )
407412 ) ;
408413 vi . stubEnv ( "GITHUB_EVENT_PATH" , "github-event.json" ) ;
409414
415+ expect ( getPullRequestMetadata ( ) ) . toEqual ( {
416+ number : "13" ,
417+ url : "https://github.com/acme/worker-project/pull/13" ,
418+ title : "Add a cool new feature" ,
419+ } ) ;
420+ } ) ;
421+
422+ test ( "should not fail when the GitHub event pull request has no title" , ( {
423+ expect,
424+ } ) => {
425+ writeFileSync (
426+ "github-event.json" ,
427+ JSON . stringify ( {
428+ pull_request : {
429+ number : 13 ,
430+ html_url : "https://github.com/acme/worker-project/pull/13" ,
431+ } ,
432+ } )
433+ ) ;
434+ vi . stubEnv ( "GITHUB_EVENT_PATH" , "github-event.json" ) ;
435+
436+ expect ( getPullRequestMetadata ( ) ) . toEqual ( {
437+ number : "13" ,
438+ url : "https://github.com/acme/worker-project/pull/13" ,
439+ } ) ;
440+ } ) ;
441+
442+ test ( "should not recover a title from the GITHUB_REF fallback" , ( {
443+ expect,
444+ } ) => {
445+ vi . stubEnv ( "GITHUB_REF" , "refs/pull/13/merge" ) ;
446+ vi . stubEnv ( "GITHUB_REPOSITORY" , "acme/worker-project" ) ;
447+
410448 expect ( getPullRequestMetadata ( ) ) . toEqual ( {
411449 number : "13" ,
412450 url : "https://github.com/acme/worker-project/pull/13" ,
@@ -419,6 +457,24 @@ describe("wrangler preview", () => {
419457 "https://gitlab.example.com/acme/worker-project"
420458 ) ;
421459 vi . stubEnv ( "CI_MERGE_REQUEST_IID" , "13" ) ;
460+ vi . stubEnv ( "CI_MERGE_REQUEST_TITLE" , "Add a cool new feature" ) ;
461+
462+ expect ( getPullRequestMetadata ( ) ) . toEqual ( {
463+ number : "13" ,
464+ url : "https://gitlab.example.com/acme/worker-project/-/merge_requests/13" ,
465+ title : "Add a cool new feature" ,
466+ } ) ;
467+ } ) ;
468+
469+ test ( "should treat a blank title the same as a missing one" , ( {
470+ expect,
471+ } ) => {
472+ vi . stubEnv (
473+ "CI_PROJECT_URL" ,
474+ "https://gitlab.example.com/acme/worker-project"
475+ ) ;
476+ vi . stubEnv ( "CI_MERGE_REQUEST_IID" , "13" ) ;
477+ vi . stubEnv ( "CI_MERGE_REQUEST_TITLE" , " " ) ;
422478
423479 expect ( getPullRequestMetadata ( ) ) . toEqual ( {
424480 number : "13" ,
@@ -4691,6 +4747,7 @@ describe("wrangler preview", () => {
46914747 "https://gitlab.example.com/acme/worker-project.git"
46924748 ) ;
46934749 vi . stubEnv ( "CI_MERGE_REQUEST_IID" , "13" ) ;
4750+ vi . stubEnv ( "CI_MERGE_REQUEST_TITLE" , "Add a cool new feature" ) ;
46944751 vi . stubEnv ( "CI_COMMIT_SHA" , "abc123def456" ) ;
46954752
46964753 let deploymentRequestBody :
@@ -4699,6 +4756,7 @@ describe("wrangler preview", () => {
46994756 "workers/commit_sha" ?: string ;
47004757 "workers/message" ?: string ;
47014758 "workers/pull_request_number" ?: string ;
4759+ "workers/pull_request_title" ?: string ;
47024760 "workers/pull_request_url" ?: string ;
47034761 "workers/repository_url" ?: string ;
47044762 "workers/tag" ?: string ;
@@ -4769,6 +4827,7 @@ describe("wrangler preview", () => {
47694827 "workers/commit_sha" : "abc123def456" ,
47704828 "workers/message" : "preview note" ,
47714829 "workers/pull_request_number" : "13" ,
4830+ "workers/pull_request_title" : "Add a cool new feature" ,
47724831 "workers/pull_request_url" :
47734832 "https://gitlab.example.com/acme/worker-project/-/merge_requests/13" ,
47744833 "workers/repository_url" :
@@ -4780,6 +4839,8 @@ describe("wrangler preview", () => {
47804839 "https://gitlab.example.com/acme/worker-project/-/merge_requests/13"
47814840 ) ;
47824841 expect ( std . out ) . not . toContain ( "repository_url" ) ;
4842+ expect ( std . out ) . not . toContain ( "pull_request_title" ) ;
4843+ expect ( std . out ) . not . toContain ( "Add a cool new feature" ) ;
47834844 } ) ;
47844845
47854846 test ( "should fall back to HEAD commit metadata for annotations in CI" , async ( {
0 commit comments