Add a skip field to the repository configuration

This commit is contained in:
Mikołaj Pęczkowski 2021-11-08 20:34:32 +01:00
parent 62dadc53bf
commit 19e68df732
4 changed files with 74 additions and 2 deletions

View File

@ -139,6 +139,11 @@ func (g *GitRepositoryManager) runCommand(cmd commands.Command) {
var wg sync.WaitGroup var wg sync.WaitGroup
for _, repo := range g.configuration.Repositories { for _, repo := range g.configuration.Repositories {
if repo.Skip && !g.cliArguments.IgnoreSkipped {
continue
}
wg.Add(1) wg.Add(1)
go func(r config.RepositoryConfig) { go func(r config.RepositoryConfig) {

View File

@ -371,3 +371,63 @@ func TestDescribeStatusNoChangeColor(t *testing.T) {
describeStatus(status) describeStatus(status)
} }
func TestSkipRepository(t *testing.T) {
grm := GitRepositoryManager{
cliArguments: config.CliArguments{
LimitToTags: []string{"example"},
Routines: 10,
},
configuration: config.Configuration{
Repositories: []config.RepositoryConfig{
{Name: "example1"},
{Name: "example2", Skip: true},
{Name: "example3"},
},
},
}
fakeCommand := FakeCommandToTest{
triggerError: false,
triggerChanged: false,
}
emt := ExpectedMessageTester{
expectedMessages: []string{
"Repository \"example1\": response from fake command\n",
"Repository \"example3\": response from fake command\n",
},
}
echo.Color(false)
echo.Output(emt)
grm.runCommand(fakeCommand)
}
func TestSkipRepositoryWithIgnore(t *testing.T) {
grm := GitRepositoryManager{
cliArguments: config.CliArguments{
LimitToTags: []string{"example"},
Routines: 10,
IgnoreSkipped: true,
},
configuration: config.Configuration{
Repositories: []config.RepositoryConfig{
{Name: "example1"},
{Name: "example2", Skip: true},
{Name: "example3"},
},
},
}
fakeCommand := FakeCommandToTest{
triggerError: false,
triggerChanged: false,
}
emt := ExpectedMessageTester{
expectedMessages: []string{
"Repository \"example1\": response from fake command\n",
"Repository \"example2\": response from fake command\n",
"Repository \"example3\": response from fake command\n",
},
}
echo.Color(false)
echo.Output(emt)
grm.runCommand(fakeCommand)
}

View File

@ -53,6 +53,10 @@ func ParseCliArguments(name, description string, arguments []string) (CliArgumen
Help: "Determine how many tasks can run simultaneously", Help: "Determine how many tasks can run simultaneously",
}) })
ignoreSkipped := parser.Flag("", "ignore-skip-flag", &argparse.Options{
Help: "Run selected command for all repositories with ignoring the skip flag",
})
if err := parser.Parse(arguments); err != nil { if err := parser.Parse(arguments); err != nil {
return CliArguments{}, errors.New(parser.Usage("Please follow this help")) return CliArguments{}, errors.New(parser.Usage("Please follow this help"))
} }
@ -74,5 +78,6 @@ func ParseCliArguments(name, description string, arguments []string) (CliArgumen
LimitToName: *limitName, LimitToName: *limitName,
LimitToTags: *limitTags, LimitToTags: *limitTags,
Routines: *limitRoutines, Routines: *limitRoutines,
IgnoreSkipped: *ignoreSkipped,
}, nil }, nil
} }

View File

@ -7,9 +7,10 @@ type Configuration struct {
type RepositoryConfig struct { type RepositoryConfig struct {
Name string `yaml:",omitempty"` Name string `yaml:",omitempty"`
Src string `yaml:",omitempty"` Src string
Dest string `yaml:",omitempty"` Dest string `yaml:",omitempty"`
Tags []string `yaml:",omitempty"` Tags []string `yaml:",omitempty"`
Skip bool
} }
type CliArguments struct { type CliArguments struct {
@ -21,4 +22,5 @@ type CliArguments struct {
LimitToName string LimitToName string
LimitToTags []string LimitToTags []string
Routines int Routines int
IgnoreSkipped bool
} }