1

From a VSTS extension I need to be able to check-out, edit, and check-in (on-prem TFVC/TFS repo v2015.3)

In the documentation https://www.visualstudio.com/en-us/docs/integrate/api/tfvc/overview it is not clear if there is an APi to do that

MSFT implemented it for their own Web Access "Code" Editor use: https://visualstudio.uservoice.com/forums/330519-team-services/suggestions/2216206-provide-check-in-check-out-functionality-through-t#{toggle_previous_statuses}

So, there is a way to achieve this. I`ve tried to reverse engineer how they did it per Browser Debugging, but the minified/bundled code is not easy to read.

Can somebody please just give me an example on how to do the check-in of source-controlled items per REST api in JS/TypeScript? Thanks!

Community
  • 1
  • 1
Ferdi Öztürk
  • 101
  • 1
  • 10
  • Is there a reason you need to use the REST API instead of the Client Object Model? I cannot see the API documented, which means even if someone did figure it out, it is liable to break in the future. – DaveShaw Oct 29 '16 at 21:51
  • Plan is to implement full functionality as self-contained VSTS extension, because I don`t want any dependencies to client VS installations, no deployment of any .NET/COM builds to the client, no redirects to my own web servers, etc. I just want to run everything in the browser (TFS web access hub page) client-side. Anyway, is there a way to access local COM from the browser code execution? Or is the sandbox blocking – Ferdi Öztürk Oct 30 '16 at 10:37

3 Answers3

3

A sample code for your reference with createChangeset() method:

/// <reference path="typings/index.d.ts" />

import * as vm from 'vso-node-api/WebApi';
import * as vss from 'vso-node-api/interfaces/Common/VSSInterfaces';
import * as tfv from 'vso-node-api/TFVCApi'
import * as tfi from 'vso-node-api/interfaces/TFVCInterfaces';

var collectionUrl = "https://xxxxxx.visualstudio.com";
let token: string = "xxxxxx";
let creds = vm.getPersonalAccessTokenHandler(token);
var connection = new vm.WebApi(collectionUrl, creds); 
let vstsTF: tfv.ITfvcApi = connection.getTfvcApi();

async function createCS(){
    var csdata = {
            comment: "test",
            changes: [
                {
                    changeType: tfi.VersionControlChangeType.Add,
                    item: {
                        path: "$/TFVCBranches/Test/3.txt",
                        contentMetadata: { encoding: 65001 },
                    },
                    newContent: {
                        content: "Placeholder file for new folder",
                        contentType: tfi.ItemContentType.RawText
                    }
                }]
        };
    (<any>vstsTF).createChangeset(csdata);

}

createCS();
Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
  • Eddie, If I change the VersionControlChangeType to ".Edit" I have trouble to check-in. It seems Add works fine, but TfvcChangeset is missing some attributes I would have to pass along, but I couldn`t yet identify which attributes are missing. Could you please check and show an example for "Edit" type checkins also? THXs – Ferdi Öztürk Dec 02 '16 at 10:42
  • @FerdiÖztürk You need to specify the "version" property in "item" to point to the latest version of the item you'd like to edit. – Eddie Chen - MSFT Dec 05 '16 at 03:00
0

There isn’t the Rest API (public/released by microsoft) that can check-in changes like edit code and check-in changes (save) on web access.

I submitted a user voice here, you can vote and track it.

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53