@@ -24,8 +24,12 @@ function pullRequest(overrides: Record<string, unknown> = {}): Record<string, un
2424 created_on : "2026-06-16T05:04:32.258456+00:00" ,
2525 updated_on : "2026-06-16T05:04:33.750542+00:00" ,
2626 author : { display_name : "Bilal Hassan" , nickname : "bilal" , type : "user" } ,
27- source : { branch : { name : "feat/page" } , repository : { full_name : "fork/web" } } ,
28- destination : { branch : { name : "master" } } ,
27+ source : {
28+ branch : { name : "feat/page" } ,
29+ commit : { hash : "9f3a7c2d8b1e6f045a9c3d7e2b8f1a6c0d4e5f93" , type : "commit" } ,
30+ repository : { full_name : "fork/web" } ,
31+ } ,
32+ destination : { branch : { name : "master" } , commit : { hash : "base-commit" } } ,
2933 links : { html : { href : "https://bitbucket.org/acme/web/pull-requests/897" } } ,
3034 ...overrides ,
3135 } ;
@@ -52,6 +56,7 @@ describe("decodePullRequestPageJson", () => {
5256 url : "https://bitbucket.org/acme/web/pull-requests/897" ,
5357 author : { login : "bilal" , name : "Bilal Hassan" } ,
5458 headBranch : "feat/page" ,
59+ headSha : "9f3a7c2d8b1e6f045a9c3d7e2b8f1a6c0d4e5f93" ,
5560 headRepositoryNameWithOwner : "fork/web" ,
5661 baseBranch : "master" ,
5762 state : "open" ,
@@ -106,6 +111,27 @@ describe("decodePullRequestPageJson", () => {
106111} ) ;
107112
108113describe ( "decodePullRequestJson" , ( ) => {
114+ it ( "preserves the source commit hash as the head SHA" , ( ) => {
115+ const decoded = expectSuccess ( decodePullRequestJson ( JSON . stringify ( pullRequest ( ) ) ) ) ;
116+
117+ expect ( decoded ) . toMatchObject ( { headSha : "9f3a7c2d8b1e6f045a9c3d7e2b8f1a6c0d4e5f93" } ) ;
118+ } ) ;
119+
120+ it . each ( [
121+ { metadata : "absent commit" , commit : undefined } ,
122+ { metadata : "null commit" , commit : null } ,
123+ { metadata : "absent hash" , commit : { } } ,
124+ { metadata : "null hash" , commit : { hash : null } } ,
125+ ] ) ( "reads detail and list payloads with $metadata" , ( { commit } ) => {
126+ const raw = pullRequest ( { source : { branch : { name : "feat/page" } , commit } } ) ;
127+ const detail = expectSuccess ( decodePullRequestJson ( JSON . stringify ( raw ) ) ) ;
128+ const list = expectSuccess ( decodePullRequestPageJson ( page ( [ raw ] ) ) ) ;
129+
130+ expect ( detail ) . toMatchObject ( { number : 897 , headBranch : "feat/page" , headSha : null } ) ;
131+ expect ( list . items ) . toHaveLength ( 1 ) ;
132+ expect ( list . items [ 0 ] ) . toMatchObject ( { number : 897 , headBranch : "feat/page" , headSha : null } ) ;
133+ } ) ;
134+
109135 it ( "reads reviewers as review requests" , ( ) => {
110136 const decoded = expectSuccess (
111137 decodePullRequestJson (
0 commit comments