TFS Rest API 签入版本控制

TFS Rest API check-in to Version Control

我需要能够从 VSTS 扩展签出、编辑和签入(本地 TFVC/TFS repo v2015.3)

在文档中 https://www.visualstudio.com/en-us/docs/integrate/api/tfvc/overview 不清楚是否有 APi 可以做到这一点

MSFT 为自己的 Web Access 实现了它 "Code" 编辑器使用:https://visualstudio.uservoice.com/forums/330519-team-services/suggestions/2216206-provide-check-in-check-out-functionality-through-t#{toggle_previous_statuses}

所以,有一种方法可以实现这一点。我曾尝试通过浏览器调试对他们的操作进行逆向工程,但 minified/bundled 代码不易阅读。

有人可以给我一个示例,说明如何在 JS/TypeScript 中根据 REST api 签入源代码控制项吗?谢谢!

没有其他 API(Microsoft 的 public/released)可以签入更改,例如编辑代码和在 Web 访问时签入更改(保存)。

我提交了一个用户声音here,你可以投票和追踪

找到了解决我自己问题的方法,现在将尝试: https://www.visualstudio.com/en-gb/docs/integrate/extensions/reference/client/api/tfs/versioncontrol/tfvcrestclient/tfvchttpclient2_2#method_createChangeset

使用 createChangeset() 方法供您参考的示例代码:

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