Skip to content

Commit

Permalink
Use cases and language import
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrocode committed Nov 17, 2022
1 parent 6ca7276 commit 4be4987
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ require (
go.uber.org/zap v1.23.0
golang.org/x/sync v0.1.0
golang.org/x/term v0.2.0
golang.org/x/text v0.4.0
gopkg.in/go-playground/validator.v9 v9.31.0
gopkg.in/yaml.v2 v2.4.0
)
Expand Down Expand Up @@ -135,7 +136,6 @@ require (
golang.org/x/net v0.2.0 // indirect
golang.org/x/oauth2 v0.2.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.2.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.103.0 // indirect
Expand Down
4 changes: 3 additions & 1 deletion server/core/runtime/policy/conftest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/runatlantis/atlantis/server/core/terraform"
"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/logging"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

const (
Expand Down Expand Up @@ -107,7 +109,7 @@ func (c ConfTestVersionDownloader) downloadConfTestVersion(v *version.Version, d
versionURLPrefix := fmt.Sprintf("%s%s", conftestDownloadURLPrefix, v.Original())

// download binary in addition to checksum file
binURL := fmt.Sprintf("%s/conftest_%s_%s_%s.tar.gz", versionURLPrefix, v.Original(), strings.Title(runtime.GOOS), conftestArch)
binURL := fmt.Sprintf("%s/conftest_%s_%s_%s.tar.gz", versionURLPrefix, v.Original(), cases.Title(language.English).String(runtime.GOOS), conftestArch)
checksumURL := fmt.Sprintf("%s/checksums.txt", versionURLPrefix)

// underlying implementation uses go-getter so the URL is formatted as such.
Expand Down
6 changes: 4 additions & 2 deletions server/core/runtime/policy/conftest_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"path/filepath"
"runtime"
"strings"
"testing"

"github.com/hashicorp/go-version"
Expand All @@ -18,14 +17,17 @@ import (
"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/logging"
. "github.com/runatlantis/atlantis/testing"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

func TestConfTestVersionDownloader(t *testing.T) {

version, _ := version.NewVersion("0.25.0")
destPath := "some/path"

fullURL := fmt.Sprintf("https://github.com/open-policy-agent/conftest/releases/download/v0.25.0/conftest_0.25.0_%s_x86_64.tar.gz?checksum=file:https://github.com/open-policy-agent/conftest/releases/download/v0.25.0/checksums.txt", strings.Title(runtime.GOOS))
fullURL := fmt.Sprintf("https://github.com/open-policy-agent/conftest/releases/download/v0.25.0/conftest_0.25.0_%s_x86_64.tar.gz?checksum=file:https://github.com/open-policy-agent/conftest/releases/download/v0.25.0/checksums.txt", cases.Title(language.English).String(runtime.GOOS))

RegisterMockTestingT(t)

Expand Down
9 changes: 7 additions & 2 deletions server/events/command/name.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package command

import "strings"
import (
"strings"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

// Name is which command to run.
type Name int
Expand All @@ -26,7 +31,7 @@ const (
// TitleString returns the string representation in title form.
// ie. policy_check becomes Policy Check
func (c Name) TitleString() string {
return strings.Title(strings.ReplaceAll(strings.ToLower(c.String()), "_", " "))
return cases.Title(language.English).String(strings.ReplaceAll(strings.ToLower(c.String()), "_", " "))
}

// String returns the string representation of c.
Expand Down
7 changes: 4 additions & 3 deletions server/events/commit_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ package events

import (
"fmt"
"strings"

"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/events/vcs"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_commit_status_updater.go CommitStatusUpdater
Expand Down Expand Up @@ -56,7 +57,7 @@ func (d *DefaultCommitStatusUpdater) UpdateCombined(repo models.Repo, pull model
case models.SuccessCommitStatus:
descripWords = "succeeded."
}
descrip := fmt.Sprintf("%s %s", strings.Title(cmdName.String()), descripWords)
descrip := fmt.Sprintf("%s %s", cases.Title(language.English).String(cmdName.String()), descripWords)
return d.Client.UpdateStatus(repo, pull, status, src, descrip, "")
}

Expand Down Expand Up @@ -92,6 +93,6 @@ func (d *DefaultCommitStatusUpdater) UpdateProject(ctx command.ProjectContext, c
descripWords = "succeeded."
}

descrip := fmt.Sprintf("%s %s", strings.Title(cmdName.String()), descripWords)
descrip := fmt.Sprintf("%s %s", cases.Title(language.English).String(cmdName.String()), descripWords)
return d.Client.UpdateStatus(ctx.BaseRepo, ctx.Pull, status, src, descrip, url)
}
4 changes: 3 additions & 1 deletion server/events/markdown_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/Masterminds/sprig/v3"
"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/events/models"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

var (
Expand Down Expand Up @@ -134,7 +136,7 @@ func GetMarkdownRenderer(
// Render formats the data into a markdown string.
// nolint: interfacer
func (m *MarkdownRenderer) Render(res command.Result, cmdName command.Name, log string, verbose bool, vcsHost models.VCSHostType) string {
commandStr := strings.Title(strings.Replace(cmdName.String(), "_", " ", -1))
commandStr := cases.Title(language.English).String(strings.Replace(cmdName.String(), "_", " ", -1))
common := commonData{
Command: commandStr,
Verbose: verbose,
Expand Down

0 comments on commit 4be4987

Please sign in to comment.