diff --git a/lib/datasource/go/__snapshots__/index.spec.ts.snap b/lib/datasource/go/__snapshots__/index.spec.ts.snap index 625877a6e8602243264ee5c246d2c76903bcd0da..8ef004e2c8cad7bf39753313f42cb1fa1d1fc53f 100644 --- a/lib/datasource/go/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/go/__snapshots__/index.spec.ts.snap @@ -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 [ diff --git a/lib/datasource/go/index.spec.ts b/lib/datasource/go/index.spec.ts index ea5993f52093445ea9ea696ad5d7325db7d71849..442f20e38acf4bd210a988f698dd38a44f906c4e 100644 --- a/lib/datasource/go/index.spec.ts +++ b/lib/datasource/go/index.spec.ts @@ -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(); + }); }); }); diff --git a/lib/datasource/go/index.ts b/lib/datasource/go/index.ts index ba341aea2b3c6e2119a07525b66736cdf0e1af4b..37e931c6f0e4fa3dd2372aacbe9dc068a662a547 100644 --- a/lib/datasource/go/index.ts +++ b/lib/datasource/go/index.ts @@ -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, diff --git a/lib/util/url.spec.ts b/lib/util/url.spec.ts index 58461fff121a665dcad0b4d8a59d4e0cd59cfdac..6e9665ceb3dfd333ee164240194956ca9c7fe04b 100644 --- a/lib/util/url.spec.ts +++ b/lib/util/url.spec.ts @@ -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'); + }); }); diff --git a/lib/util/url.ts b/lib/util/url.ts index f18a9d46f044bb640f0a5dd67eb4869a89b6c3ed..6e61b1eeee889b9c5531ecb0642991250493e1eb 100644 --- a/lib/util/url.ts +++ b/lib/util/url.ts @@ -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();