I have some files which needs to be changed programmatically and if there is the change detected. Then a branch needs to be created and then a PR for the manual approval.
I got stuck when I am trying to create the branch from the master branch. Even though if I just want to use the Initial commit (https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pushes/create?view=azure-devops-rest-5.1&tabs=HTTP#initial-commit-(create-a-new-branch)) and want to add the json file like this.
$params = '{
"refUpdates": [
{
"name": "refs/heads/feature/testBranchNish",
"oldObjectId": "0000000000000000000000000000000000000000"
}
],
"commits": [
{
"comment": "Initial commit.",
"changes": [
{
"changeType": "add",
"item": {
"path": "/setting.json"
},
"newContent": {
"content": "{"version":1}",
"contentType": "application/json"
}
}
]
}
]
}'
In the above Json, Here I need either one of the below two solutions but at this moment they both are not working.
First option: Because I need to update the json file So I should have to mention the contentType as "application/json" but it is giving the Newtonsoft.Json.JsonReaderException as mention below. Invoke-RestMethod : {"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred. Activity Id: 65512b93-8924-4e40-8bd8-ba975418d8bd.","typeName":"Newtonsoft.Json.JsonReaderException, Newtonsoft.Json" ,"typeKey":"JsonReaderException","errorCode":0,"eventId":0} At line:27 char:1
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Second Option: I don't want to provide the new content rather I would rather provide the file path something like this.
$params = '{
"refUpdates": [
{
"name": "refs/heads/feature/testBranchNish",
"oldObjectId": "0000000000000000000000000000000000000000"
}
],
"commits": [
{
"comment": "Initial commit.",
"changes": [
{
"changeType": "add",
"item": {
"path": "/setting.json"
},
"newContent": {
"path": "C:/Users/abc/setting.json",
"contentType": "application/json"
}
}
]
}
]
}'
But I don't find this option anywhere in the Microsoft documentation. So the first option is more relevant to me while seeing the MS documentation.
Please answer if you guys already have a solution of this problem.
Thanks in advance
