Skip to content

Commit 2f526a3

Browse files
authored
feat: Ability to include the repository URL of a package in pubspec.yaml (#2229)
1 parent 382e634 commit 2f526a3

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

internal/sidekick/internal/dart/annotate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type modelAnnotations struct {
5252
Imports []string
5353
DevDependencies []string
5454
DoNotPublish bool
55+
RepositoryURL string
5556
}
5657

5758
// HasServices returns true if the model has services.
@@ -210,6 +211,7 @@ func (annotate *annotateModel) annotateModel(options map[string]string) error {
210211
partFileReference string
211212
doNotPublish bool
212213
devDependencies = []string{}
214+
repositoryURL string
213215
)
214216

215217
for key, definition := range options {
@@ -234,6 +236,8 @@ func (annotate *annotateModel) annotateModel(options map[string]string) error {
234236
)
235237
}
236238
doNotPublish = value
239+
case key == "repository-url":
240+
repositoryURL = definition
237241
case strings.HasPrefix(key, "proto:"):
238242
// "proto:google.protobuf" = "package:google_cloud_protobuf/protobuf.dart"
239243
keys := strings.Split(key, ":")
@@ -315,6 +319,7 @@ func (annotate *annotateModel) annotateModel(options map[string]string) error {
315319
PackageDependencies: packageDependencies,
316320
DevDependencies: devDependencies,
317321
DoNotPublish: doNotPublish,
322+
RepositoryURL: repositoryURL,
318323
}
319324

320325
model.Codec = ann

internal/sidekick/internal/dart/annotate_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestAnnotateModel(t *testing.T) {
4444
func TestAnnotateModel_Options(t *testing.T) {
4545
model := api.NewTestAPI([]*api.Message{}, []*api.Enum{}, []*api.Service{})
4646

47-
var foo = []struct {
47+
var tests = []struct {
4848
options map[string]string
4949
verify func(*testing.T, *annotateModel)
5050
}{
@@ -84,6 +84,15 @@ func TestAnnotateModel_Options(t *testing.T) {
8484
}
8585
},
8686
},
87+
{
88+
map[string]string{"repository-url": "http://example.com/repo"},
89+
func(t *testing.T, am *annotateModel) {
90+
codec := model.Codec.(*modelAnnotations)
91+
if diff := cmp.Diff("http://example.com/repo", codec.RepositoryURL); diff != "" {
92+
t.Errorf("mismatch in Codec.RepositoryURL (-want, +got)\n:%s", diff)
93+
}
94+
},
95+
},
8796
{
8897
map[string]string{"package:http": "1.2.0"},
8998
func(t *testing.T, am *annotateModel) {
@@ -94,7 +103,7 @@ func TestAnnotateModel_Options(t *testing.T) {
94103
},
95104
}
96105

97-
for _, tt := range foo {
106+
for _, tt := range tests {
98107
annotate := newAnnotateModel(model)
99108
err := annotate.annotateModel(tt.options)
100109
if err != nil {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ limitations under the License.
2020

2121
name: {{Codec.PackageName}}
2222
description: The Google Cloud client library for the {{{Title}}}.
23+
{{#Codec.RepositoryURL}}
24+
repository: {{Codec.RepositoryURL}}
25+
{{/Codec.RepositoryURL}}
2326
{{^Codec.DoNotPublish}}
2427
version: {{Codec.PackageVersion}}
2528
{{/Codec.DoNotPublish}}

0 commit comments

Comments
 (0)