nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: googleapis/gapic-generator-go
Pull request #1434 (2023-11-01 21:27:16)

fix(gengapic): ensure input type imported


Patch:
diff --git a/internal/gengapic/client_init.go b/internal/gengapic/client_init.go
index d535681..a2f1d1e 100644
--- a/internal/gengapic/client_init.go
+++ b/internal/gengapic/client_init.go
@@ -89,6 +89,7 @@ func (g *generator) internalClientIntfInit(serv *descriptor.ServiceDescriptorPro
 		if err != nil {
 			return err
 		}
+		g.imports[inSpec] = true
 		if m.GetOutputType() == emptyType {
 			p("%s(context.Context, *%s.%s, ...gax.CallOption) error",
 				m.GetName(),


Test patch:
diff --git a/internal/gengapic/client_init_test.go b/internal/gengapic/client_init_test.go
index d9138d4..aecbaec 100644
--- a/internal/gengapic/client_init_test.go
+++ b/internal/gengapic/client_init_test.go
@@ -423,12 +423,15 @@ func TestClientInit(t *testing.T) {
 			serv:      servPlain,
 			parameter: proto.String("go-gapic-package=path;mypackage,transport=rest"),
 			imports: map[pbinfo.ImportSpec]bool{
-				{Path: "context"}:                                                     true,
-				{Path: "google.golang.org/api/option"}:                                true,
-				{Path: "google.golang.org/api/option/internaloption"}:                 true,
-				{Path: "google.golang.org/grpc"}:                                      true,
-				{Path: "net/http"}:                                                    true,
-				{Name: "httptransport", Path: "google.golang.org/api/transport/http"}: true,
+				{Path: "context"}:                                                                  true,
+				{Path: "google.golang.org/api/option"}:                                             true,
+				{Path: "google.golang.org/api/option/internaloption"}:                              true,
+				{Path: "google.golang.org/grpc"}:                                                   true,
+				{Path: "net/http"}:                                                                 true,
+				{Name: "httptransport", Path: "google.golang.org/api/transport/http"}:              true,
+				{Name: "iampb", Path: "cloud.google.com/go/iam/apiv1/iampb"}:                       true,
+				{Name: "locationpb", Path: "google.golang.org/genproto/googleapis/cloud/location"}: true,
+				{Name: "mypackagepb", Path: "github.com/googleapis/mypackage"}:                     true,
 			},
 			wantNumSnps: 6,
 		},
@@ -498,6 +501,7 @@ func TestClientInit(t *testing.T) {
 				{Path: "google.golang.org/grpc"}:                                      true,
 				{Path: "net/http"}:                                                    true,
 				{Name: "httptransport", Path: "google.golang.org/api/transport/http"}: true,
+				{Name: "mypackagepb", Path: "github.com/googleapis/mypackage"}:        true,
 			},
 			wantNumSnps: 1,
 			setExt: func() (protoreflect.ExtensionType, interface{}) {
Repository: googleapis/gapic-generator-go
Pull request #1537 (2024-06-20 14:33:47)

fix(gengapic): make field var name generic
This helps avoid clashes with keywords.


Patch:
diff --git a/internal/gengapic/genrest.go b/internal/gengapic/genrest.go
index 6268133..75b8e79 100644
--- a/internal/gengapic/genrest.go
+++ b/internal/gengapic/genrest.go
@@ -417,7 +417,7 @@ func (g *generator) generateQueryString(m *descriptorpb.MethodDescriptorProto) {
 		// Handle well known protobuf types with special JSON encodings.
 		if strContains(wellKnownTypeNames, field.GetTypeName()) {
 			b := strings.Builder{}
-			b.WriteString(fmt.Sprintf("%s, err := protojson.Marshal(req%s)\n", field.GetJsonName(), accessor))
+			b.WriteString(fmt.Sprintf("field, err := protojson.Marshal(req%s)\n", accessor))
 			b.WriteString("if err != nil {\n")
 			if m.GetOutputType() == emptyType {
 				b.WriteString("  return err\n")
@@ -429,9 +429,9 @@ func (g *generator) generateQueryString(m *descriptorpb.MethodDescriptorProto) {
 			b.WriteString("}\n")
 			// Only some of the well known types will be encoded as strings, remove the wrapping quotations for those.
 			if strContains(wellKnownStringTypes, field.GetTypeName()) {
-				b.WriteString(fmt.Sprintf("params.Add(%q, string(%s[1:len(%[2]s)-1]))", key, field.GetJsonName()))
+				b.WriteString(fmt.Sprintf("params.Add(%q, string(field[1:len(field)-1]))", key))
 			} else {
-				b.WriteString(fmt.Sprintf("params.Add(%q, string(%s))", key, field.GetJsonName()))
+				b.WriteString(fmt.Sprintf("params.Add(%q, string(field))", key))
 			}
 			paramAdd = b.String()
 		} else {


Test patch:
diff --git a/internal/gengapic/testdata/rest_UpdateRPC.want b/internal/gengapic/testdata/rest_UpdateRPC.want
index e053987..2c156d7 100644
--- a/internal/gengapic/testdata/rest_UpdateRPC.want
+++ b/internal/gengapic/testdata/rest_UpdateRPC.want
@@ -15,11 +15,11 @@ func (c *fooRESTClient) UpdateRPC(ctx context.Context, req *foopb.UpdateRequest,
 	params := url.Values{}
 	params.Add("$alt", "json;enum-encoding=int")
 	if req.GetNumericWrapper() != nil {
-		numericWrapper, err := protojson.Marshal(req.GetNumericWrapper())
+		field, err := protojson.Marshal(req.GetNumericWrapper())
 		if err != nil {
 		  return nil, err
 		}
-		params.Add("numericWrapper", string(numericWrapper))
+		params.Add("numericWrapper", string(field))
 	}
 	if items := req.GetPrimitives(); len(items) > 0 {
 		for _, item := range items {
@@ -27,11 +27,11 @@ func (c *fooRESTClient) UpdateRPC(ctx context.Context, req *foopb.UpdateRequest,
 		}
 	}
 	if req.GetUpdateMask() != nil {
-		updateMask, err := protojson.Marshal(req.GetUpdateMask())
+		field, err := protojson.Marshal(req.GetUpdateMask())
 		if err != nil {
 		  return nil, err
 		}
-		params.Add("updateMask", string(updateMask[1:len(updateMask)-1]))
+		params.Add("updateMask", string(field[1:len(field)-1]))
 	}
 
 	baseUrl.RawQuery = params.Encode()
Repository: googleapis/gapic-generator-go
Pull request #1557 (2024-08-16 21:07:18)

fix: add missing cast for proto optionals
Related: https://github.com/googleapis/gapic-generator-go/pull/1541


Patch:
diff --git a/internal/gengapic/paging.go b/internal/gengapic/paging.go
index 353d8ea..241551c 100644
--- a/internal/gengapic/paging.go
+++ b/internal/gengapic/paging.go
@@ -332,7 +332,7 @@ func internalPageSizeSetter(p func(s string, a ...interface{}), pageSize *descri
 	switch pageSize.GetType() {
 	case descriptorpb.FieldDescriptorProto_TYPE_INT32:
 		if pageSize.GetProto3Optional() {
-			p("req.%s = proto.Int32(%s)", cName, setVal)
+			p("req.%s = proto.Int32(int32(%s))", cName, setVal)
 		} else {
 			if setVal != "math.MaxInt32" {
 				setVal = fmt.Sprintf("int32(%s)", setVal)
@@ -341,7 +341,7 @@ func internalPageSizeSetter(p func(s string, a ...interface{}), pageSize *descri
 		}
 	case descriptorpb.FieldDescriptorProto_TYPE_UINT32:
 		if pageSize.GetProto3Optional() {
-			p("req.%s = proto.UInt32(%s)", cName, setVal)
+			p("req.%s = proto.UInt32(uint32(%s))", cName, setVal)
 		} else {
 			p("req.%s = uint32(%s)", cName, setVal)
 		}


Test patch:
diff --git a/internal/gengapic/testdata/method_GetManyThingsOptional.want b/internal/gengapic/testdata/method_GetManyThingsOptional.want
index e913744..7d2761f 100644
--- a/internal/gengapic/testdata/method_GetManyThingsOptional.want
+++ b/internal/gengapic/testdata/method_GetManyThingsOptional.want
@@ -12,9 +12,9 @@ func (c *fooGRPCClient) GetManyThingsOptional(ctx context.Context, req *mypackag
 			req.PageToken = proto.String(pageToken)
 		}
 		if pageSize > math.MaxInt32 {
-			req.PageSize = proto.Int32(math.MaxInt32)
+			req.PageSize = proto.Int32(int32(math.MaxInt32))
 		} else if pageSize != 0 {
-			req.PageSize = proto.Int32(pageSize)
+			req.PageSize = proto.Int32(int32(pageSize))
 		}
 		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
 			var err error
Repository: googleapis/gapic-generator-go
Pull request #1576 (2024-10-28 21:42:39)

fix: make iterator link clickable
Internal Bug: 372879282

noahdietz: `make golden` :)

Patch:
diff --git a/internal/gengapic/paging.go b/internal/gengapic/paging.go
index 42b0c0f..81d499e 100644
--- a/internal/gengapic/paging.go
+++ b/internal/gengapic/paging.go
@@ -448,7 +448,7 @@ func (g *generator) pagingIter(pt *iterType) {
 	p("}")
 	p("")
 
-	p("// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.")
+	p("// PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.")
 	p("func (it *%s) PageInfo() *iterator.PageInfo {", pt.iterTypeName)
 	p("  return it.pageInfo")
 	p("}")


Test patch:
diff --git a/internal/gengapic/testdata/gen_iterators.want b/internal/gengapic/testdata/gen_iterators.want
index 907a963..98e0deb 100644
--- a/internal/gengapic/testdata/gen_iterators.want
+++ b/internal/gengapic/testdata/gen_iterators.want
@@ -18,7 +18,7 @@ type FooIterator struct {
 	InternalFetch func(pageSize int, pageToken string) (results []*examplepb.Foo, nextPageToken string, err error)
 }
 
-// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
+// PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
 func (it *FooIterator) PageInfo() *iterator.PageInfo {
 	return it.pageInfo
 }
Repository: googleapis/gapic-generator-go
Pull request #1583 (2024-11-14 18:53:53)

fix: improve imports behavior for helpers.go
The refactor of helper methods from docs.go to helpers.go yielded a double-import, as the previous code yielded the full doc.go directly without leveraging the import management via gengapic's commit mechanism.

This PR removes the static import templating, and transitions to using the import templating available as part of the commit mechanism.


Patch:
diff --git a/internal/gengapic/gengapic.go b/internal/gengapic/gengapic.go
index 388194c..151b8ef 100644
--- a/internal/gengapic/gengapic.go
+++ b/internal/gengapic/gengapic.go
@@ -230,12 +230,8 @@ func (g *generator) collectServicesAndScopes(genReq *pluginpb.CodeGeneratorReque
 func (g *generator) genAndCommitHelpers(scopes []string) error {
 	p := g.printf
 	g.reset()
-	p("import (")
-	p("%s%q", "\t", "context")
-	p("")
-	p("%s%q", "\t", "google.golang.org/api/option")
-	p(")")
-	p("")
+	g.imports[pbinfo.ImportSpec{Path: "context"}] = true
+	g.imports[pbinfo.ImportSpec{Path: "google.golang.org/api/option"}] = true
 
 	p("// For more information on implementing a client constructor hook, see")
 	p("// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors.")


Test patch:
diff --git a/internal/gengapic/testdata/helpers_default_scope.want b/internal/gengapic/testdata/helpers_default_scope.want
index 475b61b..1cc4b5f 100644
--- a/internal/gengapic/testdata/helpers_default_scope.want
+++ b/internal/gengapic/testdata/helpers_default_scope.want
@@ -1,9 +1,3 @@
-import (
-	"context"
-
-	"google.golang.org/api/option"
-)
-
 // For more information on implementing a client constructor hook, see
 // https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors.
 type clientHookParams struct{}
diff --git a/internal/gengapic/testdata/helpers_multiple_scopes.want b/internal/gengapic/testdata/helpers_multiple_scopes.want
index 4ee4735..9b2583d 100644
--- a/internal/gengapic/testdata/helpers_multiple_scopes.want
+++ b/internal/gengapic/testdata/helpers_multiple_scopes.want
@@ -1,9 +1,3 @@
-import (
-	"context"
-
-	"google.golang.org/api/option"
-)
-
 // For more information on implementing a client constructor hook, see
 // https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors.
 type clientHookParams struct{}
diff --git a/internal/gengapic/testdata/helpers_no_scopes.want b/internal/gengapic/testdata/helpers_no_scopes.want
index 311e126..d72cc5b 100644
--- a/internal/gengapic/testdata/helpers_no_scopes.want
+++ b/internal/gengapic/testdata/helpers_no_scopes.want
@@ -1,9 +1,3 @@
-import (
-	"context"
-
-	"google.golang.org/api/option"
-)
-
 // For more information on implementing a client constructor hook, see
 // https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors.
 type clientHookParams struct{}