code review

This commit is contained in:
Josh Gross
2020-01-10 18:12:28 -05:00
parent cfcdda9620
commit b1a3f20932
12 changed files with 16 additions and 78 deletions

View File

@@ -7,7 +7,7 @@ on:
- '**.md' - '**.md'
pull_request: pull_request:
paths-ignore: paths-ignore:
- '**.md' - '**.md'
jobs: jobs:

View File

@@ -1,4 +1,4 @@
Typed Rest Client for Node.js Actions Http Client for Node.js
Copyright (c) GitHub, Inc. Copyright (c) GitHub, Inc.

View File

@@ -1,6 +1,5 @@
import * as httpm from '../_out'; import * as httpm from '../';
import * as path from 'path'; import * as am from '../auth';
import * as am from '../_out/auth';
describe('auth', () => { describe('auth', () => {
beforeEach(() => { beforeEach(() => {

View File

@@ -1,14 +1,11 @@
import * as httpm from '../_out'; import * as httpm from '../';
import * as path from 'path'; import * as path from 'path';
import * as am from '../_out/auth';
import * as fs from 'fs'; import * as fs from 'fs';
import { connect } from 'http2';
let sampleFilePath: string = path.join(__dirname, 'testoutput.txt'); let sampleFilePath: string = path.join(__dirname, 'testoutput.txt');
describe('basics', () => { describe('basics', () => {
let _http: httpm.HttpClient; let _http: httpm.HttpClient;
let _httpbin: httpm.HttpClient;
beforeEach(() => { beforeEach(() => {
_http = new httpm.HttpClient('http-client-tests'); _http = new httpm.HttpClient('http-client-tests');

View File

@@ -1,13 +1,7 @@
import * as httpm from '../_out'; import * as httpm from '../';
import * as path from 'path';
import * as am from '../_out/auth';
import * as fs from 'fs';
let sampleFilePath: string = path.join(__dirname, 'testoutput.txt');
describe('basics', () => { describe('basics', () => {
let _http: httpm.HttpClient; let _http: httpm.HttpClient;
let _httpbin: httpm.HttpClient;
beforeEach(() => { beforeEach(() => {
_http = new httpm.HttpClient('http-client-tests', [], { keepAlive: true }); _http = new httpm.HttpClient('http-client-tests', [], { keepAlive: true });

View File

@@ -1,4 +1,4 @@
import * as pm from '../_out/proxy'; import * as pm from '../proxy';
import * as url from 'url'; import * as url from 'url';
describe('proxy', () => { describe('proxy', () => {

View File

@@ -11,7 +11,7 @@ export class BasicCredentialHandler implements ifm.IRequestHandler {
} }
prepareRequest(options:any): void { prepareRequest(options:any): void {
options.headers['Authorization'] = 'Basic ' + new Buffer(this.username + ':' + this.password).toString('base64'); options.headers['Authorization'] = 'Basic ' + Buffer.from(this.username + ':' + this.password).toString('base64');
} }
// This handler cannot handle 401 // This handler cannot handle 401
@@ -57,7 +57,7 @@ export class PersonalAccessTokenCredentialHandler implements ifm.IRequestHandler
// currently implements pre-authorization // currently implements pre-authorization
// TODO: support preAuth = false where it hooks on 401 // TODO: support preAuth = false where it hooks on 401
prepareRequest(options:any): void { prepareRequest(options:any): void {
options.headers['Authorization'] = 'Basic ' + new Buffer('PAT:' + this.token).toString('base64'); options.headers['Authorization'] = 'Basic ' + Buffer.from('PAT:' + this.token).toString('base64');
} }
// This handler cannot handle 401 // This handler cannot handle 401

View File

@@ -4,7 +4,6 @@ import https = require("https");
import ifm = require('./interfaces'); import ifm = require('./interfaces');
import pm = require('./proxy'); import pm = require('./proxy');
let fs: any;
let tunnel: any; let tunnel: any;
export enum HttpCodes { export enum HttpCodes {
@@ -70,7 +69,7 @@ export function isHttps(requestUrl: string) {
} }
export class HttpClient { export class HttpClient {
userAgent: string | null | undefined; userAgent: string | undefined;
handlers: ifm.IRequestHandler[]; handlers: ifm.IRequestHandler[];
requestOptions: ifm.IRequestOptions; requestOptions: ifm.IRequestOptions;
@@ -276,8 +275,7 @@ export class HttpClient {
*/ */
public requestRawWithCallback(info: ifm.IRequestInfo, data: string | NodeJS.ReadableStream, onResult: (err: any, res: ifm.IHttpClientResponse) => void): void { public requestRawWithCallback(info: ifm.IRequestInfo, data: string | NodeJS.ReadableStream, onResult: (err: any, res: ifm.IHttpClientResponse) => void): void {
let socket; let socket;
let isDataString = typeof (data) === 'string';
if (typeof (data) === 'string') { if (typeof (data) === 'string') {
info.options.headers["Content-Length"] = Buffer.byteLength(data, 'utf8'); info.options.headers["Content-Length"] = Buffer.byteLength(data, 'utf8');
} }

47
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "@actions/http-client", "name": "@actions/http-client",
"version": "1.0.0", "version": "1.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@@ -2381,12 +2381,6 @@
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"dev": true "dev": true
}, },
"interpret": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/interpret/-/interpret-1.2.0.tgz",
"integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==",
"dev": true
},
"invariant": { "invariant": {
"version": "2.2.4", "version": "2.2.4",
"resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz",
@@ -3473,19 +3467,6 @@
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==",
"dev": true "dev": true
}, },
"nock": {
"version": "11.7.2",
"resolved": "https://registry.npmjs.org/nock/-/nock-11.7.2.tgz",
"integrity": "sha512-7swr5bL1xBZ5FctyubjxEVySXOSebyqcL7Vy1bx1nS9IUqQWj81cmKjVKJLr8fHhtzI1MV8nyCdENA/cGcY1+Q==",
"dev": true,
"requires": {
"debug": "^4.1.0",
"json-stringify-safe": "^5.0.1",
"lodash": "^4.17.13",
"mkdirp": "^0.5.0",
"propagate": "^2.0.0"
}
},
"node-int64": { "node-int64": {
"version": "0.4.0", "version": "0.4.0",
"resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",
@@ -3839,12 +3820,6 @@
"sisteransi": "^1.0.3" "sisteransi": "^1.0.3"
} }
}, },
"propagate": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz",
"integrity": "sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==",
"dev": true
},
"psl": { "psl": {
"version": "1.7.0", "version": "1.7.0",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.7.0.tgz", "resolved": "https://registry.npmjs.org/psl/-/psl-1.7.0.tgz",
@@ -3909,15 +3884,6 @@
"util.promisify": "^1.0.0" "util.promisify": "^1.0.0"
} }
}, },
"rechoir": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz",
"integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=",
"dev": true,
"requires": {
"resolve": "^1.1.6"
}
},
"regex-not": { "regex-not": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/regex-not/-/regex-not-1.0.2.tgz", "resolved": "https://registry.npmjs.org/regex-not/-/regex-not-1.0.2.tgz",
@@ -4177,17 +4143,6 @@
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=",
"dev": true "dev": true
}, },
"shelljs": {
"version": "0.8.3",
"resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.3.tgz",
"integrity": "sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A==",
"dev": true,
"requires": {
"glob": "^7.0.0",
"interpret": "^1.0.0",
"rechoir": "^0.6.2"
}
},
"shellwords": { "shellwords": {
"version": "0.1.1", "version": "0.1.1",
"resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz", "resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz",

View File

@@ -4,7 +4,7 @@
"description": "Actions Http Client", "description": "Actions Http Client",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "rm -Rf ./_out && tsc && cp package*.json ./_out && cp *.md ./_out && cp LICENSE ./_out && cp actions.png ./_out", "build": "tsc",
"test": "jest" "test": "jest"
}, },
"repository": { "repository": {
@@ -26,8 +26,6 @@
"@types/node": "^13.1.5", "@types/node": "^13.1.5",
"@types/shelljs": "^0.8.6", "@types/shelljs": "^0.8.6",
"jest": "^24.9.0", "jest": "^24.9.0",
"nock": "^11.7.2",
"shelljs": "^0.8.3",
"ts-jest": "^24.3.0", "ts-jest": "^24.3.0",
"typescript": "^3.7.4" "typescript": "^3.7.4"
} }

View File

@@ -17,7 +17,7 @@ export function getProxyUrl(reqUrl: url.Url): url.Url {
bypass = true; bypass = true;
break; break;
} }
} }
} }
let proxyUrl: url.Url; let proxyUrl: url.Url;
@@ -34,7 +34,7 @@ export function getProxyUrl(reqUrl: url.Url): url.Url {
proxyVar = process.env["http_proxy"] || proxyVar = process.env["http_proxy"] ||
process.env["HTTP_PROXY"]; process.env["HTTP_PROXY"];
} }
if (proxyVar) { if (proxyVar) {
proxyUrl = url.parse(proxyVar); proxyUrl = url.parse(proxyVar);
} }

View File

@@ -8,8 +8,5 @@
"outDir": "_out", "outDir": "_out",
"forceConsistentCasingInFileNames": true "forceConsistentCasingInFileNames": true
}, },
"files": [ "include": ["*.ts"]
"index.ts",
"auth.ts"
]
} }