¿Hay alguna manera de actualizar los contenidos de un file en un proyecto en su count de services del equipo visual studio usando verbos HTTP, de forma similar a como se hace aquí con github https://developer.github.com/v3/repos/contents/ # update-a-file .
var json={ "comment": "Update scripts.json", "changes": [{ "changeType": 2, "item": { "path": "$/ExtensionsTest/scripts.json", "contentMetadata": { "encoding": 65001 }, "version": 47 }, "newContent": { "content": "[ {\"hello\" : \"Test\"} ]", "contentType":"RawText" } }] }; $.ajax({ type: 'POST', url: 'https://xxxxx.visualstudio.com/_apis/tfvc/changesets?api-version=3.0-preview.2', contentType: 'application/json', data: JSON.stringify(json), cache: false, dataType: "json", beforeSend: function (xhr) { xhr.setRequestHeader("Authorization", "Basic " + btoa("my UserName" + ":" + "my PW")); } }).done(function (data) { console.log(data); }); };
El código anterior es el que estoy usando y me sale un error de 400. Cualquier sugerencia sobre lo que estoy haciendo mal.
Pruebe estas forms:
Si está usando GIT:
Datos JSON:
{ "refUpdates": [{ "name": "refs/heads/master", "oldObjectId": "[step 1 commit ID]" }], "commits": [{ "comment": "Updated BuildLog.cs", "changes": [{ "changeType": 2, "item": {"path": "/BuildLog.cs"}, "newContent": { "content": "using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { public class BuildLog { public int count; public string[] value6; } } ", "contentType": 0 } }] }] }
Si está usando TFVC:
Datos de Json:
{ "comment": "Updated Class1.cs", "changes": [{ "changeType": 2, "item": { "path": "$/Scrum2015/ClassLibraryB/ClassLibraryB/Class1.cs", "contentMetadata": {"encoding": 65001}, "version": [step changeset id] }, "newContent": { "content": "using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibraryB { public class Class1 { string sgs = \"\"; public void T() { ClassLibraryA.Class1 c = new ClassLibraryA.Class1(); c.TestOther2(); } } } ", "contentType": 0 } }] }
Nota: debe analizar las comillas si el contenido del file contiene comillas (\ "testing \"), al igual que otras cartas especiales.
Por otro lado, puede lograr eso a través de vso-node-api, más información, puede consultar este hilo: TFS Rest API check-in para Version Control
Actualización1:
Consulte este código para modificar su código:
var json={ "comment": "Updated tt.json", "changes": [{ "changeType": 2, "item": { "path": "$/Scrum2015/Buildtest/CoreSolutionDemo/WebApplication1/tt.json", "contentMetadata": { "encoding": 65001 }, "version": 754 }, "newContent": { "content": "[ {\"hello\" : \"Test2\"} ]", "contentType": "RawText" } }] }; $.ajax({ type: 'POST', url: 'https://XXX.visualstudio.com/_apis/tfvc/changesets?api-version=3.0-preview.2', contentType: 'application/json', data: JSON.stringify(json), cache: false, dataType: 'json', beforeSend: function (xhr) { xhr.setRequestHeader("Authorization", "Basic " + btoa("name" + ":" + "password or PAT")); }, }).done(function (data) { var s1 = "ss"; }).error(function (e) { var s = "ss"; }); })