Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
override.json
package-lock.json
VSIXPackageVersion.json
LICENSE
LICENSE

!Build
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/*
* ---------------------------------------------------------
* Copyright(C) Microsoft Corporation. All rights reserved.
* ---------------------------------------------------------
*/

import * as TfsCore from "../Core/Core";

/**
* Represents an attachment to a build.
*/
export interface Attachment {
_links: any;
/**
* The name of the attachment.
*/
name: string;
}

/**
* Data representation of a build.
*/
export interface Build {
/**
* The ID of the build.
*/
id: number;

project: TfsCore.TeamProjectReference;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* ---------------------------------------------------------
* Copyright(C) Microsoft Corporation. All rights reserved.
* ---------------------------------------------------------
*/

import { IVssRestClientOptions } from "../Common/Context";
import { RestClientBase } from "../Common/RestClientBase";

import * as Build from "./Build";

export class BuildRestClient extends RestClientBase {
constructor(options: IVssRestClientOptions) {
super(options);
}

public static readonly RESOURCE_AREA_ID = "965220d5-5bb9-42cf-8d67-9b146df2a5a4";

/**
* Gets the list of attachments of a specific type that are associated with a build.
*
* @param project - Project ID or project name
* @param buildId - The ID of the build.
* @param type - The type of attachment.
*/
public async getAttachments(
project: string,
buildId: number,
type: string
): Promise<Build.Attachment[]> {

return this.beginRequest<Build.Attachment[]>({
apiVersion: "7.2-preview.2",
routeTemplate: "{project}/_apis/build/builds/{buildId}/attachments/{type}",
routeValues: {
project: project,
buildId: buildId,
type: type
}
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./Build";
export * from "./BuildClient";
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import { getAccessToken, getService } from "azure-devops-extension-sdk";
import { IVssRestClientOptions } from "./Context";
import { CommonServiceIds, ILocationService } from "./CommonServices";

/**
* A REST client factory is the method used to create and initialize an IVssRestClient.
*/
export type RestClientFactory<T> = {
new (options: IVssRestClientOptions): T;
RESOURCE_AREA_ID?: string;
}

export function getClient<T>(clientClass: RestClientFactory<T>, clientOptions?: IVssRestClientOptions) {

const options = clientOptions || {};

if (!options.rootPath) {
options.rootPath = getService<ILocationService>(CommonServiceIds.LocationService).then(locationService => {
if (clientClass.RESOURCE_AREA_ID) {
return locationService.getResourceAreaLocation(clientClass.RESOURCE_AREA_ID);
}
else {
return locationService.getServiceLocation();
}
});
}

if (!options.authTokenProvider) {
options.authTokenProvider = {
getAuthorizationHeader: (): Promise<string> => {
return getAccessToken().then(token => token ? ("Bearer " + token) : "");
}
};
}

return new clientClass(options);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

/**
* Contribution ids of core DevOps services which can be obtained from DevOps.getService
*/
export const enum CommonServiceIds {

/**
* Service for getting URLs/locations from the host context
*/
LocationService = "ms.vss-features.location-service",

}

/**
* Host level for a VSS service
*/
export const enum TeamFoundationHostType {
/**
* The Deployment host
*/
Deployment = 1,

/**
* The Enterprise host
*/
Enterprise = 2,

/**
* The organization/project collection host
*/
Organization = 4
}

/**
* Service for external content to get locations
*/
export interface ILocationService {

/**
* Gets the URL for the given REST resource area
*
* @param resourceAreaId - Id of the resource area
*/
getResourceAreaLocation(resourceAreaId: string): Promise<string>;

/**
* Gets the location of a remote service at a given host type.
*
* @param serviceInstanceType - The GUID of the service instance type to lookup
* @param hostType - The host type to lookup (defaults to the host type of the current page data)
*/
getServiceLocation(serviceInstanceType?: string, hostType?: TeamFoundationHostType): Promise<string>;

/**
* Attemps to create a url for the specified route template and paramaters. The url will include host path.
* For example, if the page url is https://dev.azure.com/foo and you try to create admin settings url for project "bar",
* the output will be /foo/bar/_admin.
*
* This will asynchronously fetch a route contribution if it has not been included in page data.
*
* @param routeId - Id of the route contribution
* @param routeValues - Route value replacements
* @param hostPath - Optional host path to use rather than the default host path for the page.
*/
routeUrl(routeId: string, routeValues?: { [key: string]: string }, hostPath?: string): Promise<string>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

/**
* Interface for a class that can retrieve authorization tokens to be used in fetch requests.
*/
export interface IAuthorizationTokenProvider {
/**
* Gets the authorization header to use in a fetch request
*
* @param forceRefresh - If true, indicates that we should get a new token, if applicable for current provider.
* @returns the value to use for the Authorization header in a request.
*/
getAuthorizationHeader(forceRefresh?: boolean): Promise<string>;
}

/**
* Options for a specific instance of a REST client.
*/
export interface IVssRestClientOptions {

/**
* Auth token manager that can be used to get and attach auth tokens to requests.
* If not supplied, the default token provider is used if the serviceInstanceType option is supplied
* and is different from the hosting page's service instance type.
*/
authTokenProvider?: IAuthorizationTokenProvider;

/**
* The root URL path to use for this client. Can be relative or absolute.
*/
rootPath?: string | Promise<string>;

/**
* Current session id.
*/
sessionId?: string;

/**
* Current command for activity logging.
*/
command?: string;
}
Loading
Loading