Skip to content

Commit 946cbe7

Browse files
authored
fix(internal/config): remove unused source.Branch (#5686)
The source.Branch config field is no longer be used.
1 parent d849309 commit 946cbe7

4 files changed

Lines changed: 8 additions & 49 deletions

File tree

doc/config-schema.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ This document describes the schema for the librarian.yaml.
4444

4545
| Field | Type | Description |
4646
| :--- | :--- | :--- |
47-
| `branch` | string | Is the source's git branch to pull updates from. Unset should be interpreted as the repository default branch. |
4847
| `commit` | string | Is the git commit hash or tag to use. |
4948
| `dir` | string | Is a local directory path to use instead of fetching. If set, Commit and SHA256 are ignored. |
5049
| `sha256` | string | Is the expected hash of the tarball for this commit. |

internal/config/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ type Sources struct {
107107

108108
// Source represents a source repository.
109109
type Source struct {
110-
// Branch is the source's git branch to pull updates from.
111-
// Unset should be interpreted as the repository default branch.
112-
Branch string `yaml:"branch,omitempty"`
113-
114110
// Commit is the git commit hash or tag to use.
115111
Commit string `yaml:"commit"`
116112

internal/librarian/update.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,6 @@ func updateSource(endpoints *fetch.Endpoints, repo fetch.RepoRef, source *config
123123
return nil
124124
}
125125

126-
// Source configuration specifically references a branch of the
127-
// source repository.
128-
if source.Branch != "" {
129-
repo.Branch = source.Branch
130-
}
131-
132126
oldCommit := source.Commit
133127
oldSHA256 := source.SHA256
134128

internal/librarian/update_test.go

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ type updateTestSetup struct {
3737
const (
3838
googleapisTestCommit = "123456"
3939
discoveryTestCommit = "abcdef"
40-
conformanceTestCommit = "conformance1234"
40+
conformanceTestCommit = "protobuf1234"
4141
protobufTestCommit = "protobuf1234"
4242
showcaseTestCommit = "showcase1234"
4343
googleapisTestTarball = "googleapis-tarball-content"
4444
discoveryTestTarball = "discovery-tarball-content"
45-
conformanceTestTarball = "conformance-tarball-content"
45+
conformanceTestTarball = "protobuf-tarball-content"
4646
protobufTestTarball = "protobuf-tarball-content"
4747
showcaseTestTarball = "showcase-tarball-content"
48-
testBranch = "other"
4948
unchangedPlaceholder = "this-should-not-change"
5049
)
5150

@@ -58,24 +57,19 @@ var (
5857
)
5958

6059
func setupUpdateTest(t *testing.T, conf *config.Config) *updateTestSetup {
61-
// Source.Branch can be empty in the config file. Update should default to
62-
// using the branch configured in [sourceRepos], so we only set up the
63-
// test server handlers with Source.Branch when it is explicitly set as it
64-
// would be in the file on disk.
65-
googleapisBranch := determineBranch("googleapis", conf.Sources.Googleapis)
66-
discoveryBranch := determineBranch("discovery", conf.Sources.Discovery)
67-
conformanceBranch := determineBranch("conformance", conf.Sources.Conformance)
68-
protobufBranch := determineBranch("protobuf", conf.Sources.ProtobufSrc)
69-
showcaseBranch := determineBranch("showcase", conf.Sources.Showcase)
60+
// Update defaults to using the branch configured in [sourceRepos].
61+
// We set up the test server handlers accordingly.
62+
googleapisBranch := sourceRepos["googleapis"].Branch
63+
discoveryBranch := sourceRepos["discovery"].Branch
64+
protobufBranch := sourceRepos["protobuf"].Branch
65+
showcaseBranch := sourceRepos["showcase"].Branch
7066

7167
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
7268
switch r.URL.Path {
7369
case "/repos/googleapis/googleapis/commits/" + googleapisBranch:
7470
w.Write([]byte(googleapisTestCommit))
7571
case "/repos/googleapis/discovery-artifact-manager/commits/" + discoveryBranch:
7672
w.Write([]byte(discoveryTestCommit))
77-
case "/repos/protocolbuffers/protobuf/commits/" + conformanceBranch:
78-
w.Write([]byte(conformanceTestCommit))
7973
case "/repos/protocolbuffers/protobuf/commits/" + protobufBranch:
8074
w.Write([]byte(protobufTestCommit))
8175
case "/repos/googleapis/gapic-showcase/commits/" + showcaseBranch:
@@ -84,8 +78,6 @@ func setupUpdateTest(t *testing.T, conf *config.Config) *updateTestSetup {
8478
w.Write([]byte(googleapisTestTarball))
8579
case "/googleapis/discovery-artifact-manager/archive/" + discoveryTestCommit + ".tar.gz":
8680
w.Write([]byte(discoveryTestTarball))
87-
case "/protocolbuffers/protobuf/archive/" + conformanceTestCommit + ".tar.gz":
88-
w.Write([]byte(conformanceTestTarball))
8981
case "/protocolbuffers/protobuf/archive/" + protobufTestCommit + ".tar.gz":
9082
w.Write([]byte(protobufTestTarball))
9183
case "/googleapis/gapic-showcase/archive/" + showcaseTestCommit + ".tar.gz":
@@ -106,13 +98,6 @@ func setupUpdateTest(t *testing.T, conf *config.Config) *updateTestSetup {
10698
}
10799
}
108100

109-
func determineBranch(repoName string, source *config.Source) string {
110-
if source != nil && source.Branch != "" {
111-
return source.Branch
112-
}
113-
return sourceRepos[repoName].Branch
114-
}
115-
116101
func setupTestConfig(t *testing.T, conf *config.Config) string {
117102
if conf == nil {
118103
return ""
@@ -209,20 +194,6 @@ func TestUpdateCommand(t *testing.T) {
209194
cfg.Sources.Discovery.SHA256 = discoveryTestSHA
210195
},
211196
},
212-
{
213-
name: "googleapis branch",
214-
args: []string{"librarian", "update", "googleapis"},
215-
setup: func(cfg *config.Config) {
216-
cfg.Sources.Googleapis.Branch = testBranch
217-
cfg.Sources.Googleapis.Commit = "this-should-be-changed"
218-
cfg.Sources.Googleapis.SHA256 = "this-should-be-changed"
219-
},
220-
wantConfig: func(cfg *config.Config) {
221-
cfg.Sources.Googleapis.Branch = testBranch
222-
cfg.Sources.Googleapis.Commit = googleapisTestCommit
223-
cfg.Sources.Googleapis.SHA256 = googleapisTestSHA
224-
},
225-
},
226197
} {
227198
t.Run(test.name, func(t *testing.T) {
228199
initialConfig := updateTestConfig()
@@ -309,7 +280,6 @@ func updateTestConfig() *config.Config {
309280
SHA256: unchangedPlaceholder,
310281
},
311282
ProtobufSrc: &config.Source{
312-
Branch: testBranch,
313283
Commit: unchangedPlaceholder,
314284
SHA256: unchangedPlaceholder,
315285
},

0 commit comments

Comments
 (0)