[ad_1]
I try to create a Pull Request by the Azure DevOps Services REST API. I am using PAT which is working with getting WorkItems like:
#!/bin/bash
source ~/bin/variables.sh
id=${1}
url="$(organization)/$(project)/_apis/wit/workitems/${id}?api-version=7.1-preview.3"
workItem=$(curl -s -u $(presenter):$(PAT) -X GET "${url}")
- organization is our organization-url.
- project is the project name.
- presenter is the user.name (from az account show)
- PAT is the personal access token.
I created a Json like:
{
"sourceRefName": "refs/heads/U1367_My_Source_Branch",
"targetRefName": "refs/heads/F231_My_Target_Branch",
"title": "F231 Source bla foo. U1367 Target bla foo",
"description": "Bla foo WorkItem: #2117",
"isDraft": true
}
The Json is generated without newlines:
json='{"sourceRefName":"'${source}'","targetRefName":"'${target}'","title":"'${title}'","description":"'${description}'","isDraft":true}'
and send it with the following:
url="https://dev.azure.com/$(organizationName)/$(project)/_apis/git/repositories/${repo}/pullrequests?supportsIterations=true&api-version=7.1-preview.1"
response=$(curl -s -u $(presenter):$(PAT) -X POST -H "Content-Type: application/json" -d '${json}' "${url}")
- organizationName is our organization name 🙂
- repo is the id (Guid) of the repo
I get this response:
{
"$id": "1",
"innerException": null,
"message": "TF400898: An Internal Error Occurred. Activity Id: 169c9863-5441-40a6-8e8d-4c826faf8308.",
"typeName": "Newtonsoft.Json.JsonReaderException, Newtonsoft.Json",
"typeKey": "JsonReaderException",
"errorCode": 0,
"eventId": 0
}
I checked the permissions of the PAT. I have the permission to create pull requests.
Any suggestions to create a working pull request via the API by a shell script?
[ad_2]