Skip to content

Commit 10493ed

Browse files
authored
feat(dart): Include a correct URL for issues (#2570)
Fixes the generation side of googleapis/google-cloud-dart#8
1 parent 62e80f1 commit 10493ed

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

internal/sidekick/internal/dart/annotate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type modelAnnotations struct {
5656
RepositoryURL string
5757
ReadMeAfterTitleText string
5858
ReadMeQuickstartText string
59+
IssueTrackerURL string
5960
ApiKeyEnvironmentVariables []string
6061
}
6162

@@ -227,6 +228,7 @@ func (annotate *annotateModel) annotateModel(options map[string]string) error {
227228
repositoryURL string
228229
readMeAfterTitleText string
229230
readMeQuickstartText string
231+
issueTrackerURL string
230232
apiKeyEnvironmentVariables = []string{}
231233
)
232234

@@ -244,6 +246,10 @@ func (annotate *annotateModel) annotateModel(options map[string]string) error {
244246
packageNameOverride = definition
245247
case key == "copyright-year":
246248
generationYear = definition
249+
case key == "issue-tracker-url":
250+
// issue-tracker-url = "http://www.example.com/issues"
251+
// A link to the issue tracker for the service.
252+
issueTrackerURL = definition
247253
case key == "version":
248254
packageVersion = definition
249255
case key == "part-file":
@@ -337,6 +343,10 @@ func (annotate *annotateModel) annotateModel(options map[string]string) error {
337343
return errors.New("all packages that define a service must define 'api-keys-environment-variables'")
338344
}
339345

346+
if issueTrackerURL == "" {
347+
return errors.New("all packages must define 'issue-tracker-url'")
348+
}
349+
340350
ann := &modelAnnotations{
341351
Parent: model,
342352
PackageName: packageName(model, packageNameOverride),
@@ -359,6 +369,7 @@ func (annotate *annotateModel) annotateModel(options map[string]string) error {
359369
DevDependencies: devDependencies,
360370
DoNotPublish: doNotPublish,
361371
RepositoryURL: repositoryURL,
372+
IssueTrackerURL: issueTrackerURL,
362373
ReadMeAfterTitleText: readMeAfterTitleText,
363374
ReadMeQuickstartText: readMeQuickstartText,
364375
ApiKeyEnvironmentVariables: apiKeyEnvironmentVariables,

internal/sidekick/internal/dart/annotate_test.go

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
var (
2727
requiredConfig = map[string]string{
2828
"api-keys-environment-variables": "GOOGLE_API_KEY,GEMINI_API_KEY",
29+
"issue-tracker-url": "http://www.example.com/issues",
2930
"package:googleapis_auth": "^2.0.0",
3031
"package:google_cloud_gax": "^1.2.3",
3132
"package:http": "^4.5.6"}
@@ -34,8 +35,12 @@ var (
3435
func TestAnnotateModel(t *testing.T) {
3536
model := api.NewTestAPI([]*api.Message{}, []*api.Enum{}, []*api.Service{})
3637
model.PackageName = "test"
38+
39+
options := maps.Clone(requiredConfig)
40+
maps.Copy(options, map[string]string{"package:google_cloud_gax": "^1.2.3"})
41+
3742
annotate := newAnnotateModel(model)
38-
err := annotate.annotateModel(map[string]string{"package:google_cloud_gax": "^1.2.3"})
43+
err := annotate.annotateModel(options)
3944
if err != nil {
4045
t.Fatal(err)
4146
}
@@ -120,6 +125,15 @@ func TestAnnotateModel_Options(t *testing.T) {
120125
}
121126
},
122127
},
128+
{
129+
map[string]string{"issue-tracker-url": "http://example.com/issues"},
130+
func(t *testing.T, am *annotateModel) {
131+
codec := model.Codec.(*modelAnnotations)
132+
if diff := cmp.Diff("http://example.com/issues", codec.IssueTrackerURL); diff != "" {
133+
t.Errorf("mismatch in Codec.IssueTrackerURL (-want, +got)\n:%s", diff)
134+
}
135+
},
136+
},
123137
{
124138
map[string]string{"google_cloud_gax": "^1.2.3", "package:http": "1.2.0"},
125139
func(t *testing.T, am *annotateModel) {
@@ -146,6 +160,40 @@ func TestAnnotateModel_Options(t *testing.T) {
146160
}
147161
}
148162

163+
func TestAnnotateModel_Options_MissingRequired(t *testing.T) {
164+
method := sample.MethodListSecretVersions()
165+
service := &api.Service{
166+
Name: sample.ServiceName,
167+
Documentation: sample.APIDescription,
168+
DefaultHost: sample.DefaultHost,
169+
Methods: []*api.Method{method},
170+
Package: sample.Package,
171+
}
172+
model := api.NewTestAPI(
173+
[]*api.Message{sample.ListSecretVersionsRequest(), sample.ListSecretVersionsResponse(),
174+
sample.Secret(), sample.SecretVersion(), sample.Replication(), sample.Automatic(),
175+
sample.CustomerManagedEncryption()},
176+
[]*api.Enum{sample.EnumState()},
177+
[]*api.Service{service},
178+
)
179+
180+
var tests = []string{
181+
"api-keys-environment-variables",
182+
"issue-tracker-url",
183+
}
184+
185+
for _, tt := range tests {
186+
annotate := newAnnotateModel(model)
187+
options := maps.Clone(requiredConfig)
188+
delete(options, tt)
189+
190+
err := annotate.annotateModel(options)
191+
if err == nil {
192+
t.Fatalf("expected error when missing %q", tt)
193+
}
194+
}
195+
}
196+
149197
func TestAnnotateMethod(t *testing.T) {
150198
method := sample.MethodListSecretVersions()
151199
service := &api.Service{

internal/sidekick/internal/dart/generate_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package dart
1616

1717
import (
1818
"io/fs"
19+
"maps"
1920
"os"
2021
"os/exec"
2122
"path"
@@ -47,6 +48,7 @@ func TestFromProtobuf(t *testing.T) {
4748
},
4849
Codec: map[string]string{
4950
"api-keys-environment-variables": "GOOGLE_API_KEY,GEMINI_API_KEY",
51+
"issue-tracker-url": "http://www.example.com/issues",
5052
"copyright-year": "2025",
5153
"not-for-publication": "true",
5254
"version": "0.1.0",
@@ -82,7 +84,11 @@ func TestFromProtobuf(t *testing.T) {
8284
func TestGeneratedFiles(t *testing.T) {
8385
model := api.NewTestAPI([]*api.Message{}, []*api.Enum{}, []*api.Service{})
8486
annotate := newAnnotateModel(model)
85-
annotate.annotateModel(map[string]string{"package:google_cloud_gax": "^1.2.3", "package:http": "^4.5.6"})
87+
88+
options := maps.Clone(requiredConfig)
89+
maps.Copy(options, map[string]string{"package:google_cloud_gax": "^1.2.3", "package:http": "^4.5.6"})
90+
91+
annotate.annotateModel(options)
8692
files := generatedFiles(model)
8793
if len(files) == 0 {
8894
t.Errorf("expected a non-empty list of template files from generatedFiles()")

internal/sidekick/internal/dart/templates/README.md.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The Google Cloud client library for the {{{Title}}}.
3535
>
3636
> Your feedback is valuable and will help us evolve this package. For general
3737
> feedback, suggestions, and comments, please file an issue in the
38-
> [bug tracker]({{Codec.RepositoryURL}}/issues).
38+
> [bug tracker]({{{Codec.IssueTrackerURL}}}).
3939

4040
## What's this?
4141

internal/sidekick/internal/dart/templates/pubspec.yaml.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ description: The Google Cloud client library for the {{{Title}}}.
2323
{{#Codec.RepositoryURL}}
2424
repository: {{Codec.RepositoryURL}}
2525
{{/Codec.RepositoryURL}}
26+
issue_tracker: {{{Codec.IssueTrackerURL}}}
2627
{{^Codec.DoNotPublish}}
2728
version: {{Codec.PackageVersion}}
2829
{{/Codec.DoNotPublish}}

0 commit comments

Comments
 (0)