Esempio n. 1
0
func gatherData(cfg *githubhelper.Config) (*reportData, error) {
	issues, err := cfg.ListAllIssues(&github.IssueListByRepoOptions{
		State:  "open",
		Sort:   "created",
		Labels: []string{"kind/flake"},
	})
	if err != nil {
		return nil, err
	}

	r := reportData{
		loginToEmail:  map[string]string{},
		loginToIssues: map[string][]issueReportData{},
	}
	for _, issue := range issues {
		assignee := "UNASSIGNED"
		if issue.Assignee != nil && issue.Assignee.Login != nil {
			assignee = *issue.Assignee.Login
			if _, ok := r.loginToEmail[assignee]; !ok {
				if u, err := cfg.GetUser(assignee); err == nil {
					if u.Email != nil {
						r.loginToEmail[assignee] = *u.Email
					} else {
						// Don't keep looking this up
						r.loginToEmail[assignee] = ""
					}
				}
			}
		}
		age := time.Duration(0)
		if issue.CreatedAt != nil {
			age = time.Now().Sub(*issue.CreatedAt)
		}
		priority := "??"
		priorityLabels := githubhelper.GetLabelsWithPrefix(issue.Labels, "priority/")
		if len(priorityLabels) == 1 {
			priority = strings.TrimPrefix(priorityLabels[0], "priority/")
		}
		if priority == "P2" || priority == "P3" {
			r.lowPriorityTests++
			continue
		}
		reportData := issueReportData{
			priority: priority,
			number:   *issue.Number,
			title:    *issue.Title,
			age:      age,
		}
		r.loginToIssues[assignee] = append(r.loginToIssues[assignee], reportData)
		if priority == "??" {
			const unprioritized = "UNPRIORITIZED"
			r.loginToIssues[unprioritized] = append(r.loginToIssues[unprioritized], reportData)
		}
		r.totalTests++
	}
	return &r, nil
}