Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deps): upgrade to got v10 #5469

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6c51983
CUpgrade to Got 10
szmarczak Feb 12, 2020
e414f6a
update yarn lock
viceice Feb 12, 2020
29e4d3e
fix types
viceice Feb 12, 2020
47c0c13
add null checks
viceice Feb 12, 2020
af19ce7
fix snapshots
viceice Feb 12, 2020
b04919e
fix types
viceice Feb 12, 2020
118c5fc
Merge branch 'master' into got-10
viceice Feb 13, 2020
5cb9132
fix test name
viceice Feb 13, 2020
4a35a55
fix retry
szmarczak Feb 15, 2020
8b2d4aa
Update lib/datasource/rubygems/get.ts
szmarczak Feb 16, 2020
f15c864
Update lib/datasource/rubygems/get.ts
szmarczak Feb 16, 2020
cb7668e
Merge remote-tracking branch 'origin/HEAD' into szmarczak/got-10
viceice Feb 17, 2020
4971fb1
fix snapshots
viceice Feb 17, 2020
d1b31a2
fix type
viceice Feb 17, 2020
56996b7
remove retry
viceice Feb 17, 2020
5026507
fix options
viceice Feb 17, 2020
bff4c6e
add statusCode workaround
viceice Feb 17, 2020
5ef8e78
add `code` workaround
viceice Feb 17, 2020
2138fff
chore: testing
viceice Feb 19, 2020
1a63260
Merge remote-tracking branch 'origin/HEAD' into szmarczak/got-10
viceice Feb 27, 2020
f583128
fix: wrong merge
viceice Feb 27, 2020
c3046ee
chore: update got
viceice Feb 27, 2020
471708c
chore: fix api
viceice Feb 27, 2020
ee4a49e
chore: fix linting
viceice Feb 27, 2020
24ba4c3
Merge remote-tracking branch 'origin/HEAD' into szmarczak/got-10
viceice Feb 27, 2020
df5dee3
fix: fix got hooks
viceice Feb 27, 2020
9c7a1be
Merge remote-tracking branch 'origin/HEAD' into szmarczak/got-10
viceice Feb 27, 2020
7b675cc
fix: missing getter
viceice Feb 27, 2020
f19c7af
chore: fix lint error
viceice Feb 28, 2020
0db8164
fix: wrong auth handling
viceice Feb 28, 2020
1856d95
Merge branch 'master' of https://github.com/renovatebot/renovate into…
viceice Feb 28, 2020
ce0b2bd
chore: fix tests
viceice Feb 28, 2020
776ffd6
Merge branch 'master' of https://github.com/renovatebot/renovate into…
viceice Feb 28, 2020
e12c555
Merge branch 'master' of https://github.com/renovatebot/renovate into…
viceice Feb 28, 2020
2614a41
Merge branch 'master' of https://github.com/renovatebot/renovate into…
viceice Feb 28, 2020
bb0d910
Merge branch 'master' of https://github.com/renovatebot/renovate into…
viceice Mar 2, 2020
d6b57f5
chore: fix args
viceice Mar 2, 2020
994a26f
chore: fix api
viceice Mar 2, 2020
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
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ module.exports = {
'prefer-template': 0,
'no-underscore-dangle': 0,

'import/no-unresolved': [2, { ignore: ['^type-fest$'] }],

// Makes no sense to allow type inferrence for expression parameters, but require typing the response
'@typescript-eslint/explicit-function-return-type': [
'error',
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/cargo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function getPkgReleases({
const crateUrl = baseUrl + path;
try {
let res: any = await got(crateUrl, {
hostType: DATASOURCE_CARGO,
context: { hostType: DATASOURCE_CARGO },
});
if (!res || !res.body) {
logger.warn(
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/cdnjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function getPkgReleases({
const url = depUrl(depName);

try {
const res = await got(url, { json: true });
const res = await got(url, { responseType: 'json' });

const cdnjsResp: CdnjsResponse = res.body;

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/dart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function getPkgReleases({
} = null;
try {
raw = await got(pkgUrl, {
json: true,
responseType: 'json',
});
} catch (err) {
if (err.statusCode === 404 || err.code === 'ENOTFOUND') {
Expand Down
20 changes: 10 additions & 10 deletions lib/datasource/docker/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports[`api/docker getPkgReleases adds library/ prefix for Docker Hub (explicit
"headers": Object {
"authorization": "Basic c29tZS11c2VybmFtZTpzb21lLXBhc3N3b3Jk",
},
"json": true,
"responseType": "json",
},
],
Array [
Expand All @@ -24,7 +24,7 @@ exports[`api/docker getPkgReleases adds library/ prefix for Docker Hub (explicit
"headers": Object {
"authorization": "Bearer some-token ",
},
"json": true,
"responseType": "json",
},
],
Array [
Expand Down Expand Up @@ -103,7 +103,7 @@ exports[`api/docker getPkgReleases adds library/ prefix for Docker Hub (implicit
"headers": Object {
"authorization": "Basic c29tZS11c2VybmFtZTpzb21lLXBhc3N3b3Jk",
},
"json": true,
"responseType": "json",
},
],
Array [
Expand All @@ -112,7 +112,7 @@ exports[`api/docker getPkgReleases adds library/ prefix for Docker Hub (implicit
"headers": Object {
"authorization": "Bearer some-token ",
},
"json": true,
"responseType": "json",
},
],
Array [
Expand Down Expand Up @@ -191,7 +191,7 @@ exports[`api/docker getPkgReleases adds no library/ prefix for other registries
"headers": Object {
"authorization": "Basic c29tZS11c2VybmFtZTpzb21lLXBhc3N3b3Jk",
},
"json": true,
"responseType": "json",
},
],
Array [
Expand All @@ -200,7 +200,7 @@ exports[`api/docker getPkgReleases adds no library/ prefix for other registries
"headers": Object {
"authorization": "Bearer some-token ",
},
"json": true,
"responseType": "json",
},
],
Array [
Expand Down Expand Up @@ -277,7 +277,7 @@ exports[`api/docker getPkgReleases uses custom registry in depName 1`] = `
"https://registry.company.com/v2/node/tags/list?n=10000",
Object {
"headers": Object {},
"json": true,
"responseType": "json",
},
],
Array [
Expand Down Expand Up @@ -325,14 +325,14 @@ Array [
"https://registry.company.com/v2/node/tags/list?n=10000",
Object {
"headers": Object {},
"json": true,
"responseType": "json",
},
],
Array [
"https://api.github.com/user/9287/repos?page=3&per_page=100",
Object {
"headers": Object {},
"json": true,
"responseType": "json",
},
],
Array [
Expand Down Expand Up @@ -365,7 +365,7 @@ exports[`api/docker getPkgReleases uses lower tag limit for ECR deps 1`] = `
"https://123456789.dkr.ecr.us-east-1.amazonaws.com/v2/node/tags/list?n=1000",
Object {
"headers": Object {},
"json": true,
"responseType": "json",
},
],
Array [
Expand Down
29 changes: 18 additions & 11 deletions lib/datasource/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import hasha from 'hasha';
import URL from 'url';
import parseLinkHeader from 'parse-link-header';
import wwwAuthenticate from 'www-authenticate';
import { OutgoingHttpHeaders } from 'http';
import AWS from 'aws-sdk';
import { Options } from 'got';
import { logger } from '../../logger';
import got from '../../util/got';
import got, { GotHeaders } from '../../util/got';
import * as hostRules from '../../util/host-rules';
import { DatasourceError, PkgReleaseConfig, ReleaseResult } from '../common';
import { GotResponse } from '../../platform';
Expand Down Expand Up @@ -61,7 +61,7 @@ export function getRegistryRepository(

function getECRAuthToken(
region: string,
opts: hostRules.HostRule
opts: Options
): Promise<string | null> {
const config = { region, accessKeyId: undefined, secretAccessKey: undefined };
if (opts.username && opts.password) {
Expand Down Expand Up @@ -97,7 +97,7 @@ function getECRAuthToken(
async function getAuthHeaders(
registry: string,
repository: string
): Promise<OutgoingHttpHeaders | null> {
): Promise<GotHeaders | null> {
try {
const apiCheckUrl = `${registry}/v2/`;
const apiCheckResponse = await got(apiCheckUrl, { throwHttpErrors: false });
Expand All @@ -108,10 +108,12 @@ async function getAuthHeaders(
apiCheckResponse.headers['www-authenticate']
);

const opts: hostRules.HostRule & {
headers?: Record<string, string>;
} = hostRules.find({ hostType: DATASOURCE_DOCKER, url: apiCheckUrl });
opts.json = true;
// TODO: fix types
const opts: any = hostRules.find({
hostType: DATASOURCE_DOCKER,
url: apiCheckUrl,
});
opts.responseType = 'json';
if (ecrRegex.test(registry)) {
const [, region] = ecrRegex.exec(registry);
const auth = await getECRAuthToken(region, opts);
Expand All @@ -138,7 +140,9 @@ async function getAuthHeaders(
logger.trace(
`Obtaining docker registry token for ${repository} using url ${authUrl}`
);
const authResponse = (await got(authUrl, opts)).body;
const authResponse = (
await got<{ token?: string; access_token?: string }>(authUrl, opts)
).body;

const token = authResponse.token || authResponse.access_token;
// istanbul ignore if
Expand Down Expand Up @@ -346,7 +350,10 @@ async function getTags(
}
let page = 1;
do {
const res = await got<{ tags: string[] }>(url, { json: true, headers });
const res = await got<{ tags: string[] }>(url, {
responseType: 'json',
headers,
});
tags = tags.concat(res.body.tags);
const linkHeader = parseLinkHeader(res.headers.link as string);
url =
Expand Down Expand Up @@ -437,7 +444,7 @@ export function getConfigResponseBeforeRedirectHook(options: any): void {

export function getConfigResponse(
url: string,
headers: OutgoingHttpHeaders
headers: GotHeaders
): Promise<GotResponse> {
return got(url, {
headers,
Expand Down
10 changes: 5 additions & 5 deletions lib/datasource/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
DigestConfig,
} from '../common';
import { logger } from '../../logger';
import got, { GotJSONOptions } from '../../util/got';
import got, { GotJSONOptions, GotResponse } from '../../util/got';
import { PLATFORM_FAILURE } from '../../constants/error-messages';
import { DATASOURCE_GITHUB } from '../../constants/data-binary-source';

Expand All @@ -20,12 +20,12 @@ async function fetchJSONFile(repo: string, fileName: string): Promise<Preset> {
? 'application/vnd.github.machine-man-preview+json'
: 'application/vnd.github.v3+json',
},
json: true,
hostType: DATASOURCE_GITHUB,
responseType: 'json',
context: { hostType: DATASOURCE_GITHUB },
};
let res: { body: { content: string } };
let res: GotResponse<{ content: string }>;
try {
res = await got(url, opts);
res = await got<{ content: string }>(url, opts);
} catch (err) {
if (err.message === PLATFORM_FAILURE) {
throw err;
Expand Down
8 changes: 4 additions & 4 deletions lib/datasource/go/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ async function getDatasource(name: string): Promise<DataSource | null> {
try {
const res = (
await got(pkgUrl, {
hostType: DATASOURCE_GO,
context: { hostType: DATASOURCE_GO },
})
).body;
const sourceMatch = res.match(
regEx(`<meta\\s+name="go-source"\\s+content="${name}\\s+([^\\s]+)`)
);
const sourceMatch = regEx(
`<meta\\s+name="go-source"\\s+content="${name}\\s+([^\\s]+)`
).exec(res);
if (sourceMatch) {
const [, goSourceUrl] = sourceMatch;
logger.debug({ depName: name, goSourceUrl }, 'Go lookup source url');
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/gradle-version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function getPkgReleases({
versionsUrls.map(async url => {
try {
const response: GradleRelease = await got(url, {
json: true,
responseType: 'json',
});
const releases = response.body
.filter(release => !release.snapshot && !release.nightly)
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/helm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function getRepositoryData(
}
let res: any;
try {
res = await got('index.yaml', { baseUrl: repository });
res = await got('index.yaml', { prefixUrl: repository });
if (!res || !res.body) {
logger.warn(`Received invalid response from ${repository}`);
return null;
Expand Down
8 changes: 4 additions & 4 deletions lib/datasource/hex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export async function getPkgReleases({
const depName = lookupName.split(':')[0];
const hexUrl = `https://hex.pm/api/packages/${depName}`;
try {
const response = await got(hexUrl, {
json: true,
hostType: DATASOURCE_HEX,
const response = await got<HexRelease>(hexUrl, {
responseType: 'json',
context: { hostType: DATASOURCE_HEX },
});

const hexRelease: HexRelease = response.body;
const hexRelease = response.body;

if (!hexRelease) {
logger.warn({ depName }, `Invalid response body`);
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/maven/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function downloadHttpProtocol(
let raw: { body: string };
try {
raw = await got(pkgUrl, {
hostType,
context: { hostType },
hooks: {
beforeRedirect: [
(options: any): void => {
Expand Down
Loading