diff --git a/scripts/modowners/go.mod b/scripts/modowners/go.mod index 4c8b57c59f4..fa9ed513052 100644 --- a/scripts/modowners/go.mod +++ b/scripts/modowners/go.mod @@ -1,4 +1,4 @@ -module modowners +module github.com/grafana/grafana/scripts/modowners go 1.19 diff --git a/scripts/modowners/go.txd b/scripts/modowners/go.txd index 982b09c6189..aad0786577c 100644 --- a/scripts/modowners/go.txd +++ b/scripts/modowners/go.txd @@ -1,4 +1,4 @@ -module github.com/grafana/grafana +module github.com/grafana/grafana/scripts/modowners go 1.19 diff --git a/scripts/modowners/modowners_generation_script.go b/scripts/modowners/modowners_generation_script.go new file mode 100644 index 00000000000..ba0f401dc22 --- /dev/null +++ b/scripts/modowners/modowners_generation_script.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + "os" +) + +/* +load in the modules + for each module, call func that takes in module name and return list of files + with list of files, call func that takes in list of files, returns presumed owner (single team name) + modify modfile, write it back out (should be straightfwd) modfile.AddComment + need to write it back to my filesystem as go.mod.altered, compare to go.mod, raise the PR + + +write new output to test_go.mod so i can compare and make sure it's valid + when i want to raise pr, copy test_go.mod and paste into go.mod + +dont worry about if things are in the right place + +create folder called testdata +test files in the folder +whatever i want to do with this func, i do it with test data - return to the test +encourages me to write thing func so it doesnt print to stdoutput and parse from OS, rather send it io.Reader with w/e go.mod file and return either io.Writer or +call thing() + +best way to test things is usually to use test functions, and not the main func +no diff b/n test func and main func +*/ + +func getFiles(moduleName string) ([]string, error) { + fmt.Println("I AM GET FILES") + // get list of modules + m, err := parseGoMod(os.DirFS("."), "go.mod") + if err != nil { + return nil, err + } + + // for each module, return a list of files that import it + for _, mod := range m { + if mod.Indirect == false { + fmt.Println(mod) + } + } + return []string{}, nil +} diff --git a/scripts/modowners/modowners_generation_script_test.go b/scripts/modowners/modowners_generation_script_test.go index 4bc40e7dda5..f74b7d1d22f 100644 --- a/scripts/modowners/modowners_generation_script_test.go +++ b/scripts/modowners/modowners_generation_script_test.go @@ -5,27 +5,16 @@ import ( ) /* -load in the modules - - for each module, call func that takes in module name and return list of files - with list of files, call func that takes in list of files, returns presumed owner (single team name) - modify modfile, write it back out (should be straightfwd) modfile.AddComment - need to write it back to my filesystem as go.mod.altered, compare to go.mod, raise the PR - -write new output to test_go.mod so i can compare and make sure it's valid - - when i want to raise pr, copy test_go.mod and paste into go.mod - -dont worry about if things are in the right place +question: how do i mock files that import the below 3 imports and use said imports? */ func TestGetFiles(t *testing.T) { for _, test := range []struct { moduleName string expectedResult []string }{ - {"test1.mod", []string{"file1.go", "file2.go", "file3.go"}}, - {"test2.mod", []string{"file4.go"}}, - {"test3.mod", []string{"file5.go", "file6.go", "file7.go", "file8.go"}}, + {"cloud.google.com/go/storage v1.28.1", []string{"file1.go", "file2.go", "file3.go"}}, + {"cuelang.org/go v0.5.0", []string{"file4.go"}}, + {"github.com/Azure/azure-sdk-for-go v65.0.0+incompatible", []string{"file2.go", "file4.go", "file5.go"}}, } { result, err := getFiles(test.moduleName) if err != nil {