Skip to content

Commit 2984d7a

Browse files
authored
refactor: standardize logging messages to lowercase (#2750)
Normalize all log messages to lowercase for consistency across the codebase.
1 parent 264a6a0 commit 2984d7a

File tree

18 files changed

+87
-87
lines changed

18 files changed

+87
-87
lines changed

internal/automation/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ func Run(args []string) error {
3030
ctx := context.Background()
3131
options, err := parseFlags(args)
3232
if err != nil {
33-
slog.Error("Error parsing command", slog.Any("err", err))
33+
slog.Error("error parsing command", slog.Any("err", err))
3434
return err
3535
}
3636

3737
err = runCommandFn(ctx, options.Command, options.ProjectId, options.Push, options.Build, options.ForceRun)
3838
if err != nil {
39-
slog.Error("Error running command", slog.Any("err", err))
39+
slog.Error("error running command", slog.Any("err", err))
4040
return err
4141
}
4242
return nil

internal/automation/trigger.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func runCommandWithConfig(ctx context.Context, client CloudBuildClient, ghClient
9797
if triggerName == "stage-release" {
9898
_, week := dateTime.ISOWeek()
9999
if week%2 == 0 && !forceRun {
100-
slog.Info("Skipping stage-release on an even week.")
100+
slog.Info("skipping stage-release on an even week.")
101101
return nil
102102
}
103103
}
@@ -124,12 +124,12 @@ func runCommandWithConfig(ctx context.Context, client CloudBuildClient, ghClient
124124
repositoryOwner := parts[len(parts)-2]
125125
prs, err := ghClient.FindMergedPullRequestsWithPendingReleaseLabel(ctx, repositoryOwner, repository.Name)
126126
if err != nil {
127-
slog.Error("Error finding merged pull requests for publish-release", slog.Any("err", err), slog.String("repository", repository.Name))
127+
slog.Error("error finding merged pull requests for publish-release", slog.Any("err", err), slog.String("repository", repository.Name))
128128
errs = append(errs, err)
129129
continue
130130
}
131131
if len(prs) == 0 {
132-
slog.Info("No pull requests with label 'release:pending' found. Skipping 'publish-release' trigger.", slog.String("repository", repository.Name))
132+
slog.Info("no pull requests with label 'release:pending' found. Skipping 'publish-release' trigger.", slog.String("repository", repository.Name))
133133
continue
134134
} else {
135135
substitutions["_PR"] = fmt.Sprintf("%v", prs[0].GetHTMLURL())
@@ -140,7 +140,7 @@ func runCommandWithConfig(ctx context.Context, client CloudBuildClient, ghClient
140140
}
141141
err = runCloudBuildTriggerByName(ctx, client, projectId, region, triggerName, substitutions)
142142
if err != nil {
143-
slog.Error("Error triggering cloudbuild", slog.Any("err", err))
143+
slog.Error("error triggering cloudbuild", slog.Any("err", err))
144144
errs = append(errs, err)
145145
}
146146
}

internal/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,15 @@ func (c *Config) setupUser() error {
277277

278278
func (c *Config) createWorkRoot() error {
279279
if c.WorkRoot != "" {
280-
slog.Info("Using specified working directory", "dir", c.WorkRoot)
280+
slog.Info("using specified working directory", "dir", c.WorkRoot)
281281
return nil
282282
}
283283
path, err := os.MkdirTemp(tempDir(), "librarian-*")
284284
if err != nil {
285285
return err
286286
}
287287

288-
slog.Info("Temporary working directory", "dir", path)
288+
slog.Info("temporary working directory", "dir", path)
289289
c.WorkRoot = path
290290
return nil
291291
}

internal/github/github.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ func (c *Client) GetRawContent(ctx context.Context, path, ref string) ([]byte, e
188188
// which must have a GitHub HTTPS URL. We assume a base branch of "main".
189189
func (c *Client) CreatePullRequest(ctx context.Context, repo *Repository, remoteBranch, baseBranch, title, body string, isDraft bool) (*PullRequestMetadata, error) {
190190
if body == "" {
191-
slog.Warn("Provided PR body is empty, setting default.")
191+
slog.Warn("provided PR body is empty, setting default.")
192192
body = "Regenerated all changed APIs. See individual commits for details."
193193
}
194-
slog.Info("Creating PR", "branch", remoteBranch, "base", baseBranch, "title", title)
194+
slog.Info("creating PR", "branch", remoteBranch, "base", baseBranch, "title", title)
195195
// The body may be excessively long, only display in debug mode.
196196
slog.Debug("with PR body", "body", body)
197197
newPR := &github.NewPullRequest{
@@ -207,14 +207,14 @@ func (c *Client) CreatePullRequest(ctx context.Context, repo *Repository, remote
207207
return nil, err
208208
}
209209

210-
slog.Info("PR created", "url", pr.GetHTMLURL())
210+
slog.Info("pr created", "url", pr.GetHTMLURL())
211211
pullRequestMetadata := &PullRequestMetadata{Repo: repo, Number: pr.GetNumber()}
212212
return pullRequestMetadata, nil
213213
}
214214

215215
// GetLabels fetches the labels for an issue.
216216
func (c *Client) GetLabels(ctx context.Context, number int) ([]string, error) {
217-
slog.Info("Getting labels", "number", number)
217+
slog.Info("getting labels", "number", number)
218218
var allLabels []string
219219
opts := &github.ListOptions{
220220
PerPage: 100,
@@ -237,14 +237,14 @@ func (c *Client) GetLabels(ctx context.Context, number int) ([]string, error) {
237237

238238
// ReplaceLabels replaces all labels for an issue.
239239
func (c *Client) ReplaceLabels(ctx context.Context, number int, labels []string) error {
240-
slog.Info("Replacing labels", "number", number, "labels", labels)
240+
slog.Info("replacing labels", "number", number, "labels", labels)
241241
_, _, err := c.Issues.ReplaceLabelsForIssue(ctx, c.repo.Owner, c.repo.Name, number, labels)
242242
return err
243243
}
244244

245245
// AddLabelsToIssue adds labels to an existing issue in a GitHub repository.
246246
func (c *Client) AddLabelsToIssue(ctx context.Context, repo *Repository, number int, labels []string) error {
247-
slog.Info("Labels added to issue", "number", number, "labels", labels)
247+
slog.Info("labels added to issue", "number", number, "labels", labels)
248248
_, _, err := c.Issues.AddLabelsToIssue(ctx, repo.Owner, repo.Name, number, labels)
249249
return err
250250
}
@@ -351,7 +351,7 @@ func (c *Client) FindMergedPullRequestsWithLabel(ctx context.Context, owner, rep
351351
// CreateTag creates a lightweight tag in the repository at the given commit SHA.
352352
// This does NOT create a release, just the tag.
353353
func (c *Client) CreateTag(ctx context.Context, tagName, commitSHA string) error {
354-
slog.Info("Creating tag", "tag", tagName, "commit", commitSHA)
354+
slog.Info("creating tag", "tag", tagName, "commit", commitSHA)
355355
ref := "refs/tags/" + tagName
356356
tagRef := &github.Reference{
357357
Ref: github.Ptr(ref),
@@ -363,7 +363,7 @@ func (c *Client) CreateTag(ctx context.Context, tagName, commitSHA string) error
363363

364364
// ClosePullRequest closes the pull request specified by pull request number.
365365
func (c *Client) ClosePullRequest(ctx context.Context, number int) error {
366-
slog.Info("Closing pull request", slog.Int("number", number))
366+
slog.Info("closing pull request", slog.Int("number", number))
367367
state := "closed"
368368
_, _, err := c.PullRequests.Edit(ctx, c.repo.Owner, c.repo.Name, number, &github.PullRequest{
369369
State: &state,

internal/gitrepo/gitrepo.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func newRepositoryWithoutUser(opts *RepositoryOptions) (*LocalRepository, error)
123123
if !opts.MaybeClone {
124124
return open(opts.Dir)
125125
}
126-
slog.Info("Checking for repository", "dir", opts.Dir)
126+
slog.Info("checking for repository", "dir", opts.Dir)
127127
_, err := os.Stat(opts.Dir)
128128
if err == nil {
129129
return open(opts.Dir)
@@ -135,14 +135,14 @@ func newRepositoryWithoutUser(opts *RepositoryOptions) (*LocalRepository, error)
135135
if opts.RemoteBranch == "" {
136136
return nil, fmt.Errorf("gitrepo: remote branch is required when cloning")
137137
}
138-
slog.Info("Repository not found, executing clone")
138+
slog.Info("repository not found, executing clone")
139139
return clone(opts.Dir, opts.RemoteURL, opts.RemoteBranch, opts.CI, opts.Depth)
140140
}
141141
return nil, fmt.Errorf("failed to check for repository at %q: %w", opts.Dir, err)
142142
}
143143

144144
func open(dir string) (*LocalRepository, error) {
145-
slog.Info("Opening repository", "dir", dir)
145+
slog.Info("opening repository", "dir", dir)
146146
repo, err := git.PlainOpen(dir)
147147
if err != nil {
148148
return nil, err
@@ -155,7 +155,7 @@ func open(dir string) (*LocalRepository, error) {
155155
}
156156

157157
func clone(dir, url, branch, ci string, depth int) (*LocalRepository, error) {
158-
slog.Info("Cloning repository", "url", url, "dir", dir)
158+
slog.Info("cloning repository", "url", url, "dir", dir)
159159
options := &git.CloneOptions{
160160
URL: url,
161161
ReferenceName: plumbing.NewBranchReferenceName(branch),
@@ -197,7 +197,7 @@ func (r *LocalRepository) AddAll() error {
197197
// Commit creates a new commit with the provided message and author
198198
// information.
199199
func (r *LocalRepository) Commit(msg string) error {
200-
slog.Info("Committing", "message", msg)
200+
slog.Info("committing", "message", msg)
201201
worktree, err := r.repo.Worktree()
202202
if err != nil {
203203
return err
@@ -239,7 +239,7 @@ func (r *LocalRepository) IsClean() (bool, error) {
239239
// ChangedFiles returns a list of files that have been modified, added, or deleted
240240
// in the working tree, including both staged and unstaged changes.
241241
func (r *LocalRepository) ChangedFiles() ([]string, error) {
242-
slog.Debug("Getting changed files")
242+
slog.Debug("getting changed files")
243243
worktree, err := r.repo.Worktree()
244244
if err != nil {
245245
return nil, err
@@ -301,7 +301,7 @@ func (r *LocalRepository) GetCommit(commitHash string) (*Commit, error) {
301301

302302
// GetLatestCommit returns the latest commit of the given path in the repository.
303303
func (r *LocalRepository) GetLatestCommit(path string) (*Commit, error) {
304-
slog.Info("Retrieving the latest commit", "path", path)
304+
slog.Info("retrieving the latest commit", "path", path)
305305
opt := &git.LogOptions{
306306
Order: git.LogOrderCommitterTime,
307307
FileName: &path,
@@ -450,7 +450,7 @@ func getHashForPath(commit *object.Commit, path string) (string, error) {
450450

451451
// ChangedFilesInCommit returns the files changed in the given commit.
452452
func (r *LocalRepository) ChangedFilesInCommit(commitHash string) ([]string, error) {
453-
slog.Debug("Getting changed files in commit", "hash", commitHash)
453+
slog.Debug("getting changed files in commit", "hash", commitHash)
454454
commit, err := r.repo.CommitObject(plumbing.NewHash(commitHash))
455455
if err != nil {
456456
return nil, fmt.Errorf("failed to get commit object for hash %s: %w", commitHash, err)
@@ -500,7 +500,7 @@ func (r *LocalRepository) ChangedFilesInCommit(commitHash string) ([]string, err
500500
// CreateBranchAndCheckout creates a new git branch and checks out the
501501
// branch in the local git repository.
502502
func (r *LocalRepository) CreateBranchAndCheckout(name string) error {
503-
slog.Info("Creating branch and checking out", "name", name)
503+
slog.Info("creating branch and checking out", "name", name)
504504
worktree, err := r.repo.Worktree()
505505
if err != nil {
506506
return err
@@ -516,7 +516,7 @@ func (r *LocalRepository) CreateBranchAndCheckout(name string) error {
516516
func (r *LocalRepository) Push(branchName string) error {
517517
// https://stackoverflow.com/a/75727620
518518
refSpec := fmt.Sprintf("+refs/heads/%s:refs/heads/%s", branchName, branchName)
519-
slog.Info("Pushing changes", "branch name", branchName, slog.Any("refspec", refSpec))
519+
slog.Info("pushing changes", "branch name", branchName, slog.Any("refspec", refSpec))
520520
return r.pushRefSpec(refSpec)
521521
}
522522

@@ -527,7 +527,7 @@ func (r *LocalRepository) DeleteBranch(branchName string) error {
527527
}
528528

529529
func (r *LocalRepository) pushRefSpec(refSpec string) error {
530-
slog.Info("Pushing changes", "refSpec", refSpec)
530+
slog.Info("pushing changes", "refSpec", refSpec)
531531

532532
// Check for the configured URI for the `origin` remote.
533533
// If there are multiple URLs, the first one is selected.
@@ -558,7 +558,7 @@ func (r *LocalRepository) pushRefSpec(refSpec string) error {
558558
}); err != nil {
559559
return err
560560
}
561-
slog.Info("Successfully pushed changes", "refSpec", refSpec)
561+
slog.Info("successfully pushed changes", "refSpec", refSpec)
562562
return nil
563563
}
564564

@@ -593,7 +593,7 @@ func canUseSSH(remoteURI string) bool {
593593
// remote repository. The useSSH determines if Basic Auth or SSH is used.
594594
func (r *LocalRepository) authCreds(useSSH bool) (transport.AuthMethod, error) {
595595
if useSSH {
596-
slog.Info("Authenticating with SSH")
596+
slog.Info("authenticating with SSH")
597597
// This is the generic `git` username when cloning via SSH. It is the value
598598
// that exists before the URL. e.g. [email protected]:googleapis/librarian.git
599599
auth, err := ssh.DefaultAuthBuilder("git")
@@ -602,7 +602,7 @@ func (r *LocalRepository) authCreds(useSSH bool) (transport.AuthMethod, error) {
602602
}
603603
return auth, nil
604604
}
605-
slog.Info("Authenticating with basic auth")
605+
slog.Info("authenticating with basic auth")
606606
return &httpAuth.BasicAuth{
607607
// GitHub's authentication needs the username set to a non-empty value, but
608608
// it does not need to match the token
@@ -619,7 +619,7 @@ func (r *LocalRepository) authCreds(useSSH bool) (transport.AuthMethod, error) {
619619
func (r *LocalRepository) Restore(paths []string) error {
620620
args := []string{"restore"}
621621
args = append(args, paths...)
622-
slog.Info("Restoring uncommitted changes", "paths", strings.Join(paths, ","))
622+
slog.Info("restoring uncommitted changes", "paths", strings.Join(paths, ","))
623623
cmd := exec.Command("git", args...)
624624
cmd.Stderr = os.Stderr
625625
cmd.Stdout = os.Stdout
@@ -629,7 +629,7 @@ func (r *LocalRepository) Restore(paths []string) error {
629629

630630
// CleanUntracked removes untracked files within the given paths.
631631
func (r *LocalRepository) CleanUntracked(paths []string) error {
632-
slog.Info("Cleaning untracked files", "paths", strings.Join(paths, ","))
632+
slog.Info("cleaning untracked files", "paths", strings.Join(paths, ","))
633633
worktree, err := r.repo.Worktree()
634634
if err != nil {
635635
return err

internal/images/images.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ func (c *ArtifactRegistryClient) FindLatest(ctx context.Context, imageName strin
102102
if err != nil {
103103
return "", err
104104
}
105-
slog.Info("Found packages version", "version", version.GetName())
105+
slog.Info("found packages version", "version", version.GetName())
106106

107107
// latest SHA is found as the "subjectDigest" metadata field
108108
latestSha := ""
109109
for key, field := range version.GetMetadata().GetFields() {
110110
if key == "subjectDigest" {
111-
slog.Info("Found SHA", "sha", field.GetStringValue())
111+
slog.Info("found SHA", "sha", field.GetStringValue())
112112
latestSha = field.GetStringValue()
113113
break
114114
}

internal/librarian/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func buildSingleLibrary(ctx context.Context, containerClient ContainerClient, st
3535
RepoDir: repo.GetDir(),
3636
State: state,
3737
}
38-
slog.Info("Performing build for library", "id", libraryState.ID)
38+
slog.Info("performing build for library", "id", libraryState.ID)
3939
if containerErr := containerClient.Build(ctx, buildRequest); containerErr != nil {
4040
if restoreErr := restoreLibrary(libraryState, repo); restoreErr != nil {
4141
return errors.Join(containerErr, restoreErr)
@@ -54,6 +54,6 @@ func buildSingleLibrary(ctx context.Context, containerClient ContainerClient, st
5454
return responseErr
5555
}
5656

57-
slog.Info("Build succeeds", "id", libraryState.ID)
57+
slog.Info("build succeeds", "id", libraryState.ID)
5858
return nil
5959
}

0 commit comments

Comments
 (0)