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(util/hash): replace sha256 hasha use cases #23547

Merged
merged 3 commits into from
Jul 24, 2023
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
6 changes: 2 additions & 4 deletions lib/modules/datasource/crate/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import hasha from 'hasha';
import Git from 'simple-git';
import upath from 'upath';
import { GlobalConfig } from '../../../config/global';
Expand All @@ -7,6 +6,7 @@ import * as memCache from '../../../util/cache/memory';
import { cache } from '../../../util/cache/package/decorator';
import { privateCacheDir, readCacheFile } from '../../../util/fs';
import { simpleGitConfig } from '../../../util/git/config';
import { toSha256 } from '../../../util/hash';
import { newlineRegex, regEx } from '../../../util/regex';
import { joinUrlParts, parseUrl } from '../../../util/url';
import * as cargoVersioning from '../../versioning/cargo';
Expand Down Expand Up @@ -214,9 +214,7 @@ export class CrateDatasource extends Datasource {
private static cacheDirFromUrl(url: URL): string {
const proto = url.protocol.replace(regEx(/:$/), '');
const host = url.hostname;
const hash = hasha(url.pathname, {
algorithm: 'sha256',
}).substring(0, 7);
const hash = toSha256(url.pathname).substring(0, 7);

return `crate-registry-${proto}-${host}-${hash}`;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/datasource/docker/common.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import is from '@sindresorhus/is';
import { parse } from 'auth-header';
import hasha from 'hasha';
import {
HOST_DISABLED,
PAGE_NOT_FOUND_ERROR,
} from '../../../constants/error-messages';
import { logger } from '../../../logger';
import type { HostRule } from '../../../types';
import { ExternalHostError } from '../../../types/errors/external-host-error';
import { toSha256 } from '../../../util/hash';
import * as hostRules from '../../../util/host-rules';
import type { Http } from '../../../util/http';
import type {
Expand Down Expand Up @@ -285,7 +285,7 @@ export function getRegistryRepository(
export function extractDigestFromResponseBody(
manifestResponse: HttpResponse
): string {
return 'sha256:' + hasha(manifestResponse.body, { algorithm: 'sha256' });
return 'sha256:' + toSha256(manifestResponse.body);
}

export function findLatestStable(tags: string[]): string | null {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import hasha from 'hasha';
import * as httpMock from '../../../../test/http-mock';
import type { GithubDigestFile } from '../../../util/github/types';
import { toSha256 } from '../../../util/hash';
import { GitHubReleaseAttachmentMocker } from './test';

import { GithubReleaseAttachmentsDatasource } from '.';
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('modules/datasource/github-release-attachments/digest', () => {
'asset.zip': content,
'smallest.zip': '1'.repeat(8 * 1024),
});
const contentDigest = await hasha.async(content, { algorithm: 'sha256' });
const contentDigest = toSha256(content);

const digestAsset = await githubReleaseAttachments.findDigestAsset(
release,
Expand Down Expand Up @@ -147,9 +147,7 @@ describe('modules/datasource/github-release-attachments/digest', () => {
const release = releaseMock.withAssets('v1.0.1', {
'asset.zip': updatedContent,
});
const contentDigest = await hasha.async(updatedContent, {
algorithm: 'sha256',
});
const contentDigest = toSha256(updatedContent);

const digest = await githubReleaseAttachments.mapDigestAssetToRelease(
digestAsset,
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/datasource/rubygems/metadata-cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import hasha from 'hasha';
import * as packageCache from '../../../util/cache/package';
import { toSha256 } from '../../../util/hash';
import type { Http } from '../../../util/http';
import { AsyncResult, Result } from '../../../util/result';
import { parseUrl } from '../../../util/url';
Expand All @@ -21,7 +21,7 @@ export class MetadataCache {
): Promise<ReleaseResult> {
const cacheNs = `datasource-rubygems`;
const cacheKey = `metadata-cache:${registryUrl}:${packageName}`;
const hash = hasha(versions, { algorithm: 'sha256' });
const hash = toSha256(versions.join(''));

const loadCache = (): AsyncResult<ReleaseResult, unknown> =>
Result.wrapNullable(
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/platform/pr-body.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import hasha from 'hasha';
import { toSha256 } from '../../util/hash';
import { getPrBodyStruct, hashBody } from './pr-body';

describe('modules/platform/pr-body', () => {
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('modules/platform/pr-body', () => {

it('returns raw config hash', () => {
const config = '{}';
const rawConfigHash = hasha(config, { algorithm: 'sha256' });
const rawConfigHash = toSha256(config);
const input = `<!--renovate-config-hash:${rawConfigHash}-->`;
const hash = hashBody(input);
expect(getPrBodyStruct(input)).toEqual({
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/platform/pr-body.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import is from '@sindresorhus/is';
import hasha from 'hasha';
import { logger } from '../../logger';
import { stripEmojis } from '../../util/emoji';
import { toSha256 } from '../../util/hash';
import { regEx } from '../../util/regex';
import { fromBase64 } from '../../util/string';
import type { PrBodyStruct } from './types';
Expand Down Expand Up @@ -31,7 +31,7 @@ export function hashBody(body: string | undefined): string {
}
result = stripEmojis(result);
result = noWhitespaceOrHeadings(result);
result = hasha(result, { algorithm: 'sha256' });
result = toSha256(result);
return result;
}

Expand Down
5 changes: 0 additions & 5 deletions lib/util/hasha.ts

This file was deleted.

2 changes: 1 addition & 1 deletion lib/workers/repository/onboarding/pr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { hashBody } from '../../../../modules/platform/pr-body';
import { scm } from '../../../../modules/platform/scm';
import { emojify } from '../../../../util/emoji';
import { getFile } from '../../../../util/git';
import { toSha256 } from '../../../../util/hasha';
import { toSha256 } from '../../../../util/hash';
import * as template from '../../../../util/template';
import type { BranchConfig } from '../../../types';
import {
Expand Down