UNPKG

azure-devops-api

Version:

azure devops api for automating add the workitem

72 lines (71 loc) 3.07 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createWorkItem = void 0; const azdev = require("azure-devops-node-api"); function createWorkItem(token, orgName, project, workItemInfo) { return __awaiter(this, void 0, void 0, function* () { const wiClient = yield getWiClient(token, orgName); const patchDoc = [ { op: 'add', path: '/fields/System.Title', value: workItemInfo.title }, { op: 'add', path: '/fields/System.Description', value: workItemInfo.description } ]; if (workItemInfo.areaPath !== '') { patchDoc.push({ op: 'add', path: '/fields/System.AreaPath', value: workItemInfo.areaPath }); } if (workItemInfo.iterationPath !== '') { patchDoc.push({ op: 'add', path: '/fields/System.IterationPath', value: workItemInfo.iterationPath }); } if (workItemInfo.assignedto !== '') { patchDoc.push({ op: 'add', path: '/fields/System.AssignedTo', value: workItemInfo.assignedto }); } if (workItemInfo.parentLink !== '') { patchDoc.push({ op: 'add', path: "/relations/-", value: { rel: "System.LinkTypes.Hierarchy-Reverse", url: workItemInfo.parentLink } }); } const workItem = yield wiClient.createWorkItem(null, patchDoc, project, workItemInfo.type); if ((workItem === null || workItem === void 0 ? void 0 : workItem.id) === undefined) { throw new Error('Work item was not created'); } return workItem.id; }); } exports.createWorkItem = createWorkItem; function getWiClient(token, orgName) { return __awaiter(this, void 0, void 0, function* () { const orgUrl = `https://dev.azure.com/${orgName}`; const authHandler = azdev.getPersonalAccessTokenHandler(token); const connection = new azdev.WebApi(orgUrl, authHandler); return connection.getWorkItemTrackingApi(); }); }