Skip to content

Commit

Permalink
owner lable csv program
Browse files Browse the repository at this point in the history
  • Loading branch information
AvineshTripathi committed Dec 15, 2021
1 parent 9e74c32 commit aa817fa
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions owner-lable.go
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
}
}
}



0 comments on commit aa817fa

Please sign in to comment.