Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bazel run //examples/server/gateway:gateway
bazel test //...

# Run tests with verbose output
bazel test //... --test_output=all --test_arg=-v
bazel test //... --test_output=all --test_arg=-test.v
```

### Dependency Management
Expand Down
31 changes: 14 additions & 17 deletions entities/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,33 @@ import (
)

// RequestLandStrategy defines the possible source control integration methods.
type RequestLandStrategy int
type RequestLandStrategy string

// do not use iota here, as values should be fixed and consistent across versions.
const (
// RequestLandStrategyDefault lets the server decide based on configuration.
RequestLandStrategyDefault RequestLandStrategy = 0
// RequestLandStrategyUnknown is the unknown strategy. It is set by default when the structure is initialized. It should never be seen in the system and used for error control.
RequestLandStrategyUnknown RequestLandStrategy = ""
// RequestLandStrategyRebase rebases commits onto the target branch before landing.
RequestLandStrategyRebase RequestLandStrategy = 1
// RequestLandStrategySquashRebase squashes commits into a single commit before rebase.
RequestLandStrategySquashRebase RequestLandStrategy = 2
RequestLandStrategyRebase RequestLandStrategy = "rebase"
// RequestLandStrategySquashRebase squashes commits into a single commit before rebasing on top of the target branch.
RequestLandStrategySquashRebase RequestLandStrategy = "squash_rebase"
// RequestLandStrategyMerge merges commits into the target branch by creating a separate merge commit, preserving the commit history along with hashes.
RequestLandStrategyMerge RequestLandStrategy = 3
RequestLandStrategyMerge RequestLandStrategy = "merge"
)

// RequestState defines the possible states of a land request.
type RequestState int
type RequestState string

// TODO: define all states
// do not use iota here, as values should be fixed and consistent across versions.
const (
// RequestStateUnknown is the unreachable state. It is set by default when the structure is initialized. It should never be seen in the system.
RequestStateUnknown RequestState = 0
RequestStateUnknown RequestState = ""
// RequestStateNew is the initial state of a land request. It is confirmed by the system but the processing is not started yet.
RequestStateNew RequestState = 1
RequestStateNew RequestState = "new"
// RequestStateProcessing is the state of a land request that is being processed.
RequestStateProcessing RequestState = 2
RequestStateProcessing RequestState = "processing"
// RequestStateLanded is the state of a land request that has been successfully processed and landed. This is the final state.
RequestStateLanded RequestState = 3
RequestStateLanded RequestState = "landed"
// RequestStateError is the state of a land request that has encountered an error. This is the final state.
RequestStateError RequestState = 4
RequestStateError RequestState = "error"
)

// Change represents a set of related code changes identified by one or more IDs from a particular code change provider, like Github Pull Requests.
Expand All @@ -61,7 +58,7 @@ type Request struct {
Seq int64
// Change is a number of code changes (such as pull requests) to land into the target branch. Target branch is defined by the queue configuration.
Change Change
// LandStrategy is the source control integration strategy to use for this land operation. If not specified, the default queue strategy is used.
// LandStrategy is the source control integration strategy to use for this land operation.
LandStrategy RequestLandStrategy

// ****************
Expand Down
4 changes: 2 additions & 2 deletions extensions/storage/mysql/schema/request.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ CREATE TABLE IF NOT EXISTS request (
seq BIGINT NOT NULL,
change_source VARCHAR(255) NOT NULL,
change_ids JSON NOT NULL,
land_strategy INT NOT NULL,
state INT NOT NULL,
land_strategy VARCHAR(64) NOT NULL,
state VARCHAR(64) NOT NULL,
version INT NOT NULL,
PRIMARY KEY (queue, seq)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
29 changes: 27 additions & 2 deletions gateway/controller/land.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ func (c *LandController) Land(ctx context.Context, req *pb.LandRequest) (*pb.Lan
Source: req.Change.GetSource(),
IDs: req.Change.GetIds(),
}
strategy := entities.RequestLandStrategy(int(req.Strategy))

request, err := c.storeFactory.GetRequestStore().Create(ctx, req.Queue, change, strategy, entities.RequestStateNew)
// TODO: validate that queue is configured. Return error if not.
queue := req.Queue

// TODO: pass default queue land strategy to resolver function to process a default.
strategy, err := resolveRequestLandStrategy(req.Strategy)
if err != nil {
return nil, fmt.Errorf("LandController failed to map strategy for queue=%s: %w", req.Queue, err)
}

request, err := c.storeFactory.GetRequestStore().Create(ctx, queue, change, strategy, entities.RequestStateNew)
if err != nil {
return nil, fmt.Errorf("LandController failed to create request for queue=%s: %w", req.Queue, err)
}
Expand All @@ -59,3 +67,20 @@ func (c *LandController) Land(ctx context.Context, req *pb.LandRequest) (*pb.Lan
Sqid: sqid,
}, nil
}

// protoStrategyToEntity maps a proto Strategy enum to the entity RequestLandStrategy.
func resolveRequestLandStrategy(s pb.Strategy) (entities.RequestLandStrategy, error) {
switch s {
case pb.Strategy_DEFAULT:
// TODO: resolve default strategy based on queue configuration
return entities.RequestLandStrategyRebase, nil
case pb.Strategy_REBASE:
return entities.RequestLandStrategyRebase, nil
case pb.Strategy_SQUASH_REBASE:
return entities.RequestLandStrategySquashRebase, nil
case pb.Strategy_MERGE:
return entities.RequestLandStrategyMerge, nil
default:
return entities.RequestLandStrategyUnknown, fmt.Errorf("unknown proto strategy: %v", s)
}
}
2 changes: 1 addition & 1 deletion gateway/controller/land_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestLand_PassesCorrectParametersToStore(t *testing.T) {
req := &pb.LandRequest{
Queue: "my-queue",
Change: &pb.Change{Source: "github", Ids: []string{"pr-1", "pr-2"}},
Strategy: pb.Strategy_STRATEGY_REBASE,
Strategy: pb.Strategy_REBASE,
}
resp, err := controller.Land(ctx, req)

Expand Down
8 changes: 4 additions & 4 deletions gateway/proto/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ message PingResponse {
// Strategy defines the possible source control integration methods
enum Strategy {
// Default strategy (let server decide based on configuration)
STRATEGY_DEFAULT = 0;
DEFAULT = 0;
// Rebase commits onto target branch before landing
STRATEGY_REBASE = 1;
REBASE = 1;
// Same as REBASE but squash commits into a single commit before rebase
STRATEGY_SQUASH_REBASE = 2;
SQUASH_REBASE = 2;
// Merge commits into the target branch by creating a separate merge commit, preserving the commit history along with hashes
STRATEGY_MERGE = 3;
MERGE = 3;
}

// Change represents a set of related code changes identified by one or more IDs from a particular code change provider, like Github Pull Requests.
Expand Down
39 changes: 20 additions & 19 deletions gateway/protopb/gateway.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 31 additions & 32 deletions gateway/protopb/gateway.pb.yarpc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration_tests/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (s *IntegrationSuite) TestLandRequest() {
req := &gatewaypb.LandRequest{
Queue: "integration-test-queue",
Change: &gatewaypb.Change{Source: "github", Ids: []string{"pr-100", "pr-101"}},
Strategy: gatewaypb.Strategy_STRATEGY_REBASE,
Strategy: gatewaypb.Strategy_REBASE,
}

s.log.logf("Sending Land request for queue=%s", req.Queue)
Expand Down