Skip to content

Commit 6017f2b

Browse files
noahdietzcatchyzheng
authored andcommitted
chore(internal): fix Url to URL casing (#1000)
Just a little clean up, renaming all instances of CamelCase `Url` to upper case `URL` Fixes #689
1 parent 0923c85 commit 6017f2b

7 files changed

Lines changed: 24 additions & 24 deletions

File tree

internal/github/github.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ type PullRequestMetadata struct {
8585

8686
// ParseURL parses a GitHub URL (anything to do with a repository) to determine
8787
// the GitHub repo details (owner and name).
88-
func ParseURL(remoteUrl string) (*Repository, error) {
89-
if !strings.HasPrefix(remoteUrl, "https://github.com/") {
90-
return nil, fmt.Errorf("remote '%s' is not a GitHub remote", remoteUrl)
88+
func ParseURL(remoteURL string) (*Repository, error) {
89+
if !strings.HasPrefix(remoteURL, "https://github.com/") {
90+
return nil, fmt.Errorf("remote '%s' is not a GitHub remote", remoteURL)
9191
}
92-
remotePath := remoteUrl[len("https://github.com/"):]
92+
remotePath := remoteURL[len("https://github.com/"):]
9393
pathParts := strings.Split(remotePath, "/")
9494
organization := pathParts[0]
9595
repoName := pathParts[1]

internal/github/github_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,56 +241,56 @@ func TestFetchGitHubRepoFromRemote(t *testing.T) {
241241
}
242242
}
243243

244-
func TestParseUrl(t *testing.T) {
244+
func TestParseURL(t *testing.T) {
245245
t.Parallel()
246246
for _, test := range []struct {
247247
name string
248-
remoteUrl string
248+
remoteURL string
249249
wantRepo *Repository
250250
wantErr bool
251251
wantErrSubstr string
252252
}{
253253
{
254254
name: "Valid HTTPS URL",
255-
remoteUrl: "https://github.com/owner/repo.git",
255+
remoteURL: "https://github.com/owner/repo.git",
256256
wantRepo: &Repository{Owner: "owner", Name: "repo"},
257257
wantErr: false,
258258
},
259259
{
260260
name: "Valid HTTPS URL without .git",
261-
remoteUrl: "https://github.com/owner/repo",
261+
remoteURL: "https://github.com/owner/repo",
262262
wantRepo: &Repository{Owner: "owner", Name: "repo"},
263263
wantErr: false,
264264
},
265265
{
266266
name: "Invalid URL scheme",
267-
remoteUrl: "http://github.com/owner/repo.git",
267+
remoteURL: "http://github.com/owner/repo.git",
268268
wantErr: true,
269269
wantErrSubstr: "not a GitHub remote",
270270
},
271271
{
272272
name: "URL with extra path components",
273-
remoteUrl: "https://github.com/owner/repo/pulls",
273+
remoteURL: "https://github.com/owner/repo/pulls",
274274
wantRepo: &Repository{Owner: "owner", Name: "repo"},
275275
wantErr: false,
276276
},
277277
} {
278278
t.Run(test.name, func(t *testing.T) {
279279
t.Parallel()
280-
repo, err := ParseURL(test.remoteUrl)
280+
repo, err := ParseURL(test.remoteURL)
281281

282282
if test.wantErr {
283283
if err == nil {
284-
t.Errorf("ParseUrl() err = nil, want error containing %q", test.wantErrSubstr)
284+
t.Errorf("ParseURL() err = nil, want error containing %q", test.wantErrSubstr)
285285
} else if !strings.Contains(err.Error(), test.wantErrSubstr) {
286-
t.Errorf("ParseUrl() err = %v, want error containing %q", err, test.wantErrSubstr)
286+
t.Errorf("ParseURL() err = %v, want error containing %q", err, test.wantErrSubstr)
287287
}
288288
} else {
289289
if err != nil {
290-
t.Errorf("ParseUrl() err = %v, want nil", err)
290+
t.Errorf("ParseURL() err = %v, want nil", err)
291291
}
292292
if diff := cmp.Diff(test.wantRepo, repo); diff != "" {
293-
t.Errorf("ParseUrl() repo mismatch (-want +got): %s", diff)
293+
t.Errorf("ParseURL() repo mismatch (-want +got): %s", diff)
294294
}
295295
}
296296
})

internal/librarian/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func cloneOrOpenLanguageRepo(workRoot, repo, ci string) (*gitrepo.Repository, er
3535
return nil, errors.New("repo must be specified")
3636
}
3737

38-
if isUrl(repo) {
38+
if isURL(repo) {
3939
// repo is a URL
4040
// Take the last part of the URL as the directory name. It feels very
4141
// unlikely that will clash with anything else (e.g. "output")

internal/librarian/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func newGenerateRunner(cfg *config.Config) (*generateRunner, error) {
120120
image := deriveImage(cfg.Image, state)
121121

122122
var ghClient GitHubClient
123-
if isUrl(cfg.Repo) {
123+
if isURL(cfg.Repo) {
124124
// repo is a URL
125125
languageRepo, err := github.ParseURL(cfg.Repo)
126126
if err != nil {

internal/librarian/generate_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func TestNewGenerateRunner(t *testing.T) {
317317
t.Run(test.name, func(t *testing.T) {
318318
t.Parallel()
319319
// We need to create a fake state and config file for the test to pass.
320-
if test.cfg.Repo != "" && !isUrl(test.cfg.Repo) {
320+
if test.cfg.Repo != "" && !isURL(test.cfg.Repo) {
321321
stateFile := filepath.Join(test.cfg.Repo, config.LibrarianDir, pipelineStateFile)
322322

323323
if err := os.MkdirAll(filepath.Dir(stateFile), 0755); err != nil {
@@ -360,7 +360,7 @@ func TestNewGenerateRunner(t *testing.T) {
360360
func newTestGitRepo(t *testing.T) *gitrepo.Repository {
361361
t.Helper()
362362
dir := t.TempDir()
363-
remoteUrl := "https://github.com/googleapis/librarian.git"
363+
remoteURL := "https://github.com/googleapis/librarian.git"
364364
runGit(t, dir, "init")
365365
runGit(t, dir, "config", "user.email", "test@example.com")
366366
runGit(t, dir, "config", "user.name", "Test User")
@@ -369,7 +369,7 @@ func newTestGitRepo(t *testing.T) *gitrepo.Repository {
369369
}
370370
runGit(t, dir, "add", "README.md")
371371
runGit(t, dir, "commit", "-m", "initial commit")
372-
runGit(t, dir, "remote", "add", "origin", remoteUrl)
372+
runGit(t, dir, "remote", "add", "origin", remoteURL)
373373
repo, err := gitrepo.NewRepository(&gitrepo.RepositoryOptions{Dir: dir})
374374
if err != nil {
375375
t.Fatalf("gitrepo.Open(%q) = %v", dir, err)

internal/librarian/librarian.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type ContainerClient interface {
8888
Configure(ctx context.Context, request *docker.ConfigureRequest) error
8989
}
9090

91-
func isUrl(s string) bool {
91+
func isURL(s string) bool {
9292
u, err := url.ParseRequestURI(s)
9393
if err != nil || u.Scheme == "" || u.Host == "" {
9494
return false

internal/librarian/librarian_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestRun(t *testing.T) {
2929
}
3030
}
3131

32-
func TestIsUrl(t *testing.T) {
32+
func TestIsURL(t *testing.T) {
3333
for _, test := range []struct {
3434
name string
3535
input string
@@ -82,9 +82,9 @@ func TestIsUrl(t *testing.T) {
8282
},
8383
} {
8484
t.Run(test.name, func(t *testing.T) {
85-
got := isUrl(test.input)
85+
got := isURL(test.input)
8686
if diff := cmp.Diff(test.want, got); diff != "" {
87-
t.Errorf("isUrl() mismatch (-want +got):\n%s", diff)
87+
t.Errorf("isURL() mismatch (-want +got):\n%s", diff)
8888
}
8989
})
9090
}

0 commit comments

Comments
 (0)