Skip to content

Commit 4ca050e

Browse files
authored
fix(worker/repository): only set artifacts status when branch was updated (#44597)
* fix(worker/repository): only set artifacts status when branch was updated * test: fix test
1 parent be1027d commit 4ca050e

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

lib/workers/repository/update/branch/index.spec.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import * as _changelog from '../../changelog/index.ts';
3737
import * as _prAutomerge from '../pr/automerge.ts';
3838
import type { ResultWithPr } from '../pr/index.ts';
3939
import * as _prWorker from '../pr/index.ts';
40+
import * as artifacts from './artifacts.ts';
4041
import * as _automerge from './automerge.ts';
4142
import * as _checkExisting from './check-existing.ts';
4243
import * as _commit from './commit.ts';
@@ -949,7 +950,11 @@ describe('workers/repository/update/branch/index', () => {
949950
});
950951

951952
it('returns if branch automerge is pending', async () => {
952-
expect.assertions(1);
953+
expect.assertions(2);
954+
const setArtifactErrorStatus = vi.spyOn(
955+
artifacts,
956+
'setArtifactErrorStatus',
957+
);
953958
getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce(
954959
partial<PackageFilesResult>({
955960
updatedPackageFiles: [partial<FileChange>()],
@@ -972,6 +977,7 @@ describe('workers/repository/update/branch/index', () => {
972977
result: 'done',
973978
commitSha: null,
974979
});
980+
expect(setArtifactErrorStatus).not.toHaveBeenCalled();
975981
});
976982

977983
it('returns if PR creation failed', async () => {
@@ -1027,6 +1033,10 @@ describe('workers/repository/update/branch/index', () => {
10271033
});
10281034

10291035
it('retries setting branch status checks after PR creation', async () => {
1036+
const setArtifactErrorStatus = vi.spyOn(
1037+
artifacts,
1038+
'setArtifactErrorStatus',
1039+
);
10301040
getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce(
10311041
partial<PackageFilesResult>({
10321042
updatedPackageFiles: [partial<FileChange>()],
@@ -1056,6 +1066,7 @@ describe('workers/repository/update/branch/index', () => {
10561066
});
10571067
// Called twice: once before ensurePr, once after PR creation
10581068
expect(platform.setBranchStatus).toHaveBeenCalledTimes(2);
1069+
expect(setArtifactErrorStatus).not.toHaveBeenCalled();
10591070
});
10601071

10611072
it('does not retry setting branch status checks when PR is not created', async () => {
@@ -1091,7 +1102,11 @@ describe('workers/repository/update/branch/index', () => {
10911102
});
10921103

10931104
it('returns if branch exists but updated', async () => {
1094-
expect.assertions(3);
1105+
expect.assertions(4);
1106+
const setArtifactErrorStatus = vi.spyOn(
1107+
artifacts,
1108+
'setArtifactErrorStatus',
1109+
);
10951110
getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce(
10961111
partial<PackageFilesResult>({
10971112
updatedPackageFiles: [partial<FileChange>()],
@@ -1119,10 +1134,15 @@ describe('workers/repository/update/branch/index', () => {
11191134

11201135
expect(automerge.tryBranchAutomerge).toHaveBeenCalledTimes(0);
11211136
expect(prWorker.ensurePr).toHaveBeenCalledTimes(0);
1137+
expect(setArtifactErrorStatus).toHaveBeenCalledTimes(1);
11221138
});
11231139

11241140
it('updates branch when no fingerprint match', async () => {
1125-
expect.assertions(3);
1141+
expect.assertions(4);
1142+
const setArtifactErrorStatus = vi.spyOn(
1143+
artifacts,
1144+
'setArtifactErrorStatus',
1145+
);
11261146
getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce(
11271147
partial<PackageFilesResult>({
11281148
updatedPackageFiles: [partial<FileChange>()],
@@ -1151,6 +1171,7 @@ describe('workers/repository/update/branch/index', () => {
11511171

11521172
expect(automerge.tryBranchAutomerge).toHaveBeenCalledTimes(0);
11531173
expect(prWorker.ensurePr).toHaveBeenCalledTimes(0);
1174+
expect(setArtifactErrorStatus).toHaveBeenCalledTimes(1);
11541175
});
11551176

11561177
it('updates branch when forceRebase=true', async () => {

lib/workers/repository/update/branch/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ import { isScheduledNow } from './schedule.ts';
6060
import { setConfidence, setStability } from './status-checks.ts';
6161

6262
async function setBranchStatusChecks(config: BranchConfig): Promise<void> {
63-
await setArtifactErrorStatus(config);
6463
await setStability(config);
6564
await setConfidence(config);
6665
}
@@ -147,6 +146,7 @@ export async function processBranch(
147146
config.branchPrefixOld!,
148147
);
149148
branchExists = await scm.branchExists(branchName);
149+
// v8 ignore else -- TODO: add test #40625
150150
if (branchExists) {
151151
config.branchName = branchName;
152152
logger.debug('Found existing branch with branchPrefixOld');
@@ -706,6 +706,7 @@ export async function processBranch(
706706
topic: artifactErrorTopic,
707707
});
708708

709+
// v8 ignore else -- TODO: add test #40625
709710
if (!config.artifactNotices?.length) {
710711
await ensureCommentRemoval({
711712
type: 'by-topic',
@@ -742,6 +743,12 @@ export async function processBranch(
742743
// baseBranch is not checked out at the start of processBranch() due to pull/16246
743744
await scm.checkoutBranch(config.baseBranch);
744745
updatesVerified = true;
746+
747+
// only update artifact status if branch was updated
748+
// also do before platform automerge reattempt
749+
if (commitSha) {
750+
await setArtifactErrorStatus(config);
751+
}
745752
}
746753

747754
if (branchPr) {
@@ -762,6 +769,7 @@ export async function processBranch(
762769
});
763770
}
764771
}
772+
// v8 ignore else -- TODO: add test #40625
765773
if (platform.refreshPr) {
766774
await platform.refreshPr(branchPr.number);
767775
}
@@ -1001,6 +1009,7 @@ export async function processBranch(
10011009
commitSha,
10021010
};
10031011
}
1012+
// v8 ignore else -- TODO: add test #40625
10041013
if (ensurePrResult.type === 'with-pr') {
10051014
const { pr } = ensurePrResult;
10061015
branchPr = pr;
@@ -1009,6 +1018,11 @@ export async function processBranch(
10091018
// associate the status with. The earlier call may have been
10101019
// skipped if no pipeline existed yet.
10111020
await setBranchStatusChecks(config);
1021+
1022+
// only update artifact status if branch was updated
1023+
if (commitSha) {
1024+
await setArtifactErrorStatus(config);
1025+
}
10121026
if (config.artifactErrors?.length) {
10131027
logger.warn(
10141028
{ artifactErrors: config.artifactErrors },
@@ -1039,6 +1053,7 @@ export async function processBranch(
10391053
content += `\`\`\`\n${error.stderr!}\n\`\`\`\n\n`;
10401054
});
10411055
content = platform.massageMarkdown(content, config.rebaseLabel);
1056+
// v8 ignore else -- TODO: add test #40625
10421057
if (
10431058
!(
10441059
config.suppressNotifications!.includes('artifactErrors') ||
@@ -1075,6 +1090,7 @@ export async function processBranch(
10751090
if (config.automerge) {
10761091
logger.debug('PR is configured for automerge');
10771092
// skip automerge if there is a new commit since status checks aren't done yet
1093+
// v8 ignore else -- TODO: add test #40625
10781094
if (config.ignoreTests === true || !commitSha) {
10791095
logger.debug('checking auto-merge');
10801096
const prAutomergeResult = await checkAutoMerge(pr, config);

0 commit comments

Comments
 (0)