forked from kubernetes/community
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e74c32
commit aa817fa
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/csv" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
|
||
|
||
// struct to read the OWNERS file | ||
type Help struct { | ||
Approvers []string `yaml:"approvers"` | ||
Reviewers []string `yaml:"reviewers"` | ||
Labels []string `yaml:"labels"` | ||
} | ||
|
||
|
||
func main() { | ||
var b Help | ||
var pathfile []string | ||
|
||
//get a list of path present in the repo | ||
err := filepath.Walk(".", | ||
func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
pathfile = append(pathfile, path) | ||
|
||
return nil | ||
}) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
animals := [][]string{} | ||
|
||
//creating the csv file | ||
f, err := os.Create("owners-label.csv") | ||
if err != nil { | ||
log.Fatalln("failed to open file", err) | ||
} | ||
defer f.Close() | ||
|
||
w := csv.NewWriter(f) | ||
defer w.Flush() | ||
|
||
count := 0 | ||
|
||
//read owners file look for labels and put it in the csv | ||
for _, j := range pathfile { | ||
temp := []string{} | ||
if strings.Contains(j, "/OWNERS"){ | ||
data, err := ioutil.ReadFile(j) | ||
if err != nil { | ||
fmt.Println("File reading error", err) | ||
} | ||
if err = yaml.Unmarshal(data, &b); err != nil { | ||
log.Fatal(err) | ||
} | ||
temp = append(temp, j) | ||
temp =append(temp, b.Labels...) | ||
animals = append(animals, temp) | ||
|
||
if err := w.Write(animals[count]); err != nil { | ||
log.Fatalln("error writing record to file", err) | ||
} | ||
count= count +1 | ||
} | ||
} | ||
} | ||
|
||
|
||
|