如何使用 Visual Studio Team Services Client for Node.js (vso-node-api) 创建工作项?

How to create work items using Visual Studio Team Services Client for Node.js (vso-node-api)?

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

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

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

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

import tl = require('vsts-task-lib/task');
let auth = tl.getEndpointAuthorization("SYSTEMVSSCONNECTION", false);
var token = auth.parameters["AccessToken"];