Skip to content

Commit d29d274

Browse files
committed
fix(auto-replace): fix issues when updating digest and version
Also do `replaceWithoutReplaceString` if `replaceString` is missing and more than one value changed (e.g. `digest` and `version`). See #36461 and the regression test.
1 parent 39ce284 commit d29d274

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

lib/workers/repository/update/branch/auto-replace.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,29 @@ export async function doAutoReplace(
224224
if (reuseExistingBranch) {
225225
return await checkExistingBranch(upgrade, existingContent);
226226
}
227+
228+
// check if current !== newString and return 1 if it does or 0 if it doesn't
229+
const updatedToInt = (
230+
current: string | undefined,
231+
newString: string | undefined,
232+
): number => (current && newString && newString !== current ? 1 : 0);
233+
// count how many strings need to be updated
234+
const changedCount =
235+
updatedToInt(depName, newName) +
236+
updatedToInt(currentValue, newValue) +
237+
updatedToInt(currentDigest, newDigest) +
238+
updatedToInt(currentDigestShort, newDigest);
239+
logger.debug(
240+
{ packageFile, depName, changedCount },
241+
'N values changed and need to be updated',
242+
);
243+
227244
const replaceWithoutReplaceString =
228-
is.string(newName) &&
229-
newName !== depName &&
230-
(is.undefined(upgrade.replaceString) ||
231-
!upgrade.replaceString?.includes(depName!));
245+
(is.string(newName) &&
246+
newName !== depName &&
247+
(is.undefined(upgrade.replaceString) ||
248+
!upgrade.replaceString?.includes(depName!))) ||
249+
(is.undefined(upgrade.replaceString) && changedCount > 1);
232250
const replaceString = upgrade.replaceString ?? currentValue ?? currentDigest;
233251
logger.trace({ depName, replaceString }, 'autoReplace replaceString');
234252
let searchIndex: number;

0 commit comments

Comments
 (0)