Skip to content
This repository has been archived by the owner on Dec 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #97 from phrase/do-not-push-config
Browse files Browse the repository at this point in the history
config/push: do not push .phraseapp.yml configuration
  • Loading branch information
sacry-dyn authored Mar 23, 2017
2 parents f883c6c + 49d2379 commit 2ea5233
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/paths/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/phrase/phraseapp-client/internal/shared"
)

var YamlConfigName = ".phraseapp.yml"

func Validate(file, formatName, formatExtension string) error {
if strings.TrimSpace(file) == "" {
return fmt.Errorf("File patterns may not be empty!\nFor more information see %s", shared.DocsConfigUrl)
Expand Down Expand Up @@ -56,3 +58,7 @@ func Segments(s string) []string {

return strings.FieldsFunc(filepath.Clean(s), func(c rune) bool { return c == filepath.Separator })
}

func IsPhraseAppYmlConfig(path string) bool {
return strings.Contains(filepath.Base(path), YamlConfigName)
}
33 changes: 33 additions & 0 deletions internal/paths/paths_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package paths

import (
"testing"
)

func TestIsPhraseAppYamlConfig(t *testing.T) {
tests := []struct {
test string
expect bool
}{
{
test: "abc/*/.phraseapp.yml",
expect: true,
}, {
test: "abc/*/abc.phraseapp.yml",
expect: true,
}, {
test: "abc/*/.phraseapp.yml/lol.yml",
expect: false,
}, {
test: "abc/*/.phraseapp.yml/.yml",
expect: false,
},
}

for _, test := range tests {
was := IsPhraseAppYmlConfig(test.test)
if was != test.expect {
t.Fatalf("expected %q to yield %v, but was: %v", test.test, test.expect, was)
}
}
}
4 changes: 4 additions & 0 deletions push.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ func (source *Source) LocaleFiles() (LocaleFiles, error) {

var localeFiles LocaleFiles
for _, path := range filePaths {
if paths.IsPhraseAppYmlConfig(path) {
continue
}

localeFile := new(LocaleFile)
localeFile.fillFromPath(path, source.File)

Expand Down
3 changes: 3 additions & 0 deletions push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ func setupLocalesFiles(t *testing.T) (dir string) {
"b/YY/c/d.txt",
"b/YY/foo.bar.json",
"b/YY/foo.json",
"b/XX/.phraseapp.yml",
"b/XX/en.yml",
}
files = append(files, []string{
"config/locales/application.en.yml",
Expand Down Expand Up @@ -356,6 +358,7 @@ func TestLocaleFiles(t *testing.T) {
{"b/YY/foo.json", "", "foo", "", false},
{"b/YY/foo.bar.json", "", "foo.bar", "", false}, // weird locale!
}},
{"b/XX/<locale_name>.yml", []localeFile{{"b/XX/en.yml", "", "en", "", false}}},
}

for _, tti := range tt {
Expand Down

0 comments on commit 2ea5233

Please sign in to comment.