I think you need to look thru all the scmGitReferences to find the branch one from previous run for your branch.
It looks like "canonicalName": "refs/heads/stage" for my branch stage.
{
"data": {
"type": "scmGitReferences",
"id": "6ce1ce69-c00b-46d1-8453-887f23b8JJHS",
"attributes": {
"name": "stage",
"canonicalName": "refs/heads/stage",
"isDeleted": false,
"kind": "BRANCH"
},
"links": {
"self": "https://api.appstoreconnect.apple.com/v1/scmGitReferences/6ce1ce69-c00b-46d1-8453-887f23b8JJHS"
}
},
"included": {}
}
This works for me
{
"sourceBranchOrTag": {
"data": {
"type": "scmGitReferences",
"id": "6ce1ce69-c00b-46d1-8453-887f23b8JJHS"
}
},
workflow: {
data: {
type: "ciWorkflows",
id: `${branch === 'stage' ? stageWorkflow : prodWorkflow}`
}
}
};
How did I get the IDs?
Start with your workflow:
const gitRef = await readAll('https://api.appstoreconnect.apple.com/v1/ciWorkflows/59D98329-2C36-4A9D-A657-B32EJUNK/relationships/repository');
console.log(JSON.stringify(gitRef, null, 2));
Then look at gitReferences:
const gitrepo = await readAll('https://api.appstoreconnect.apple.com/v1/scmRepositories/02604932-197a-48a0-b182-fa78f97JUNK/relationships/gitReferences');
console.log(JSON.stringify(gitrepo, null, 2));
then find the right one -- to see in detail:
const reference = await readAll('https://api.appstoreconnect.apple.com/v1/scmGitReferences/6ce1ce69-c00b-46d1-8453-887f23b8JJHS');
console.log(JSON.stringify(reference, null, 2));