mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 15:06:27 +00:00
fix(go): Improve go-import content parsing (#9022)
This commit is contained in:
parent
dda7514e20
commit
ccdb09fe3c
5 changed files with 90 additions and 3 deletions
|
@ -143,6 +143,56 @@ Array [
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`datasource/go getReleases handles fyne.io 1`] = `
|
||||||
|
Object {
|
||||||
|
"releases": Array [
|
||||||
|
Object {
|
||||||
|
"gitRef": "v1.0.0",
|
||||||
|
"version": "v1.0.0",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"gitRef": "v2.0.0",
|
||||||
|
"version": "v2.0.0",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"sourceUrl": "https://github.com/fyne-io/fyne",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`datasource/go getReleases handles fyne.io 2`] = `
|
||||||
|
Array [
|
||||||
|
Object {
|
||||||
|
"headers": Object {
|
||||||
|
"accept-encoding": "gzip, deflate",
|
||||||
|
"host": "fyne.io",
|
||||||
|
"user-agent": "https://github.com/renovatebot/renovate",
|
||||||
|
},
|
||||||
|
"method": "GET",
|
||||||
|
"url": "https://fyne.io/fyne?go-get=1",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"headers": Object {
|
||||||
|
"accept": "application/vnd.github.v3+json",
|
||||||
|
"accept-encoding": "gzip, deflate",
|
||||||
|
"host": "api.github.com",
|
||||||
|
"user-agent": "https://github.com/renovatebot/renovate",
|
||||||
|
},
|
||||||
|
"method": "GET",
|
||||||
|
"url": "https://api.github.com/repos/fyne-io/fyne/tags?per_page=100",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"headers": Object {
|
||||||
|
"accept": "application/vnd.github.v3+json",
|
||||||
|
"accept-encoding": "gzip, deflate",
|
||||||
|
"host": "api.github.com",
|
||||||
|
"user-agent": "https://github.com/renovatebot/renovate",
|
||||||
|
},
|
||||||
|
"method": "GET",
|
||||||
|
"url": "https://api.github.com/repos/fyne-io/fyne/releases?per_page=100",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`datasource/go getReleases processes real data 1`] = `
|
exports[`datasource/go getReleases processes real data 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"releases": Array [
|
"releases": Array [
|
||||||
|
|
|
@ -445,5 +445,28 @@ describe('datasource/go', () => {
|
||||||
expect(httpCalls).toMatchSnapshot();
|
expect(httpCalls).toMatchSnapshot();
|
||||||
httpMock.reset();
|
httpMock.reset();
|
||||||
});
|
});
|
||||||
|
it('handles fyne.io', async () => {
|
||||||
|
httpMock
|
||||||
|
.scope('https://fyne.io/')
|
||||||
|
.get('/fyne?go-get=1')
|
||||||
|
.reply(
|
||||||
|
200,
|
||||||
|
'<meta name="go-import" content="fyne.io/fyne git https://github.com/fyne-io/fyne">'
|
||||||
|
);
|
||||||
|
httpMock
|
||||||
|
.scope('https://api.github.com/')
|
||||||
|
.get('/repos/fyne-io/fyne/tags?per_page=100')
|
||||||
|
.reply(200, [{ name: 'v1.0.0' }, { name: 'v2.0.0' }])
|
||||||
|
.get('/repos/fyne-io/fyne/releases?per_page=100')
|
||||||
|
.reply(200, []);
|
||||||
|
const res = await getPkgReleases({
|
||||||
|
datasource,
|
||||||
|
depName: 'fyne.io/fyne',
|
||||||
|
});
|
||||||
|
expect(res).toMatchSnapshot();
|
||||||
|
expect(res).not.toBeNull();
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
expect(httpMock.getTrace()).toMatchSnapshot();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { logger } from '../../logger';
|
||||||
import * as hostRules from '../../util/host-rules';
|
import * as hostRules from '../../util/host-rules';
|
||||||
import { Http } from '../../util/http';
|
import { Http } from '../../util/http';
|
||||||
import { regEx } from '../../util/regex';
|
import { regEx } from '../../util/regex';
|
||||||
|
import { trimTrailingSlash } from '../../util/url';
|
||||||
import * as bitbucket from '../bitbucket-tags';
|
import * as bitbucket from '../bitbucket-tags';
|
||||||
import * as github from '../github-tags';
|
import * as github from '../github-tags';
|
||||||
import * as gitlab from '../gitlab-tags';
|
import * as gitlab from '../gitlab-tags';
|
||||||
|
@ -115,8 +116,11 @@ async function getDatasource(goModule: string): Promise<DataSource | null> {
|
||||||
const parsedUrl = URL.parse(goImportURL);
|
const parsedUrl = URL.parse(goImportURL);
|
||||||
|
|
||||||
// split the go module from the URL: host/go/module -> go/module
|
// split the go module from the URL: host/go/module -> go/module
|
||||||
const split = goModule.split('/');
|
const lookupName = trimTrailingSlash(parsedUrl.pathname)
|
||||||
const lookupName = split[1] + '/' + split[2];
|
.replace(/\.git$/, '')
|
||||||
|
.split('/')
|
||||||
|
.slice(-2)
|
||||||
|
.join('/');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
datasource: github.id,
|
datasource: github.id,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { resolveBaseUrl, validateUrl } from './url';
|
import { resolveBaseUrl, trimTrailingSlash, validateUrl } from './url';
|
||||||
|
|
||||||
describe('util/url', () => {
|
describe('util/url', () => {
|
||||||
test.each([
|
test.each([
|
||||||
|
@ -53,4 +53,10 @@ describe('util/url', () => {
|
||||||
expect(validateUrl('http://github.com')).toBe(true);
|
expect(validateUrl('http://github.com')).toBe(true);
|
||||||
expect(validateUrl('https://github.com')).toBe(true);
|
expect(validateUrl('https://github.com')).toBe(true);
|
||||||
});
|
});
|
||||||
|
it('trimTrailingSlash', () => {
|
||||||
|
expect(trimTrailingSlash('foo')).toBe('foo');
|
||||||
|
expect(trimTrailingSlash('/foo/bar')).toBe('/foo/bar');
|
||||||
|
expect(trimTrailingSlash('foo/')).toBe('foo');
|
||||||
|
expect(trimTrailingSlash('foo//////')).toBe('foo');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,6 +4,10 @@ export function ensureTrailingSlash(url: string): string {
|
||||||
return url.replace(/\/?$/, '/');
|
return url.replace(/\/?$/, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function trimTrailingSlash(url: string): string {
|
||||||
|
return url.replace(/\/+$/, '');
|
||||||
|
}
|
||||||
|
|
||||||
export function resolveBaseUrl(baseUrl: string, input: string | URL): string {
|
export function resolveBaseUrl(baseUrl: string, input: string | URL): string {
|
||||||
const inputString = input.toString();
|
const inputString = input.toString();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue