Skip to content

Commit

Permalink
move reading of distros to main func
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Wiesinger <[email protected]>
  • Loading branch information
mowies committed Dec 12, 2024
1 parent 2ebadce commit af6b14a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
19 changes: 10 additions & 9 deletions githubgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ func main() {
if len(generators) == 0 {
generators = []datatype.Generator{&issueTemplatesGenerator{}, &codeownersGenerator{skipGithub: *skipGithubCheck}}
}
if err := run(*folder, *allowlistFilePath, generators); err != nil {

distributions, err := getDistributions(*folder)
if err != nil {
log.Fatal(err)
}

if err = run(*folder, *allowlistFilePath, generators, distributions); err != nil {
log.Fatal(err)
}
}
Expand All @@ -71,13 +77,13 @@ func loadMetadata(filePath string) (datatype.Metadata, error) {
return md, nil
}

func run(folder string, allowlistFilePath string, generators []datatype.Generator) error {
func run(folder string, allowlistFilePath string, generators []datatype.Generator, distros []datatype.DistributionData) error {
components := map[string]datatype.Metadata{}
var foldersList []string
maxLength := 0
var allCodeowners []string
err := filepath.Walk(folder, func(path string, info fs.FileInfo, _ error) error {
if info.Name() == "datatype.Metadata.yaml" {
if info.Name() == "metadata.yaml" {
m, err := loadMetadata(path)
if err != nil {
return err
Expand Down Expand Up @@ -115,18 +121,13 @@ func run(folder string, allowlistFilePath string, generators []datatype.Generato
slices.Sort(allCodeowners)
allCodeowners = slices.Compact(allCodeowners)

distributions, err := getDistributions(folder)
if err != nil {
return err
}

data := datatype.GithubData{
Folders: foldersList,
Codeowners: allCodeowners,
AllowlistFilePath: allowlistFilePath,
MaxLength: maxLength,
Components: components,
Distributions: distributions,
Distributions: distros,
}

for _, g := range generators {
Expand Down
18 changes: 15 additions & 3 deletions githubgen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func Test_run(t *testing.T) {
folder string
allowlistFilePath string
generators fake.MockGenerator
distributions []datatype.DistributionData
}
tests := []struct {
name string
Expand All @@ -25,17 +26,28 @@ func Test_run(t *testing.T) {
args: args{
folder: ".",
allowlistFilePath: "cmd/githubgen/allowlist.txt",
generators: fake.MockGenerator{},
generators: fake.MockGenerator{
GenerateFunc: func(data datatype.GithubData) error {
return nil
},
},
distributions: []datatype.DistributionData{
{
Name: "my-distro",
URL: "some-url",
Maintainers: nil,
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := run(tt.args.folder, tt.args.allowlistFilePath, []datatype.Generator{&tt.args.generators}); (err != nil) != tt.wantErr {
if err := run(tt.args.folder, tt.args.allowlistFilePath, []datatype.Generator{&tt.args.generators}, tt.args.distributions); (err != nil) != tt.wantErr {
t.Errorf("run() error = %v, wantErr %v", err, tt.wantErr)
}
require.Equal(t, tt.args.generators.GenerateCalls(), 1)
require.Equal(t, len(tt.args.generators.GenerateCalls()), 1)
})
}
}

0 comments on commit af6b14a

Please sign in to comment.