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

refactor(go): Extract digest functionality to separate file #12351

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions lib/datasource/go/digest.ts
@@ -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;
}
}
}
3 changes: 2 additions & 1 deletion lib/datasource/go/index.spec.ts
Expand Up @@ -2,7 +2,8 @@ import { getPkgReleases } from '..';
import * as httpMock from '../../../test/http-mock';
import { logger, mocked } from '../../../test/util';
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');

Expand Down
38 changes: 1 addition & 37 deletions lib/datasource/go/index.ts
Expand Up @@ -2,7 +2,7 @@ import { logger } from '../../logger';
import { regEx } from '../../util/regex';
import * as github from '../github-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 { bitbucket, getDatasource } from './util';

Expand Down Expand Up @@ -115,39 +115,3 @@ export async function getReleases(

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;
}
}
}