Skip to content

Commit

Permalink
Replaced request with typed-rest-client package (#16188)
Browse files Browse the repository at this point in the history
* replace request with typed-rest-client

* bump version

* bump version
  • Loading branch information
AndreyIvanov42 authored May 12, 2022
1 parent 74a7808 commit 0aa2f0d
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 468 deletions.
95 changes: 78 additions & 17 deletions Tasks/DownloadBuildArtifactsV0/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 13 additions & 19 deletions Tasks/DownloadGitHubNpmPackageV1/npminstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NpmToolRunner } from './npmtoolrunner';
import * as util from 'packaging-common/util';
import * as npmutil from 'packaging-common/npm/npmutil';
import * as path from 'path';
import * as request from 'request';
import * as httpClient from 'typed-rest-client/HttpClient';

export async function run(): Promise<void> {
try {
Expand Down Expand Up @@ -93,14 +93,12 @@ function createProjectFile(projectDirectory: string, owner: string): string {
return path.join(projectDirectory, "package.json");
}

function GetGitHubUser(endpointId: string): Promise<string> {
async function GetGitHubUser(endpointId: string): Promise<string> {
let externalAuth = tl.getEndpointAuthorization(endpointId, true);
let scheme = tl.getEndpointAuthorizationScheme(endpointId, true).toLowerCase();

if (!(scheme == "token" || scheme == "personalaccesstoken")) {
return new Promise((resolve, reject) => {
resolve("");
});
return "";
}

let token = "";
Expand All @@ -110,21 +108,17 @@ function GetGitHubUser(endpointId: string): Promise<string> {
token = externalAuth.parameters["accessToken"];
}

var url = "https://api.github.com/user";

return new Promise((resolve, reject) => {
request.get({
url : url,
headers : {
"Authorization": "Token " + token,
"User-Agent": "azure-pipelines"
}
}, function(error, response, body) {
if (error) reject(error);
let responseJson = JSON.parse(body);
resolve(responseJson["login"]);
});
const http = new httpClient.HttpClient('typed-test-client');

let res = await http.get("https://api.github.com/user", {
"Authorization": "Token " + token,
"User-Agent": "azure-pipelines"
});

let body = await res.readBody();
let json: { login: string } = JSON.parse(body);

return json.login;
}

function getEndpointAuthData(endpointName: string): string {
Expand Down
Loading

0 comments on commit 0aa2f0d

Please sign in to comment.