func (fjr *FlakyJobReporter) parseFlakyJobs(jsonIn []byte) ([]*FlakyJob, error) {
	var flakeMap map[string]*FlakyJob
	err := json.Unmarshal(jsonIn, &flakeMap)
	if err != nil || flakeMap == nil {
		return nil, fmt.Errorf("error unmarshaling flaky jobs json: %v", err)
	}
	flakyJobs := make([]*FlakyJob, 0, len(flakeMap))

	for job, fj := range flakeMap {
		if job == "" {
			glog.Errorf("Flaky jobs json contained a job with an empty jobname.\n")
			continue
		}
		if fj == nil {
			glog.Errorf("Flaky jobs json has invalid data for job '%s'.\n", job)
			continue
		}
		if fj.Consistency == nil {
			glog.Errorf("Flaky jobs json has no 'consistency' field for job '%s'.\n", job)
			continue
		}
		if fj.FlakeCount == nil {
			glog.Errorf("Flaky jobs json has no 'flakes' field for job '%s'.\n", job)
			continue
		}
		if fj.FlakyTests == nil {
			glog.Errorf("Flaky jobs json has no 'flakiest' field for job '%s'.\n", job)
			continue
		}
		fj.Name = job
		fj.reporter = fjr
		flakyJobs = append(flakyJobs, fj)
	}

	sort.SliceStable(flakyJobs, func(i, j int) bool {
		if *flakyJobs[i].FlakeCount == *flakyJobs[j].FlakeCount {
			return *flakyJobs[i].Consistency < *flakyJobs[j].Consistency
		}
		return *flakyJobs[i].FlakeCount > *flakyJobs[j].FlakeCount
	})

	return flakyJobs, nil
}
func (fjr *FlakyJobReporter) parseFlakyJobs(jsonIn []byte) ([]*FlakyJob, error) {
	var flakeMap map[string]*FlakyJob
	err := json.Unmarshal(jsonIn, &flakeMap)
	if err != nil || flakeMap == nil {
		return nil, fmt.Errorf("error unmarshaling flaky jobs json: %v", err)
	}
	flakyJobs := make([]*FlakyJob, 0, len(flakeMap))

	for job, fj := range flakeMap {
		if job == "" {
			glog.Errorf("Flaky jobs json contained a job with an empty jobname.\n")
			continue
		}
		if fj == nil {
			glog.Errorf("Flaky jobs json has invalid data for job '%s'.\n", job)
			continue
		}
		if fj.Consistency == nil {
			glog.Errorf("Flaky jobs json has no 'consistency' field for job '%s'.\n", job)
			continue
		}
		if fj.FlakeCount == nil {
			glog.Errorf("Flaky jobs json has no 'flakes' field for job '%s'.\n", job)
			continue
		}
		if fj.FlakyTests == nil {
			glog.Errorf("Flaky jobs json has no 'flakiest' field for job '%s'.\n", job)
			continue
		}
		fj.Name = job
		fj.reporter = fjr
		flakyJobs = append(flakyJobs, fj)
	}

	sort.SliceStable(flakyJobs, func(i, j int) bool {
		if *flakyJobs[i].FlakeCount == *flakyJobs[j].FlakeCount {
			return *flakyJobs[i].Consistency < *flakyJobs[j].Consistency
		}
		return *flakyJobs[i].FlakeCount > *flakyJobs[j].FlakeCount
	})

	return flakyJobs, nil
}
func ( fjr * FlakyJobReporter ) parseFlakyJobs ( jsonIn [ ] byte ) ( [ ] * FlakyJob , error ) { var flakeMap map [ string ] * FlakyJob err := json . Unmarshal ( jsonIn , & flakeMap ) if err != nil || flakeMap == nil { return nil , fmt . Errorf ( " " , err ) } flakyJobs := make ( [ ] * FlakyJob , 0 , len ( flakeMap ) ) for job , fj := range flakeMap { if job == " " { glog . Errorf ( " \n " ) continue } if fj == nil { glog . Errorf ( " \n " , job ) continue } if fj . Consistency == nil { glog . Errorf ( " \n " , job ) continue } if fj . FlakeCount == nil { glog . Errorf ( " \n " , job ) continue } if fj . FlakyTests == nil { glog . Errorf ( " \n " , job ) continue } fj . Name = job fj . reporter = fjr flakyJobs = append ( flakyJobs , fj ) } sort . SliceStable ( flakyJobs , func ( i , j int ) bool { if * flakyJobs [ i ] . FlakeCount == * flakyJobs [ j ] . FlakeCount { return * flakyJobs [ i ] . Consistency < * flakyJobs [ j ] . Consistency } return * flakyJobs [ i ] . FlakeCount > * flakyJobs [ j ] . FlakeCount } ) return flakyJobs , nil }
// parseFlakyJobs parses JSON generated by the 'flakes' bigquery metric into a sorted slice of
// *FlakyJob.
parseFlakyJobs parses JSON generated by the flakes bigquery metric into a sorted slice of * FlakyJob .