diff --git a/.github/workflows/pr-size.yml b/.github/workflows/pr-size.yml index 56f49a9511..472d14a625 100644 --- a/.github/workflows/pr-size.yml +++ b/.github/workflows/pr-size.yml @@ -179,32 +179,39 @@ jobs: (response) => response.data, ); - if (files.length >= 3000) { + const isFileListTruncated = files.length >= 3000; + if (isFileListTruncated) { core.warning( - "The GitHub pull request files API may truncate results at 3,000 files; PR size may be undercounted.", + "The GitHub pull request files API may truncate results at 3,000 files; forcing size:XXL.", ); } let testChangedLines = 0; let nonTestChangedLines = 0; - for (const file of files) { - const changedLinesForFile = (file.additions ?? 0) + (file.deletions ?? 0); + if (!isFileListTruncated) { + for (const file of files) { + const changedLinesForFile = (file.additions ?? 0) + (file.deletions ?? 0); - if (changedLinesForFile === 0) { - continue; - } + if (changedLinesForFile === 0) { + continue; + } - if (isTestFile(file.filename)) { - testChangedLines += changedLinesForFile; - continue; - } + if (isTestFile(file.filename)) { + testChangedLines += changedLinesForFile; + continue; + } - nonTestChangedLines += changedLinesForFile; + nonTestChangedLines += changedLinesForFile; + } } - const changedLines = nonTestChangedLines === 0 ? testChangedLines : nonTestChangedLines; - const nextLabelName = resolveSizeLabel(changedLines); + const changedLines = isFileListTruncated + ? 1000 + : (nonTestChangedLines === 0 ? testChangedLines : nonTestChangedLines); + const nextLabelName = isFileListTruncated + ? "size:XXL" + : resolveSizeLabel(changedLines); const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({ owner: context.repo.owner, diff --git a/apps/server/src/git/Layers/GitCore.ts b/apps/server/src/git/Layers/GitCore.ts index a95c1eac8c..21296b4605 100644 --- a/apps/server/src/git/Layers/GitCore.ts +++ b/apps/server/src/git/Layers/GitCore.ts @@ -549,7 +549,20 @@ export const makeGitCore = (options?: { executeOverride?: GitCoreShape["execute" allowNonZeroExit: true, timeoutMs: Duration.toMillis(STATUS_UPSTREAM_REFRESH_TIMEOUT), }, - ).pipe(Effect.asVoid); + ).pipe( + Effect.flatMap((result) => + result.code === 0 + ? Effect.void + : Effect.fail( + createGitCommandError( + "GitCore.fetchUpstreamRefForStatus", + cwd, + ["fetch", "--quiet", "--no-tags", upstream.remoteName, refspec], + `upstream fetch exited with code ${result.code}`, + ), + ), + ), + ); }; const statusUpstreamRefreshCache = yield* Cache.makeWith({ @@ -629,7 +642,7 @@ export const makeGitCore = (options?: { executeOverride?: GitCoreShape["execute" const listRemoteNames = (cwd: string): Effect.Effect, GitCommandError> => runGitStdout("GitCore.listRemoteNames", cwd, ["remote"]).pipe( - Effect.map((stdout) => parseRemoteNames(stdout).toReversed()), + Effect.map((stdout) => parseRemoteNames(stdout)), ); const resolvePrimaryRemoteName = (cwd: string): Effect.Effect => @@ -638,9 +651,10 @@ export const makeGitCore = (options?: { executeOverride?: GitCoreShape["execute" return "origin"; } const remotes = yield* listRemoteNames(cwd); - const [firstRemote] = remotes; - if (firstRemote) { - return firstRemote; + // Prefer "upstream" when "origin" is absent, then fall back to first listed remote. + const preferred = remotes.find((r) => r === "upstream") ?? remotes[0]; + if (preferred) { + return preferred; } return yield* createGitCommandError( "GitCore.resolvePrimaryRemoteName", @@ -943,16 +957,19 @@ export const makeGitCore = (options?: { executeOverride?: GitCoreShape["execute" const prepareCommitContext: GitCoreShape["prepareCommitContext"] = (cwd, filePaths) => Effect.gen(function* () { - if (filePaths && filePaths.length > 0) { + if (filePaths !== undefined && filePaths !== null) { yield* runGit("GitCore.prepareCommitContext.reset", cwd, ["reset"]).pipe( Effect.catch(() => Effect.void), ); - yield* runGit("GitCore.prepareCommitContext.addSelected", cwd, [ - "add", - "-A", - "--", - ...filePaths, - ]); + if (filePaths.length > 0) { + yield* runGit("GitCore.prepareCommitContext.addSelected", cwd, [ + "add", + "-A", + "--", + ...filePaths, + ]); + } + // filePaths is an explicit empty array — leave the index empty. } else { yield* runGit("GitCore.prepareCommitContext.addAll", cwd, ["add", "-A"]); }