0

从我的 TFS 扩展中,使用 TfvcHttpClient,我可以将文件签入到安装了扩展的同一个 TFS,但是如何签入到其他 TFS 的 tfvc?

import TFS_VC_TfvcRestClient = require("TFS/VersionControl/TfvcRestClient");
var tfvcApi = TFS_VC_TfvcRestClient.getClient();

我可以以某种方式告诉 getClient() 使用另一个 serverUrl 吗?

编辑:添加了更具体的签入代码

function checkinXML() {
    $(".vlc-tvc").hide();
    $(".vlc-button").hide();
    var changeset/*: TFS_VC_Contracts.TfvcChangeset*/ = {
        accountId: VSS.getWebContext().account.id,
        //author: {
        //    id: VSS.getWebContext().user.id,
        //    displayName: VSS.getWebContext().user.name,
        //    uniqueName: VSS.getWebContext().user.uniqueName,
        //    //url: how to get URL?
        //},
        //changesetId: currentChangeset ++?,
        //checkedInBy: {
        //    id: VSS.getWebContext().user.id,
        //    displayName: VSS.getWebContext().user.name,
        //    uniqueName: VSS.getWebContext().user.uniqueName
        //    //url: how to get URL?
        //},
        //checkinNotes: [],
        //collectionId: collectionID,
        //teamProjectIds: [projectID],
        //commentTruncated: false,
        //createdDate: null,
        //hasMoreChanges: false,
        policyOverride: {
            policyFailures: []
        },
        //url: how to get URL?
        //workItems: null,
        //_links: null,
        comment: VSS.getWebContext().user.name,
        changes: [
            {
                //mergeSources: [],
                //pendingVersion: {},
                changeType: TFS_VC_Contracts.VersionControlChangeType.Add,
                item: {
                    //changeDate: {},
                    //deletionId: {},
                    //hashValue: {},
                    isFolder: false,
                    isBranch: false,
                    isPendingChange: false,
                    //size: {},
                    //_links: {},
                    //version: {},
                    contentMetadata: {
                        contentType: "text/xml",
                        encoding: 65001
                        //    fileName: "D.USD.xml",
                        //    extension: ".xml"
                    },
                    path: sourceControlPath //+ "/" + projectName + ".xml"
                },
                newContent: {
                    content: newXML,
                    contentType: TFS_VC_Contracts.ItemContentType.RawText
                },
                //sourceServerItem: sourceControlPath + "/" + projectName + ".xml"
            }
        ]
    };
    statusindicatorObject.startWait();

    tfvcApi.getItem(changeset.changes[0].item.path).then(function (result) {
        changeset.changes[0].changeType = TFS_VC_Contracts.VersionControlChangeType.Edit;
        changeset.changes[0].item['version'] = result.version;
    }, function (error) {
        console.log(error);
    }).then(function () {
        tfvcApi.createChangeset(<any>changeset/*, projectName*/).then(function () {
            statusindicatorObject.endWait();
            var successCheckInDialog = VSS_Controls_Dialogs.show(VSS_Controls_Dialogs.ModalDialog, {
                title: "XML Check-In "  + sourceControlPath,
                content: $("<p/>").addClass("confirmation-text").html("Successfully checked-in XML to <b>" + sourceControlPath + "</br>."),
                useBowtieStyle: true,
                buttons: {
                    "OK": function () {
                        successCheckInDialog.close();
                        successCheckInDialog.dispose();
                    }
                }
            });
            $(".vlc-button").show();
            $(".vlc-tvc").show();
        }, function (error) {
            statusindicatorObject.endWait();
            var failureCheckInDialog = VSS_Controls_Dialogs.show(VSS_Controls_Dialogs.ModalDialog, {
                title: "XML Check-In " + sourceControlPath,
                content: $("<p/>").addClass("confirmation-text").html("Check-In failure: <b>" + error + "</b>!"),
                useBowtieStyle: true,
                buttons: {
                    "OK": function () {
                        failureCheckInDialog.close();
                        failureCheckInDialog.dispose();
                    }
                }
            });
            $(".vlc-button").show();
            $(".vlc-tvc").show();
        });
    });
}
4

1 回答 1

1

你不能。

该连接使用隐式身份验证令牌,该令牌仅对构建定义中指定的 TFVC 有效。

这意味着您必须显式获取第二个令牌,例如通过变量传递 PAT。此外,您不能将同一个工作区用于另一个 TFVC 映射,但您必须使用两个工作区(定义和使用一个工作区是一项垃圾工作)并复制文件。

于 2017-03-13T14:52:52.267 回答