0

我需要使用 Visual Studio Team Services Client for Node.js (vso-node-api) 创建 VSTS 工作项,请提供任何示例?

4

2 回答 2

5

我创建了一个简单的代码示例来获取和创建工作项供您参考,有关详细信息,请参阅以下部分:

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

import * as vm from 'vso-node-api/WebApi';
import * as wa from 'vso-node-api/WorkItemTrackingApi';
import * as wi from 'vso-node-api/interfaces/WorkItemTrackingInterfaces';
import * as vss from 'vso-node-api/interfaces/Common/VSSInterfaces';

var collectionUrl = "https://xxxxxx.visualstudio.com";

let token: string = "Yourpersonalaccesstoken";

let creds = vm.getPersonalAccessTokenHandler(token);

var connection = new vm.WebApi(collectionUrl, creds); 

let vstsWI: wa.IWorkItemTrackingApi = connection.getWorkItemTrackingApi();

async function getWI() {
    let wiid: number = 1;
    let workitem: wi.WorkItem = await vstsWI.getWorkItem(wiid);

    console.log(workitem.url);
}

getWI();

async function createWI() {
    let wijson: vss.JsonPatchDocument = [{ "op": "add", "path": "/fields/System.Title", "value": "Task created from Node JS" }];
    let project: string = "Project";
    let witype: string = "Task";
    let cWI: wi.WorkItem = await vstsWI.createWorkItem(null, wijson, project, witype);
    console.log(cWI.id);
}

createWI();
于 2016-09-22T09:18:20.147 回答
0

使用使用 vsts-task-lib 检索到的令牌

import tl = require('vsts-task-lib/task');
let auth = tl.getEndpointAuthorization("SYSTEMVSSCONNECTION", false);
var token = auth.parameters["AccessToken"];
于 2016-09-26T12:15:53.557 回答