Ejemplo n.º 1
0
Archivo: be.go Proyecto: Komosa/bug
func beImportBug(identifier, issuesDir, fullbepath string) {
	/* BE appears to store the top level data of a bug
	   ins a json file named values with the format:
	    {
	        "creator": "Dave MacFarlane <*****@*****.**>",
	        "reporter": "Dave MacFarlane <*****@*****.**>",
	        "severity": "minor",
	        "status": "open",
	        "summary": "abc",
	        "time": "Tue, 12 Jan 2016 00:05:28 +0000"
	    }

	    and the description of bugs entirely in comments.
	    All we really care about is the summary so that we
	    can get the directory name for the issues/ directory,
	    but the severity+status can also be used as a status
	    to ensure that we have at least 1 file to be tracked
	    by git.
	*/

	type BeValues struct {
		Creator  string `json:creator`
		Reporter string `json:reporter`
		Severity string `json:severity`
		Status   string `json:status`
		Summary  string `json:summary`
		Time     string `json:time`
	}
	file := fullbepath + "/values"

	fmt.Printf("File: %s\n", file)
	data, _ := ioutil.ReadFile(file)
	var beBug BeValues
	err := json.Unmarshal([]byte(data), &beBug)
	if err != nil {
		fmt.Printf("Error unmarshalling data: %s\n", err.Error())
	}

	fmt.Printf("%s\n", beBug)

	bugdir := bugs.TitleToDir(beBug.Summary)

	b := bugs.Bug{bugs.Directory(issuesDir) + bugdir}
	if dir := b.GetDirectory(); dir != "" {
		os.Mkdir(string(dir), 0755)
	}
	if beBug.Status != "" && beBug.Severity != "" {
		b.SetStatus(beBug.Status + ":" + beBug.Severity)
	}

	comments := fullbepath + "/comments/"
	dir, err := os.Open(comments)

	files, err := dir.Readdir(-1)
	var Description string
	if len(files) > 0 && err == nil {
		for _, file := range files {
			if file.IsDir() {
				Description = Description + "\n" +
					beImportComments(b, comments+file.Name(), len(files) > 1)
			}
		}
	}
	b.SetDescription(Description)
	b.SetIdentifier(identifier)
}