本文整理汇总了TypeScript中vso-node-api/WebApi.WebApi.getCoreApi方法的典型用法代码示例。如果您正苦于以下问题:TypeScript WebApi.getCoreApi方法的具体用法?TypeScript WebApi.getCoreApi怎么用?TypeScript WebApi.getCoreApi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vso-node-api/WebApi.WebApi
的用法示例。
在下文中一共展示了WebApi.getCoreApi方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: main
async function main(): Promise<void> {
var feed = getProjectAndFeedIdFromInputParam("feed");
if(feed.projectId) {
throw new Error(tl.loc("UnsupportedProjectScopedFeeds"));
}
let feedId = feed.feedId;
let regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
let packageId = tl.getInput("definition");
if(!regexGuid.test(packageId)){
packageId = "Nuget_" + tl.getInput("definition");
}
let version = tl.getInput("version");
let downloadPath = tl.getInput("downloadPath");
let collectionUrl = tl.getVariable("System.TeamFoundationCollectionUri");
var accessToken = getAuthToken();
var credentialHandler = vsts.getBearerHandler(accessToken);
var vssConnection = new vsts.WebApi(collectionUrl, credentialHandler);
var coreApi = vssConnection.getCoreApi();
const retryLimitValue: string = tl.getVariable("VSTS_HTTP_RETRY");
const retryLimit: number = (!!retryLimitValue && !isNaN(parseInt(retryLimitValue))) ? parseInt(retryLimitValue) : 4;
tl.debug(`RetryLimit set to ${retryLimit}`);
await executeWithRetries("downloadPackage", () => downloadPackage(collectionUrl, accessToken, credentialHandler, feedId, packageId, version, downloadPath).catch((reason) => {
throw reason;
}), retryLimit);
}
示例2: getNuGetFeedRegistryUrl
export async function getNuGetFeedRegistryUrl(accessToken:string, feedId: string, nuGetVersion: VersionInfo): Promise<string>
{
const ApiVersion = "3.0-preview.1";
let PackagingAreaName: string = "nuget";
// If no version is received, V3 is assumed
let PackageAreaId: string = nuGetVersion && nuGetVersion.productVersion.a < 3 ? "5D6FC3B3-EF78-4342-9B6E-B3799C866CFA" : "9D3A4E8E-2F8F-4AE1-ABC2-B461A51CB3B3";
let credentialHandler = vsts.getBearerHandler(accessToken);
let collectionUrl = tl.getVariable("System.TeamFoundationCollectionUri");
// The second element contains the transformed packaging URL
let packagingCollectionUrl = (await locationHelpers.assumeNuGetUriPrefixes(collectionUrl))[1];
if (!packagingCollectionUrl)
{
packagingCollectionUrl = collectionUrl;
}
const overwritePackagingCollectionUrl = tl.getVariable("NuGet.OverwritePackagingCollectionUrl");
if (overwritePackagingCollectionUrl) {
tl.debug("Overwriting packaging collection URL");
packagingCollectionUrl = overwritePackagingCollectionUrl;
}
let vssConnection = new vsts.WebApi(packagingCollectionUrl, credentialHandler);
let coreApi = vssConnection.getCoreApi();
let data = await Retry(async () => {
return await coreApi.vsoClient.getVersioningData(ApiVersion, PackagingAreaName, PackageAreaId, { feedId: feedId });
}, 4, 100);
return data.requestUrl;
}
示例3: main
async function main(): Promise<void> {
let feedId = tl.getInput("feed");
let packageId = tl.getInput("definition");
let version = tl.getInput("version");
let downloadPath = tl.getInput("downloadPath");
let collectionUrl = tl.getVariable("System.TeamFoundationCollectionUri");
var accessToken = getAuthToken();
var credentialHandler = vsts.getBearerHandler(accessToken);
var vssConnection = new vsts.WebApi(collectionUrl, credentialHandler);
var coreApi = vssConnection.getCoreApi();
await downloadPackage(collectionUrl, credentialHandler, feedId, packageId, version, downloadPath);
}
示例4: getFeedRegistryUrl
export async function getFeedRegistryUrl(feedId: string): Promise<string> {
const apiVersion = '3.0-preview.1';
const area = 'npm';
const locationId = 'D9B75B07-F1D9-4A67-AAA6-A4D9E66B3352';
let accessToken = getSystemAccessToken();
let credentialHandler = vsts.getBearerHandler(accessToken);
let collectionUrl = await getPackagingCollectionUrl();
let vssConnection = new vsts.WebApi(collectionUrl, credentialHandler);
let coreApi = vssConnection.getCoreApi();
let data = await coreApi.vsoClient.getVersioningData(apiVersion, area, locationId, { feedId: feedId });
return data.requestUrl;
}
示例5: main
async function main(): Promise<void> {
let feedId = tl.getInput("feed");
let regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
let packageId = tl.getInput("definition");
if(!regexGuid.test(packageId)){
packageId = "Nuget_" + tl.getInput("definition");
}
let version = tl.getInput("version");
let downloadPath = tl.getInput("downloadPath");
let collectionUrl = tl.getVariable("System.TeamFoundationCollectionUri");
var accessToken = getAuthToken();
var credentialHandler = vsts.getBearerHandler(accessToken);
var vssConnection = new vsts.WebApi(collectionUrl, credentialHandler);
var coreApi = vssConnection.getCoreApi();
await downloadPackage(collectionUrl, accessToken, credentialHandler, feedId, packageId, version, downloadPath);
}
示例6: getServiceEndPoint
export function getServiceEndPoint(feedId: string, accessToken: string, area: string, locationId: string ): Q.Promise<string>{
var collectionUrl = tl.getVariable("System.TeamFoundationCollectionUri");
var oauth = vstsWebApi.getBearerHandler(accessToken);
var connection = new vstsWebApi.WebApi(collectionUrl, oauth);
var coreApi = connection.getCoreApi();
var serviceURL = '';
return coreApi.vsoClient.getVersioningData("3.0-preview.1", area, locationId, { feedId: feedId })
.then((versioningData) => {
tl._writeLine("Found " + area + " endpoint: " + versioningData.requestUrl);
return versioningData.requestUrl;
})
.fail(err => {
tl.error(tl.loc("CouldNotFindServiceEndpoint", area));
tl.error(err);
tl.exit(1);
return '';
})
}
示例7: downloadPackage
export async function downloadPackage(collectionUrl: string, credentialHandler: bearm.BearerCredentialHandler, feedId: string, packageId: string, version: string, downloadPath: string) {
var feedsUrl = collectionUrl.replace(".visualstudio.com",".feeds.visualstudio.com");
var feedConnection = new vsts.WebApi(feedsUrl, credentialHandler);
var packagesUrl = collectionUrl.replace(".visualstudio.com",".pkgs.visualstudio.com");
var packageConnection = new vsts.WebApi(packagesUrl, credentialHandler);
var packageUrl = await getNuGetPackageUrl(feedConnection.getCoreApi().vsoClient, feedId, packageId);
await new Promise((resolve, reject) => {
feedConnection.getCoreApi().restClient.get(packageUrl, ApiVersion, null, { responseIsCollection: false }, async function (error, status, result) {
if (!!error || status != 200) {
return reject(tl.loc("FailedToGetPackageMetadata", error));
}
var packageType = result.protocolType.toLowerCase();
var packageName = result.name;
if (packageType == "nuget") {
var getDownloadUrlPromise = getDownloadUrl(packageConnection.getCoreApi().vsoClient, feedId, packageName, version)
getDownloadUrlPromise.catch((error) => {
return reject(error)
});
var downloadUrl = await getDownloadUrlPromise;
if (!tl.exist(downloadPath)) {
tl.mkdirP(downloadPath);
}
var zipLocation = path.resolve(downloadPath, "../", packageName) + ".zip";
var unzipLocation = path.join(downloadPath, "");
console.log(tl.loc("StartingDownloadOfPackage", packageName, zipLocation));
var downloadNugetPackagePromise = downloadNugetPackage(packageConnection.getCoreApi(), downloadUrl, zipLocation);
downloadNugetPackagePromise.catch((error) => {
return reject(error)
});
await downloadNugetPackagePromise;
console.log(tl.loc("ExtractingNugetPackage", packageName, unzipLocation));
var unzipPromise = unzip(zipLocation, unzipLocation);
unzipPromise.catch((error) => {
return reject(error)
});
await unzipPromise;
if (tl.exist(zipLocation)) {
tl.rmRF(zipLocation, false);
}
return resolve();
}
else {
return reject(tl.loc("PackageTypeNotSupported"));
}
});
});
}