mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 15:06:27 +00:00
refactor(go): Extract digest functionality to separate file (#12351)
This commit is contained in:
parent
9030b1a9ed
commit
bc94980bc0
3 changed files with 42 additions and 38 deletions
39
lib/datasource/go/digest.ts
Normal file
39
lib/datasource/go/digest.ts
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import * as github from '../github-tags';
|
||||||
|
import type { DigestConfig } from '../types';
|
||||||
|
import { bitbucket, getDatasource } from './util';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* go.getDigest
|
||||||
|
*
|
||||||
|
* This datasource resolves a go module URL into its source repository
|
||||||
|
* and then fetches the digest it if it is on GitHub.
|
||||||
|
*
|
||||||
|
* This function will:
|
||||||
|
* - Determine the source URL for the module
|
||||||
|
* - Call the respective getDigest in github to retrieve the commit hash
|
||||||
|
*/
|
||||||
|
export async function getDigest(
|
||||||
|
{ lookupName }: Partial<DigestConfig>,
|
||||||
|
value?: string
|
||||||
|
): Promise<string | null> {
|
||||||
|
const source = await getDatasource(lookupName);
|
||||||
|
if (!source) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore v0.0.0- pseudo versions that are used Go Modules - look up default branch instead
|
||||||
|
const tag = value && !value.startsWith('v0.0.0-2') ? value : undefined;
|
||||||
|
|
||||||
|
switch (source.datasource) {
|
||||||
|
case github.id: {
|
||||||
|
return github.getDigest(source, tag);
|
||||||
|
}
|
||||||
|
case bitbucket.id: {
|
||||||
|
return bitbucket.getDigest(source, tag);
|
||||||
|
}
|
||||||
|
/* istanbul ignore next: can never happen, makes lint happy */
|
||||||
|
default: {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,8 @@ import { getPkgReleases } from '..';
|
||||||
import * as httpMock from '../../../test/http-mock';
|
import * as httpMock from '../../../test/http-mock';
|
||||||
import { logger, mocked } from '../../../test/util';
|
import { logger, mocked } from '../../../test/util';
|
||||||
import * as _hostRules from '../../util/host-rules';
|
import * as _hostRules from '../../util/host-rules';
|
||||||
import { id as datasource, getDigest } from '.';
|
import { getDigest } from './digest';
|
||||||
|
import { id as datasource } from '.';
|
||||||
|
|
||||||
jest.mock('../../util/host-rules');
|
jest.mock('../../util/host-rules');
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { logger } from '../../logger';
|
||||||
import { regEx } from '../../util/regex';
|
import { regEx } from '../../util/regex';
|
||||||
import * as github from '../github-tags';
|
import * as github from '../github-tags';
|
||||||
import * as gitlab from '../gitlab-tags';
|
import * as gitlab from '../gitlab-tags';
|
||||||
import type { DigestConfig, GetReleasesConfig, ReleaseResult } from '../types';
|
import type { GetReleasesConfig, ReleaseResult } from '../types';
|
||||||
import * as goproxy from './goproxy';
|
import * as goproxy from './goproxy';
|
||||||
import { bitbucket, getDatasource } from './util';
|
import { bitbucket, getDatasource } from './util';
|
||||||
|
|
||||||
|
@ -115,39 +115,3 @@ export async function getReleases(
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* go.getDigest
|
|
||||||
*
|
|
||||||
* This datasource resolves a go module URL into its source repository
|
|
||||||
* and then fetches the digest it if it is on GitHub.
|
|
||||||
*
|
|
||||||
* This function will:
|
|
||||||
* - Determine the source URL for the module
|
|
||||||
* - Call the respective getDigest in github to retrieve the commit hash
|
|
||||||
*/
|
|
||||||
export async function getDigest(
|
|
||||||
{ lookupName }: Partial<DigestConfig>,
|
|
||||||
value?: string
|
|
||||||
): Promise<string | null> {
|
|
||||||
const source = await getDatasource(lookupName);
|
|
||||||
if (!source) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ignore v0.0.0- pseudo versions that are used Go Modules - look up default branch instead
|
|
||||||
const tag = value && !value.startsWith('v0.0.0-2') ? value : undefined;
|
|
||||||
|
|
||||||
switch (source.datasource) {
|
|
||||||
case github.id: {
|
|
||||||
return github.getDigest(source, tag);
|
|
||||||
}
|
|
||||||
case bitbucket.id: {
|
|
||||||
return bitbucket.getDigest(source, tag);
|
|
||||||
}
|
|
||||||
/* istanbul ignore next: can never happen, makes lint happy */
|
|
||||||
default: {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue