Skip to content

Commit b46e38a

Browse files
authored
feat(platform): Add gitworkspace extension for pluggable git command execution (#765)
## Why? Today, each merger backend (OSS git CLI, alternative deployments) reimplements the same orchestration logic with its own git execution layer. Workspace extracts that layer into a pluggable contract so the merger can be written once. The local subprocess implementation follows in a separate PR. ## What? Adds `platform/extension/gitworkspace/` — a `Workspace` interface for executing batched git commands in a stateful environment, with a `Factory` to create per-repo instances. Includes generated mock. ## Test Plan - `make check-gazelle` — BUILD files in sync - `bazel build //platform/extension/gitworkspace:go_default_library` — interface compiles - Mock generates and compiles (consumer tests come with the local impl and merger refactor PRs) ## Issue
1 parent fe7faa0 commit b46e38a

4 files changed

Lines changed: 187 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("@rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = ["gitworkspace.go"],
6+
importpath = "github.com/uber/submitqueue/platform/extension/gitworkspace",
7+
visibility = ["//visibility:public"],
8+
)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2026 Uber Technologies, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package gitworkspace defines the pluggable interface for executing git
16+
// commands in a stateful workspace. The OSS implementation runs commands as
17+
// local subprocesses; alternative deployments wrap their backend's exec API
18+
// in the same contract.
19+
package gitworkspace
20+
21+
//go:generate mockgen -source=gitworkspace.go -destination=mock/gitworkspace_mock.go -package=mock
22+
23+
import "context"
24+
25+
// Command is one command to execute in a git workspace.
26+
type Command struct {
27+
// Alias identifies this command's Output in the response.
28+
Alias string
29+
// Bin is the executable name.
30+
Bin string
31+
// Args are the command-line arguments.
32+
Args []string
33+
// Stdin is optional standard input.
34+
Stdin string
35+
}
36+
37+
// Output is the result of one executed command.
38+
type Output struct {
39+
// Alias matches the Command that produced this output.
40+
Alias string
41+
// ExitCode is the process exit code (0 = success, -1 = skipped).
42+
ExitCode int32
43+
// Stdout is the captured standard output.
44+
Stdout string
45+
// Stderr is the captured standard error.
46+
Stderr string
47+
}
48+
49+
// Workspace is a stateful git environment where command batches execute
50+
// sequentially. Commands within one Exec call run in order; a non-zero
51+
// exit code skips the remaining commands in that batch. State persists
52+
// across Exec calls on the same Workspace.
53+
type Workspace interface {
54+
// Exec sends a batch of commands and returns their outputs.
55+
Exec(commands []Command) ([]Output, error)
56+
// Close releases the workspace and its resources.
57+
Close() error
58+
}
59+
60+
// Factory creates Workspace instances bound to a repository.
61+
type Factory interface {
62+
// For returns a Workspace for the given repository.
63+
For(ctx context.Context, repo string) (Workspace, error)
64+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = ["gitworkspace_mock.go"],
6+
importpath = "github.com/uber/submitqueue/platform/extension/gitworkspace/mock",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//platform/extension/gitworkspace:go_default_library",
10+
"@org_uber_go_mock//gomock:go_default_library",
11+
],
12+
)

‎platform/extension/gitworkspace/mock/gitworkspace_mock.go‎

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)