mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +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`] = `
|
||||
Object {
|
||||
"releases": Array [
|
||||
|
|
|
@ -445,5 +445,28 @@ describe('datasource/go', () => {
|
|||
expect(httpCalls).toMatchSnapshot();
|
||||
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 { Http } from '../../util/http';
|
||||
import { regEx } from '../../util/regex';
|
||||
import { trimTrailingSlash } from '../../util/url';
|
||||
import * as bitbucket from '../bitbucket-tags';
|
||||
import * as github from '../github-tags';
|
||||
import * as gitlab from '../gitlab-tags';
|
||||
|
@ -115,8 +116,11 @@ async function getDatasource(goModule: string): Promise<DataSource | null> {
|
|||
const parsedUrl = URL.parse(goImportURL);
|
||||
|
||||
// split the go module from the URL: host/go/module -> go/module
|
||||
const split = goModule.split('/');
|
||||
const lookupName = split[1] + '/' + split[2];
|
||||
const lookupName = trimTrailingSlash(parsedUrl.pathname)
|
||||
.replace(/\.git$/, '')
|
||||
.split('/')
|
||||
.slice(-2)
|
||||
.join('/');
|
||||
|
||||
return {
|
||||
datasource: github.id,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { resolveBaseUrl, validateUrl } from './url';
|
||||
import { resolveBaseUrl, trimTrailingSlash, validateUrl } from './url';
|
||||
|
||||
describe('util/url', () => {
|
||||
test.each([
|
||||
|
@ -53,4 +53,10 @@ describe('util/url', () => {
|
|||
expect(validateUrl('http://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(/\/?$/, '/');
|
||||
}
|
||||
|
||||
export function trimTrailingSlash(url: string): string {
|
||||
return url.replace(/\/+$/, '');
|
||||
}
|
||||
|
||||
export function resolveBaseUrl(baseUrl: string, input: string | URL): string {
|
||||
const inputString = input.toString();
|
||||
|
||||
|
|
Loading…
Reference in a new issue