From 6526f765019d79c494e9cfe85c4f383abab494ae Mon Sep 17 00:00:00 2001 From: Huiwen Date: Wed, 15 Nov 2023 18:20:31 +0000 Subject: [PATCH] Add context service --- components/public-api/gitpod/v1/context.proto | 24 ++ .../public-api/gitpod/v1/workspace.proto | 3 + components/public-api/go/v1/context.pb.go | 305 ++++++++++++++++++ .../public-api/go/v1/context_grpc.pb.go | 111 +++++++ .../go/v1/v1connect/context.connect.go | 92 ++++++ .../go/v1/v1connect/context.proxy.connect.go | 30 ++ components/public-api/go/v1/workspace.pb.go | 3 + .../src/gitpod/v1/context_connect.ts | 33 ++ .../typescript/src/gitpod/v1/context_pb.ts | 136 ++++++++ .../typescript/src/gitpod/v1/workspace_pb.ts | 4 + 10 files changed, 741 insertions(+) create mode 100644 components/public-api/gitpod/v1/context.proto create mode 100644 components/public-api/go/v1/context.pb.go create mode 100644 components/public-api/go/v1/context_grpc.pb.go create mode 100644 components/public-api/go/v1/v1connect/context.connect.go create mode 100644 components/public-api/go/v1/v1connect/context.proxy.connect.go create mode 100644 components/public-api/typescript/src/gitpod/v1/context_connect.ts create mode 100644 components/public-api/typescript/src/gitpod/v1/context_pb.ts diff --git a/components/public-api/gitpod/v1/context.proto b/components/public-api/gitpod/v1/context.proto new file mode 100644 index 00000000000000..003d15bc06edae --- /dev/null +++ b/components/public-api/gitpod/v1/context.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +package gitpod.v1; + +option go_package = "github.com/gitpod-io/gitpod/components/public-api/go/v1"; + +service ContextService { + // ParseContext parses the url and returns the context + rpc ParseContext(ParseContextRequest) returns (ParseContextResponse) {} +} + +message ParseContextRequest { + string url = 1; +} + +message ParseContextResponse { + Context context = 1; +} + +message Context { + string title = 1; + string normalized_url = 2; + string ref = 3; +} diff --git a/components/public-api/gitpod/v1/workspace.proto b/components/public-api/gitpod/v1/workspace.proto index 7595fbcc892ec9..f6054e7766b639 100644 --- a/components/public-api/gitpod/v1/workspace.proto +++ b/components/public-api/gitpod/v1/workspace.proto @@ -88,6 +88,9 @@ message CreateAndStartWorkspaceRequest { string create_local_branch = 3; } + // git describes the source refer of workspace + // Obtain available git using the ContextService.ParseContext operation if + // not sure about it. Git git = 1; } diff --git a/components/public-api/go/v1/context.pb.go b/components/public-api/go/v1/context.pb.go new file mode 100644 index 00000000000000..f5585f75096875 --- /dev/null +++ b/components/public-api/go/v1/context.pb.go @@ -0,0 +1,305 @@ +// Copyright (c) 2023 Gitpod GmbH. All rights reserved. +// Licensed under the GNU Affero General Public License (AGPL). +// See License.AGPL.txt in the project root for license information. + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc (unknown) +// source: gitpod/v1/context.proto + +package v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type ParseContextRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"` +} + +func (x *ParseContextRequest) Reset() { + *x = ParseContextRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_gitpod_v1_context_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ParseContextRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ParseContextRequest) ProtoMessage() {} + +func (x *ParseContextRequest) ProtoReflect() protoreflect.Message { + mi := &file_gitpod_v1_context_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ParseContextRequest.ProtoReflect.Descriptor instead. +func (*ParseContextRequest) Descriptor() ([]byte, []int) { + return file_gitpod_v1_context_proto_rawDescGZIP(), []int{0} +} + +func (x *ParseContextRequest) GetUrl() string { + if x != nil { + return x.Url + } + return "" +} + +type ParseContextResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Context *Context `protobuf:"bytes,1,opt,name=context,proto3" json:"context,omitempty"` +} + +func (x *ParseContextResponse) Reset() { + *x = ParseContextResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_gitpod_v1_context_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ParseContextResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ParseContextResponse) ProtoMessage() {} + +func (x *ParseContextResponse) ProtoReflect() protoreflect.Message { + mi := &file_gitpod_v1_context_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ParseContextResponse.ProtoReflect.Descriptor instead. +func (*ParseContextResponse) Descriptor() ([]byte, []int) { + return file_gitpod_v1_context_proto_rawDescGZIP(), []int{1} +} + +func (x *ParseContextResponse) GetContext() *Context { + if x != nil { + return x.Context + } + return nil +} + +type Context struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + NormalizedUrl string `protobuf:"bytes,2,opt,name=normalized_url,json=normalizedUrl,proto3" json:"normalized_url,omitempty"` + Ref string `protobuf:"bytes,3,opt,name=ref,proto3" json:"ref,omitempty"` +} + +func (x *Context) Reset() { + *x = Context{} + if protoimpl.UnsafeEnabled { + mi := &file_gitpod_v1_context_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Context) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Context) ProtoMessage() {} + +func (x *Context) ProtoReflect() protoreflect.Message { + mi := &file_gitpod_v1_context_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Context.ProtoReflect.Descriptor instead. +func (*Context) Descriptor() ([]byte, []int) { + return file_gitpod_v1_context_proto_rawDescGZIP(), []int{2} +} + +func (x *Context) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *Context) GetNormalizedUrl() string { + if x != nil { + return x.NormalizedUrl + } + return "" +} + +func (x *Context) GetRef() string { + if x != nil { + return x.Ref + } + return "" +} + +var File_gitpod_v1_context_proto protoreflect.FileDescriptor + +var file_gitpod_v1_context_proto_rawDesc = []byte{ + 0x0a, 0x17, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6f, 0x6e, 0x74, + 0x65, 0x78, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x67, 0x69, 0x74, 0x70, 0x6f, + 0x64, 0x2e, 0x76, 0x31, 0x22, 0x27, 0x0a, 0x13, 0x50, 0x61, 0x72, 0x73, 0x65, 0x43, 0x6f, 0x6e, + 0x74, 0x65, 0x78, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x75, + 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22, 0x44, 0x0a, + 0x14, 0x50, 0x61, 0x72, 0x73, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, + 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, + 0x65, 0x78, 0x74, 0x22, 0x58, 0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x12, 0x14, + 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, + 0x69, 0x74, 0x6c, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x69, 0x7a, + 0x65, 0x64, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6e, 0x6f, + 0x72, 0x6d, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x55, 0x72, 0x6c, 0x12, 0x10, 0x0a, 0x03, 0x72, + 0x65, 0x66, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x65, 0x66, 0x32, 0x63, 0x0a, + 0x0e, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, + 0x51, 0x0a, 0x0c, 0x50, 0x61, 0x72, 0x73, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x12, + 0x1e, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x72, 0x73, + 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x1f, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x72, 0x73, + 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x00, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2d, 0x69, 0x6f, 0x2f, 0x67, 0x69, 0x74, 0x70, 0x6f, + 0x64, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x70, 0x75, 0x62, + 0x6c, 0x69, 0x63, 0x2d, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x6f, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_gitpod_v1_context_proto_rawDescOnce sync.Once + file_gitpod_v1_context_proto_rawDescData = file_gitpod_v1_context_proto_rawDesc +) + +func file_gitpod_v1_context_proto_rawDescGZIP() []byte { + file_gitpod_v1_context_proto_rawDescOnce.Do(func() { + file_gitpod_v1_context_proto_rawDescData = protoimpl.X.CompressGZIP(file_gitpod_v1_context_proto_rawDescData) + }) + return file_gitpod_v1_context_proto_rawDescData +} + +var file_gitpod_v1_context_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_gitpod_v1_context_proto_goTypes = []interface{}{ + (*ParseContextRequest)(nil), // 0: gitpod.v1.ParseContextRequest + (*ParseContextResponse)(nil), // 1: gitpod.v1.ParseContextResponse + (*Context)(nil), // 2: gitpod.v1.Context +} +var file_gitpod_v1_context_proto_depIdxs = []int32{ + 2, // 0: gitpod.v1.ParseContextResponse.context:type_name -> gitpod.v1.Context + 0, // 1: gitpod.v1.ContextService.ParseContext:input_type -> gitpod.v1.ParseContextRequest + 1, // 2: gitpod.v1.ContextService.ParseContext:output_type -> gitpod.v1.ParseContextResponse + 2, // [2:3] is the sub-list for method output_type + 1, // [1:2] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_gitpod_v1_context_proto_init() } +func file_gitpod_v1_context_proto_init() { + if File_gitpod_v1_context_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_gitpod_v1_context_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ParseContextRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_gitpod_v1_context_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ParseContextResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_gitpod_v1_context_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Context); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_gitpod_v1_context_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_gitpod_v1_context_proto_goTypes, + DependencyIndexes: file_gitpod_v1_context_proto_depIdxs, + MessageInfos: file_gitpod_v1_context_proto_msgTypes, + }.Build() + File_gitpod_v1_context_proto = out.File + file_gitpod_v1_context_proto_rawDesc = nil + file_gitpod_v1_context_proto_goTypes = nil + file_gitpod_v1_context_proto_depIdxs = nil +} diff --git a/components/public-api/go/v1/context_grpc.pb.go b/components/public-api/go/v1/context_grpc.pb.go new file mode 100644 index 00000000000000..d0783796bcdacd --- /dev/null +++ b/components/public-api/go/v1/context_grpc.pb.go @@ -0,0 +1,111 @@ +// Copyright (c) 2023 Gitpod GmbH. All rights reserved. +// Licensed under the GNU Affero General Public License (AGPL). +// See License.AGPL.txt in the project root for license information. + +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc (unknown) +// source: gitpod/v1/context.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// ContextServiceClient is the client API for ContextService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ContextServiceClient interface { + // ParseContext parses the url and returns the context + ParseContext(ctx context.Context, in *ParseContextRequest, opts ...grpc.CallOption) (*ParseContextResponse, error) +} + +type contextServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewContextServiceClient(cc grpc.ClientConnInterface) ContextServiceClient { + return &contextServiceClient{cc} +} + +func (c *contextServiceClient) ParseContext(ctx context.Context, in *ParseContextRequest, opts ...grpc.CallOption) (*ParseContextResponse, error) { + out := new(ParseContextResponse) + err := c.cc.Invoke(ctx, "/gitpod.v1.ContextService/ParseContext", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ContextServiceServer is the server API for ContextService service. +// All implementations must embed UnimplementedContextServiceServer +// for forward compatibility +type ContextServiceServer interface { + // ParseContext parses the url and returns the context + ParseContext(context.Context, *ParseContextRequest) (*ParseContextResponse, error) + mustEmbedUnimplementedContextServiceServer() +} + +// UnimplementedContextServiceServer must be embedded to have forward compatible implementations. +type UnimplementedContextServiceServer struct { +} + +func (UnimplementedContextServiceServer) ParseContext(context.Context, *ParseContextRequest) (*ParseContextResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ParseContext not implemented") +} +func (UnimplementedContextServiceServer) mustEmbedUnimplementedContextServiceServer() {} + +// UnsafeContextServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ContextServiceServer will +// result in compilation errors. +type UnsafeContextServiceServer interface { + mustEmbedUnimplementedContextServiceServer() +} + +func RegisterContextServiceServer(s grpc.ServiceRegistrar, srv ContextServiceServer) { + s.RegisterService(&ContextService_ServiceDesc, srv) +} + +func _ContextService_ParseContext_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ParseContextRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ContextServiceServer).ParseContext(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gitpod.v1.ContextService/ParseContext", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ContextServiceServer).ParseContext(ctx, req.(*ParseContextRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ContextService_ServiceDesc is the grpc.ServiceDesc for ContextService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ContextService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "gitpod.v1.ContextService", + HandlerType: (*ContextServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ParseContext", + Handler: _ContextService_ParseContext_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "gitpod/v1/context.proto", +} diff --git a/components/public-api/go/v1/v1connect/context.connect.go b/components/public-api/go/v1/v1connect/context.connect.go new file mode 100644 index 00000000000000..4222b534bb562f --- /dev/null +++ b/components/public-api/go/v1/v1connect/context.connect.go @@ -0,0 +1,92 @@ +// Copyright (c) 2023 Gitpod GmbH. All rights reserved. +// Licensed under the GNU Affero General Public License (AGPL). +// See License.AGPL.txt in the project root for license information. + +// Code generated by protoc-gen-connect-go. DO NOT EDIT. +// +// Source: gitpod/v1/context.proto + +package v1connect + +import ( + context "context" + errors "errors" + connect_go "github.com/bufbuild/connect-go" + v1 "github.com/gitpod-io/gitpod/components/public-api/go/v1" + http "net/http" + strings "strings" +) + +// This is a compile-time assertion to ensure that this generated file and the connect package are +// compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of connect newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of connect or updating the connect +// version compiled into your binary. +const _ = connect_go.IsAtLeastVersion0_1_0 + +const ( + // ContextServiceName is the fully-qualified name of the ContextService service. + ContextServiceName = "gitpod.v1.ContextService" +) + +// ContextServiceClient is a client for the gitpod.v1.ContextService service. +type ContextServiceClient interface { + // ParseContext parses the url and returns the context + ParseContext(context.Context, *connect_go.Request[v1.ParseContextRequest]) (*connect_go.Response[v1.ParseContextResponse], error) +} + +// NewContextServiceClient constructs a client for the gitpod.v1.ContextService service. By default, +// it uses the Connect protocol with the binary Protobuf Codec, asks for gzipped responses, and +// sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() +// or connect.WithGRPCWeb() options. +// +// The URL supplied here should be the base URL for the Connect or gRPC server (for example, +// http://api.acme.com or https://acme.com/grpc). +func NewContextServiceClient(httpClient connect_go.HTTPClient, baseURL string, opts ...connect_go.ClientOption) ContextServiceClient { + baseURL = strings.TrimRight(baseURL, "/") + return &contextServiceClient{ + parseContext: connect_go.NewClient[v1.ParseContextRequest, v1.ParseContextResponse]( + httpClient, + baseURL+"/gitpod.v1.ContextService/ParseContext", + opts..., + ), + } +} + +// contextServiceClient implements ContextServiceClient. +type contextServiceClient struct { + parseContext *connect_go.Client[v1.ParseContextRequest, v1.ParseContextResponse] +} + +// ParseContext calls gitpod.v1.ContextService.ParseContext. +func (c *contextServiceClient) ParseContext(ctx context.Context, req *connect_go.Request[v1.ParseContextRequest]) (*connect_go.Response[v1.ParseContextResponse], error) { + return c.parseContext.CallUnary(ctx, req) +} + +// ContextServiceHandler is an implementation of the gitpod.v1.ContextService service. +type ContextServiceHandler interface { + // ParseContext parses the url and returns the context + ParseContext(context.Context, *connect_go.Request[v1.ParseContextRequest]) (*connect_go.Response[v1.ParseContextResponse], error) +} + +// NewContextServiceHandler builds an HTTP handler from the service implementation. It returns the +// path on which to mount the handler and the handler itself. +// +// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf +// and JSON codecs. They also support gzip compression. +func NewContextServiceHandler(svc ContextServiceHandler, opts ...connect_go.HandlerOption) (string, http.Handler) { + mux := http.NewServeMux() + mux.Handle("/gitpod.v1.ContextService/ParseContext", connect_go.NewUnaryHandler( + "/gitpod.v1.ContextService/ParseContext", + svc.ParseContext, + opts..., + )) + return "/gitpod.v1.ContextService/", mux +} + +// UnimplementedContextServiceHandler returns CodeUnimplemented from all methods. +type UnimplementedContextServiceHandler struct{} + +func (UnimplementedContextServiceHandler) ParseContext(context.Context, *connect_go.Request[v1.ParseContextRequest]) (*connect_go.Response[v1.ParseContextResponse], error) { + return nil, connect_go.NewError(connect_go.CodeUnimplemented, errors.New("gitpod.v1.ContextService.ParseContext is not implemented")) +} diff --git a/components/public-api/go/v1/v1connect/context.proxy.connect.go b/components/public-api/go/v1/v1connect/context.proxy.connect.go new file mode 100644 index 00000000000000..6c22c915d0153e --- /dev/null +++ b/components/public-api/go/v1/v1connect/context.proxy.connect.go @@ -0,0 +1,30 @@ +// Copyright (c) 2023 Gitpod GmbH. All rights reserved. +// Licensed under the GNU Affero General Public License (AGPL). +// See License.AGPL.txt in the project root for license information. + +// Code generated by protoc-proxy-gen. DO NOT EDIT. + +package v1connect + +import ( + context "context" + connect_go "github.com/bufbuild/connect-go" + v1 "github.com/gitpod-io/gitpod/components/public-api/go/v1" +) + +var _ ContextServiceHandler = (*ProxyContextServiceHandler)(nil) + +type ProxyContextServiceHandler struct { + Client v1.ContextServiceClient + UnimplementedContextServiceHandler +} + +func (s *ProxyContextServiceHandler) ParseContext(ctx context.Context, req *connect_go.Request[v1.ParseContextRequest]) (*connect_go.Response[v1.ParseContextResponse], error) { + resp, err := s.Client.ParseContext(ctx, req.Msg) + if err != nil { + // TODO(milan): Convert to correct status code + return nil, err + } + + return connect_go.NewResponse(resp), nil +} diff --git a/components/public-api/go/v1/workspace.pb.go b/components/public-api/go/v1/workspace.pb.go index 0693a4880c6c0c..4c2dd0cee83c0b 100644 --- a/components/public-api/go/v1/workspace.pb.go +++ b/components/public-api/go/v1/workspace.pb.go @@ -1590,6 +1590,9 @@ type CreateAndStartWorkspaceRequest_Source struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + // git describes the source refer of workspace + // Obtain available git using the ContextService.ParseContext operation if + // not sure about it. Git *CreateAndStartWorkspaceRequest_Source_Git `protobuf:"bytes,1,opt,name=git,proto3" json:"git,omitempty"` } diff --git a/components/public-api/typescript/src/gitpod/v1/context_connect.ts b/components/public-api/typescript/src/gitpod/v1/context_connect.ts new file mode 100644 index 00000000000000..a3ad5e09287d11 --- /dev/null +++ b/components/public-api/typescript/src/gitpod/v1/context_connect.ts @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2023 Gitpod GmbH. All rights reserved. + * Licensed under the GNU Affero General Public License (AGPL). + * See License.AGPL.txt in the project root for license information. + */ + +// @generated by protoc-gen-connect-es v1.1.2 with parameter "target=ts" +// @generated from file gitpod/v1/context.proto (package gitpod.v1, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import { ParseContextRequest, ParseContextResponse } from "./context_pb.js"; +import { MethodKind } from "@bufbuild/protobuf"; + +/** + * @generated from service gitpod.v1.ContextService + */ +export const ContextService = { + typeName: "gitpod.v1.ContextService", + methods: { + /** + * ParseContext parses the url and returns the context + * + * @generated from rpc gitpod.v1.ContextService.ParseContext + */ + parseContext: { + name: "ParseContext", + I: ParseContextRequest, + O: ParseContextResponse, + kind: MethodKind.Unary, + }, + } +} as const; diff --git a/components/public-api/typescript/src/gitpod/v1/context_pb.ts b/components/public-api/typescript/src/gitpod/v1/context_pb.ts new file mode 100644 index 00000000000000..410ff6f2d669fe --- /dev/null +++ b/components/public-api/typescript/src/gitpod/v1/context_pb.ts @@ -0,0 +1,136 @@ +/** + * Copyright (c) 2023 Gitpod GmbH. All rights reserved. + * Licensed under the GNU Affero General Public License (AGPL). + * See License.AGPL.txt in the project root for license information. + */ + +// @generated by protoc-gen-es v1.3.3 with parameter "target=ts" +// @generated from file gitpod/v1/context.proto (package gitpod.v1, syntax proto3) +/* eslint-disable */ +// @ts-nocheck + +import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; +import { Message, proto3 } from "@bufbuild/protobuf"; + +/** + * @generated from message gitpod.v1.ParseContextRequest + */ +export class ParseContextRequest extends Message { + /** + * @generated from field: string url = 1; + */ + url = ""; + + constructor(data?: PartialMessage) { + super(); + proto3.util.initPartial(data, this); + } + + static readonly runtime: typeof proto3 = proto3; + static readonly typeName = "gitpod.v1.ParseContextRequest"; + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { no: 1, name: "url", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): ParseContextRequest { + return new ParseContextRequest().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): ParseContextRequest { + return new ParseContextRequest().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): ParseContextRequest { + return new ParseContextRequest().fromJsonString(jsonString, options); + } + + static equals(a: ParseContextRequest | PlainMessage | undefined, b: ParseContextRequest | PlainMessage | undefined): boolean { + return proto3.util.equals(ParseContextRequest, a, b); + } +} + +/** + * @generated from message gitpod.v1.ParseContextResponse + */ +export class ParseContextResponse extends Message { + /** + * @generated from field: gitpod.v1.Context context = 1; + */ + context?: Context; + + constructor(data?: PartialMessage) { + super(); + proto3.util.initPartial(data, this); + } + + static readonly runtime: typeof proto3 = proto3; + static readonly typeName = "gitpod.v1.ParseContextResponse"; + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { no: 1, name: "context", kind: "message", T: Context }, + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): ParseContextResponse { + return new ParseContextResponse().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): ParseContextResponse { + return new ParseContextResponse().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): ParseContextResponse { + return new ParseContextResponse().fromJsonString(jsonString, options); + } + + static equals(a: ParseContextResponse | PlainMessage | undefined, b: ParseContextResponse | PlainMessage | undefined): boolean { + return proto3.util.equals(ParseContextResponse, a, b); + } +} + +/** + * @generated from message gitpod.v1.Context + */ +export class Context extends Message { + /** + * @generated from field: string title = 1; + */ + title = ""; + + /** + * @generated from field: string normalized_url = 2; + */ + normalizedUrl = ""; + + /** + * @generated from field: string ref = 3; + */ + ref = ""; + + constructor(data?: PartialMessage) { + super(); + proto3.util.initPartial(data, this); + } + + static readonly runtime: typeof proto3 = proto3; + static readonly typeName = "gitpod.v1.Context"; + static readonly fields: FieldList = proto3.util.newFieldList(() => [ + { no: 1, name: "title", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "normalized_url", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "ref", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): Context { + return new Context().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): Context { + return new Context().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): Context { + return new Context().fromJsonString(jsonString, options); + } + + static equals(a: Context | PlainMessage | undefined, b: Context | PlainMessage | undefined): boolean { + return proto3.util.equals(Context, a, b); + } +} diff --git a/components/public-api/typescript/src/gitpod/v1/workspace_pb.ts b/components/public-api/typescript/src/gitpod/v1/workspace_pb.ts index e3b20c4639d0f7..08c9b43f5308ad 100644 --- a/components/public-api/typescript/src/gitpod/v1/workspace_pb.ts +++ b/components/public-api/typescript/src/gitpod/v1/workspace_pb.ts @@ -426,6 +426,10 @@ export class CreateAndStartWorkspaceRequest extends Message { /** + * git describes the source refer of workspace + * Obtain available git using the ContextService.ParseContext operation if + * not sure about it. + * * @generated from field: gitpod.v1.CreateAndStartWorkspaceRequest.Source.Git git = 1; */ git?: CreateAndStartWorkspaceRequest_Source_Git;