Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: use util/fingerprint for branches
  • Loading branch information
rarkins committed Oct 6, 2022
commit ceb34cb9e336fe0d009a167e3ea2ce9cc15ae294
24 changes: 12 additions & 12 deletions lib/workers/repository/process/write.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import is from '@sindresorhus/is';
import hasha from 'hasha';
import {
RenovateConfig,
getConfig,
Expand All @@ -16,6 +15,7 @@ import type {
BranchCache,
RepoCacheData,
} from '../../../util/cache/repository/types';
import { fingerprint } from '../../../util/fingerprint';
import { Limit, isLimitReached } from '../../global/limits';
import { BranchConfig, BranchResult, BranchUpgradeConfig } from '../../types';
import * as _branchWorker from '../update/branch';
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('workers/repository/process/write', () => {
result: BranchResult.Done,
commitSha: 'some-value',
});
const branchManagersFingerprint = hasha(
const branchManagersFingerprint = fingerprint(
[
...new Set(
branches[0].upgrades
Expand All @@ -175,12 +175,12 @@ describe('workers/repository/process/write', () => {
),
].sort()
);
const fingerprint = hasha([
JSON.stringify(branches[0]),
const branchFingerprint = fingerprint({
branches: JSON.stringify(branches[0]),
branchManagersFingerprint,
]);
});
expect(await writeUpdates(config, branches)).toBe('done');
expect(branches[0].branchFingerprint).toBe(fingerprint);
expect(branches[0].branchFingerprint).toBe(branchFingerprint);
});

it('caches same fingerprint when no commit is made', async () => {
Expand All @@ -196,7 +196,7 @@ describe('workers/repository/process/write', () => {
],
},
]);
const branchManagersFingerprint = hasha(
const branchManagersFingerprint = fingerprint(
[
...new Set(
branches[0].upgrades
Expand All @@ -205,16 +205,16 @@ describe('workers/repository/process/write', () => {
),
].sort()
);
const fingerprint = hasha([
JSON.stringify(branches[0]),
const branchFingerprint = fingerprint({
branches: JSON.stringify(branches[0]),
branchManagersFingerprint,
]);
});
repoCache.getCache.mockReturnValueOnce({
branches: [
{
branchName: 'new/some-branch',
baseBranch: 'base_branch',
branchFingerprint: fingerprint,
branchFingerprint,
} as BranchCache,
],
});
Expand All @@ -223,7 +223,7 @@ describe('workers/repository/process/write', () => {
result: BranchResult.Done,
});
expect(await writeUpdates(config, branches)).toBe('done');
expect(branches[0].branchFingerprint).toBe(fingerprint);
expect(branches[0].branchFingerprint).toBe(branchFingerprint);
});

it('creates new branchCache when cache is not enabled', async () => {
Expand Down
11 changes: 5 additions & 6 deletions lib/workers/repository/process/write.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import is from '@sindresorhus/is';
import hasha from 'hasha';
import stringify from 'safe-stable-stringify';
import type { RenovateConfig } from '../../../config/types';
import { addMeta, logger, removeMeta } from '../../../logger';
import { hashMap } from '../../../modules/manager';
import { getCache } from '../../../util/cache/repository';
import type { BranchCache } from '../../../util/cache/repository/types';
import { fingerprint } from '../../../util/fingerprint';
import { branchExists, getBranchCommit } from '../../../util/git';
import { setBranchNewCommit } from '../../../util/git/set-branch-commit';
import { Limit, incLimitedValue, setMaxLimit } from '../../global/limits';
Expand Down Expand Up @@ -124,7 +123,7 @@ export async function writeUpdates(
// TODO: base branch name cannot be undefined - fix optional types (#7154)
const branchState = syncBranchState(branchName, baseBranch!);

const branchManagersFingerprint = hasha(
const branchManagersFingerprint = fingerprint(
[
...new Set(
branch.upgrades
Expand All @@ -133,10 +132,10 @@ export async function writeUpdates(
),
].sort()
);
const branchFingerprint = hasha([
stringify(branch),
const branchFingerprint = fingerprint({
branch,
branchManagersFingerprint,
]);
});
branch.skipBranchUpdate = canSkipBranchUpdateCheck(
branchState,
branchFingerprint
Expand Down