Skip to content

Commit

Permalink
Fix various style issues (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
fweikert authored Jul 19, 2024
1 parent 5e89768 commit 013d0e9
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package config reads Bazelisk configuration settings from files and the environment.
package config

import (
Expand Down
32 changes: 17 additions & 15 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var (
// Bazel with.
type ArgsFunc func(resolvedBazelVersion string) []string

// MakeDefaultConfig returns a config based on env and .bazeliskrc files.
func MakeDefaultConfig() config.Config {
configs := []config.Config{config.FromEnv()}

Expand Down Expand Up @@ -245,6 +246,7 @@ func getUserAgent(config config.Config) string {
return fmt.Sprintf("Bazelisk/%s", BazeliskVersion)
}

// GetBazelVersion returns the Bazel version that should be used.
func GetBazelVersion(config config.Config) (string, error) {
// Check in this order:
// - env var "USE_BAZEL_VERSION" is set to a specific version.
Expand Down Expand Up @@ -729,19 +731,19 @@ func cleanIfNeeded(bazelPath string, startupOptions []string, config config.Conf
}
}

type ParentCommit struct {
type parentCommit struct {
SHA string `json:"sha"`
}

type Commit struct {
type commit struct {
SHA string `json:"sha"`
PARENTS []ParentCommit `json:"parents"`
PARENTS []parentCommit `json:"parents"`
}

type CompareResponse struct {
Commits []Commit `json:"commits"`
BaseCommit Commit `json:"base_commit"`
MergeBaseCommit Commit `json:"merge_base_commit"`
type compareResponse struct {
Commits []commit `json:"commits"`
BaseCommit commit `json:"base_commit"`
MergeBaseCommit commit `json:"merge_base_commit"`
}

func sendRequest(url string, config config.Config) (*http.Response, error) {
Expand Down Expand Up @@ -787,31 +789,31 @@ func getBazelCommitsBetween(goodCommit string, badCommit string, config config.C
return goodCommit, nil, fmt.Errorf("unexpected response status code %d: %s", response.StatusCode, string(body))
}

var compareResponse CompareResponse
err = json.Unmarshal(body, &compareResponse)
var compResp compareResponse
err = json.Unmarshal(body, &compResp)
if err != nil {
return goodCommit, nil, fmt.Errorf("Error unmarshaling JSON: %v", err)
}

if len(compareResponse.Commits) == 0 {
if len(compResp.Commits) == 0 {
break
}

mergeBaseCommit := compareResponse.MergeBaseCommit.SHA
if mergeBaseCommit != compareResponse.BaseCommit.SHA {
mergeBaseCommit := compResp.MergeBaseCommit.SHA
if mergeBaseCommit != compResp.BaseCommit.SHA {
fmt.Printf("The good Bazel commit is not an ancestor of the bad Bazel commit, overriding the good Bazel commit to the merge base commit %s\n", mergeBaseCommit)
goodCommit = mergeBaseCommit
}

for _, commit := range compareResponse.Commits {
for _, commit := range compResp.Commits {
// If it has only one parent commit, add it to the list, otherwise it's a merge commit and we ignore it
if len(commit.PARENTS) == 1 {
commitList = append(commitList, commit.SHA)
}
}

// Check if there are more commits to fetch
if len(compareResponse.Commits) < perPage {
if len(compResp.Commits) < perPage {
break
}

Expand Down
1 change: 1 addition & 0 deletions core/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func (r *Repositories) DownloadFromBaseURL(baseURL, version, destDir, destFile s
return httputil.DownloadBinary(url, destDir, destFile, config)
}

// BuildURLFromFormat returns a Bazel download URL based on formatURL.
func BuildURLFromFormat(config config.Config, formatURL, version string) (string, error) {
osName, err := platforms.DetermineOperatingSystem()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion httputil/httputil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestSuccessOnRetryNonHTTPError(t *testing.T) {

url := "http://foo"
want := "the_body"
transport.AddError(url, errors.New("boom!"))
transport.AddError(url, errors.New("boom"))
transport.AddResponse(url, 200, want, nil)
body, _, err := ReadRemoteFile(url, "")

Expand Down
2 changes: 2 additions & 0 deletions httputil/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func showProgress(config config.Config) bool {
return true
}

// Writer creates an io.Writer to print the progress.
func Writer(w io.Writer, header string, total int64, config config.Config) io.Writer {
if !showProgress(config) {
return w
Expand All @@ -69,6 +70,7 @@ func Writer(w io.Writer, header string, total int64, config config.Config) io.Wr
return out
}

// Finish writes final output after the progress bar is complete.
func Finish(config config.Config) {
if showProgress(config) {
// Add a newline after the progress bar
Expand Down
4 changes: 2 additions & 2 deletions httputil/progress/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestFormatMb(t *testing.T) {
t.Run(name, func(t *testing.T) {
got := formatMb(tc.input)
if got != tc.want {
t.Fatalf("Expected %q, but got %q", tc.want, got)
t.Errorf("formatMb() = %q, want %q", got ,tc.want)
}
})
}
Expand All @@ -45,7 +45,7 @@ func TestFormatPercentage(t *testing.T) {
t.Run(name, func(t *testing.T) {
got := formatPercentage(tc.curr, tc.total)
if got != tc.want {
t.Fatalf("Expected %q, but got %q", tc.want, got)
t.Fatalf("formatPercentage() = %q, want %q", got, tc.want)
}
})
}
Expand Down
2 changes: 2 additions & 0 deletions platforms/platforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func DetermineExecutableFilenameSuffix() string {
return filenameSuffix
}

// DetermineArchitecture returns the architecture of the current machine.
func DetermineArchitecture(osName, version string) (string, error) {
var machineName string
switch runtime.GOARCH {
Expand All @@ -73,6 +74,7 @@ func DetermineArchitecture(osName, version string) (string, error) {
return machineName, nil
}

// DetermineOperatingSystem returns the name of the operating system.
func DetermineOperatingSystem() (string, error) {
switch runtime.GOOS {
case "darwin", "linux", "windows":
Expand Down
1 change: 1 addition & 0 deletions ws/ws.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package ws offers functions to get information about Bazel workspaces.
package ws

import (
Expand Down

0 comments on commit 013d0e9

Please sign in to comment.