Files
renovate/lib/modules/platform/default-scm.spec.ts
Jamie Tanna f932d52fbd feat(platform): get all branch update dates in a more performant manner (#44582)
* feat(platform): get all branch update dates in a more performant manner

When Renovate is working on a repository with many /potential/ branches,
as well as some actually created branches, it's possible for the
calculation for `commitHourlyLimit` to end up taking significant time.

This can lead to a less performant job generally, but can sometimes lead
to the Renovate job failing to complete, and then timing out when
executed by a job runner.

To handle this, we can instead use use `git for-each-ref` to look up
each Git ref (remotely) and request the commit date, which leads to a
much more performant lookup.

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>

* fixup! feat(platform): get all branch update dates in a more performant manner

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>

* fixup! Merge remote-tracking branch 'origin/HEAD' into wip/commit-hourly-slow

---------

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
2026-07-21 13:17:58 +00:00

98 lines
3.6 KiB
TypeScript

import { fakeSha, git, partial } from '~test/util.ts';
import { RENOVATE_FORK_UPSTREAM } from '../../util/git/index.ts';
import type { CommitFilesConfig } from '../../util/git/types.ts';
import { DefaultGitScm } from './default-scm.ts';
describe('modules/platform/default-scm', () => {
const defaultGitScm = new DefaultGitScm();
it('delegate branchExists to util/git', async () => {
git.branchExists.mockReturnValueOnce(true);
await defaultGitScm.branchExists('branchName');
expect(git.branchExists).toHaveBeenCalledTimes(1);
});
it('delegate commitAndPush to util/git', async () => {
git.commitFiles.mockResolvedValueOnce(fakeSha('sha'));
await defaultGitScm.commitAndPush(partial<CommitFilesConfig>());
expect(git.commitFiles).toHaveBeenCalledTimes(1);
});
it('delegate deleteBranch to util/git', async () => {
git.deleteBranch.mockResolvedValueOnce();
await defaultGitScm.deleteBranch('branchName');
expect(git.deleteBranch).toHaveBeenCalledTimes(1);
});
it('delegate getBranchCommit to util/git', async () => {
git.getBranchCommit.mockReturnValueOnce(fakeSha('sha'));
await defaultGitScm.getBranchCommit('branchName');
expect(git.getBranchCommit).toHaveBeenCalledTimes(1);
});
it('delegate getBranchUpdateDate to util/git', async () => {
git.getBranchUpdateDate.mockResolvedValueOnce(null);
await defaultGitScm.getBranchUpdateDate('branchName');
expect(git.getBranchUpdateDate).toHaveBeenCalledTimes(1);
});
it('delegate getAllBranchUpdateDates to util/git', async () => {
git.getAllBranchUpdateDates.mockResolvedValueOnce({});
await defaultGitScm.getAllBranchUpdateDates();
expect(git.getAllBranchUpdateDates).toHaveBeenCalledTimes(1);
});
it('delegate isBranchBehindBase to util/git', async () => {
git.isBranchBehindBase.mockResolvedValueOnce(true);
await defaultGitScm.isBranchBehindBase('abc', 'main');
expect(git.isBranchBehindBase).toHaveBeenCalledTimes(1);
});
it('delegate isBranchConflicted to util/git', async () => {
git.isBranchConflicted.mockResolvedValueOnce(true);
await defaultGitScm.isBranchConflicted('main', 'abc');
expect(git.isBranchConflicted).toHaveBeenCalledTimes(1);
});
it('delegate isBranchModified to util/git', async () => {
git.isBranchModified.mockResolvedValueOnce(true);
await defaultGitScm.isBranchModified('branchName', 'main');
expect(git.isBranchModified).toHaveBeenCalledTimes(1);
});
it('delegate getFileList to util/git', async () => {
git.getFileList.mockResolvedValueOnce([]);
await defaultGitScm.getFileList();
expect(git.getFileList).toHaveBeenCalledTimes(1);
});
it('delegate checkoutBranch to util/git', async () => {
git.checkoutBranch.mockResolvedValueOnce(fakeSha('sha'));
await defaultGitScm.checkoutBranch('branchName');
expect(git.checkoutBranch).toHaveBeenCalledTimes(1);
});
it('delegate mergeAndPush to util/git', async () => {
git.mergeBranch.mockResolvedValueOnce();
await defaultGitScm.mergeAndPush('branchName');
expect(git.mergeBranch).toHaveBeenCalledExactlyOnceWith('branchName');
});
it('delegate mergeBranch to util/git', async () => {
git.mergeToLocal.mockResolvedValueOnce();
await defaultGitScm.mergeToLocal('branchName');
expect(git.mergeToLocal).toHaveBeenCalledExactlyOnceWith('branchName');
});
it('syncs fork with upstream', async () => {
git.getRemotes.mockResolvedValueOnce([
'somebranch',
RENOVATE_FORK_UPSTREAM,
]);
await defaultGitScm.syncForkWithUpstream('branchName');
expect(git.syncForkWithUpstream).toHaveBeenCalledExactlyOnceWith(
'branchName',
);
});
});