简体   繁体   中英

TFS Rest API check-in to Version Control

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!

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();

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM