feat(projects): automatically pull clean default branches #9277
Mergedmaria-rcksmerged 4 commits into
main fromrefs/pull/9277/headmerged by maria-rcks View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/server.ts lines 327 to 339OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -322,3 +324,16 @@322324 Layer.provideMerge(GitLayerLive),323325 );324326327+const VcsAutoPullPolicyLive = Layer.effect(328+ VcsStatusBroadcaster.VcsAutoPullPolicy,329+ Effect.gen(function* () {330+ const snapshots = yield* ProjectionSnapshotQuery.ProjectionSnapshotQuery;331+ return {332+ isEnabled: (cwd: string) =>333+ snapshots.getActiveProjectByWorkspaceRoot(cwd).pipe(334+ Effect.map((project) => Option.isSome(project) && project.value.autoPull === true),335+ Effect.orElseSucceed(() => false),336+ ),337+ };338+ }),339+);apps/server/src/serverRuntimeStartup.ts lines 639 to 641OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -634,3 +636,6 @@634636 readonly abort?: (error: ServerRuntimeStartupError) => Effect.Effect<void>;635637 }636638639+export const autoPullProjects = Effect.fn("autoPullProjects")(function* (640+ projects: ReadonlyArray<OrchestrationProjectShell>,641+ git: GitVcsDriver.GitVcsDriver["Service"],
- apps/server/src/vcs/VcsStatusBroadcaster.ts line 402Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -356 +363,21 @@356363364+ const maybeAutoPull = Effect.fn("VcsStatusBroadcaster.maybeAutoPull")(function* (365+ cwd: string,366+ remote: VcsStatusRemoteResult | null,367+ ) {368+ return yield* Effect.gen(function* () {369+ if (370+ remote === null ||371+ !remote.hasUpstream ||372+ remote.aheadCount > 0 ||373+ remote.behindCount <= 0 ||374+ !(yield* autoPullPolicy.isEnabled(cwd))375+ ) {376+ return null;377+ }378+379+ yield* workflow.invalidateLocalStatus(cwd);380+ const local = yield* workflow.localStatus({ cwd });381+ if (!local.isRepo || !local.isDefaultRef || local.hasWorkingTreeChanges) return null;382+383+ yield* workflow.pullCurrentBranch(cwd);
- @@ -139,3 +140,16 @@139140 readonly automaticRemoteRefreshInterval?: Effect.Effect<Duration.Duration, never>;140141 }141142143+export class VcsAutoPullPolicy extends Context.Reference<{144+ readonly isEnabled: (cwd: string) => Effect.Effect<boolean, never>;145+}>("t3/vcs/VcsAutoPullPolicy", {146+ defaultValue: () => ({ isEnabled: () => Effect.succeed(false) }),147+}) {}148+149+export const autoPullPolicyLayer = Layer.effect(150+ VcsAutoPullPolicy,151+ Effect.gen(function* () {152+ const snapshots = yield* ProjectionSnapshotQuery.ProjectionSnapshotQuery;153+ return {154+ isEnabled: (cwd: string) =>155+ snapshots.getActiveProjectByWorkspaceRoot(cwd).pipe(
- apps/server/src/serverRuntimeStartup.ts line 680Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -636,0 +660,21 @@660+ status.hasWorkingTreeChanges ||661+ status.aheadCount > 0662+ ) {663+ yield* Effect.logDebug("Skipped automatic project pull", {664+ cwd,665+ reason: !status.isRepo666+ ? "not-a-repository"667+ : !status.isDefaultBranch668+ ? "not-on-default-branch"669+ : !status.hasUpstream670+ ? "no-upstream"671+ : status.hasWorkingTreeChanges672+ ? "working-tree-changes"673+ : "local-commits",674+ });675+ return;676+ }677+678+ if (status.behindCount <= 0) return;679+680+ const result = yield* git.pullCurrentBranch(cwd);apps/server/src/vcs/VcsStatusBroadcaster.ts line 156Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -139,3 +140,17 @@139140 readonly automaticRemoteRefreshInterval?: Effect.Effect<Duration.Duration, never>;140141 }141142143+export class VcsAutoPullPolicy extends Context.Reference<{144+ readonly isEnabled: (cwd: string) => Effect.Effect<boolean, never>;145+}>("t3/vcs/VcsAutoPullPolicy", {146+ defaultValue: () => ({ isEnabled: () => Effect.succeed(false) }),147+}) {}148+149+export const autoPullPolicyLayer = Layer.effect(150+ VcsAutoPullPolicy,151+ Effect.gen(function* () {152+ const snapshots = yield* ProjectionSnapshotQuery.ProjectionSnapshotQuery;153+ return {154+ isEnabled: (cwd: string) =>155+ snapshots.getActiveProjectByWorkspaceRoot(cwd).pipe(156+ Effect.map((project) => project._tag === "Some" && project.value.autoPull === true),
maria-rcks merged thisba3cb07
maria-rcks closed this
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed