Beispiel #1
0
func fetch(query string, full bool) ([]*issue.Issue, error) {
	can := "open"
	if full {
		can = "all"
	}
	return issue.Search(*project, can, query, full, client)
}
Beispiel #2
0
func Update(ctxt *fs.Context, client *http.Client, version string) error {
	prefix := strings.Map(func(r rune) rune {
		if 'A' <= r && r <= 'Z' {
			return r - 'A' + 'a'
		}
		if 'a' <= r && r <= 'z' || '0' <= r && r <= '9' {
			return r
		}
		return -1
	}, version)

	label := strings.Map(func(r rune) rune {
		if r == ' ' {
			return -1
		}
		return r
	}, version)

	graphFile := "/issue-dashboard/" + prefix + ".graph"
	htmlFile := "/issue-dashboard/" + label

	var graph []Point
	data, _, err := ctxt.Read(graphFile)
	if err == nil {
		if err := json.Unmarshal(data, &graph); err != nil {
			return fmt.Errorf("unmarshal dashboard graph: %v", err)
		}
	}

	yes, err := issue.Search("go", "open", "label:"+label, false, client)
	if err != nil {
		return fmt.Errorf("searching for %s issues: %v", version, err)
	}
	maybe, err := issue.Search("go", "open", "label:"+label+"Maybe", false, client)
	if err != nil {
		return fmt.Errorf("searching for %sMaybe issues: %v", label, err)
	}

	graph = append(graph, Point{time.Now(), len(yes), len(maybe)})
	data, err = json.Marshal(graph)
	if err != nil {
		return fmt.Errorf("marshal dashboard graph: %v", err)
	}
	if err := ctxt.Write(graphFile, data); err != nil {
		return fmt.Errorf("writing dashboard graph: %v", err)
	}

	byDir := map[string][]*issue.Issue{}
	for _, p := range append(yes, maybe...) {
		dir := p.Summary
		if i := strings.Index(dir, ":"); i >= 0 {
			dir = dir[:i]
		}
		if i := strings.Index(dir, ","); i >= 0 {
			dir = dir[:i]
		}
		byDir[dir] = append(byDir[dir], p)
	}

	var small []Point
	now := time.Now()
	day := -1
	for _, p := range graph {
		if p.Maybe == 0 {
			continue
		}
		d := p.Time.Day()
		if d != day || now.Sub(p.Time) < 3*24*time.Hour {
			day = d
			small = append(small, p)
		}
	}

	tmplData := struct {
		Version string
		Label   string
		Graph   []Point
		Issues  map[string][]*issue.Issue
	}{
		Version: version,
		Label:   label,
		Graph:   small,
		Issues:  byDir,
	}

	var buf bytes.Buffer
	tmpl, err := template.New("main").
		Funcs(template.FuncMap{
			"hasLabel":  hasLabel,
			"hasStatus": hasStatus,
		}).
		Parse(dashTemplate)
	if err != nil {
		return fmt.Errorf("parsing template: %v", err)
	}
	if err := tmpl.Execute(&buf, &tmplData); err != nil {
		return fmt.Errorf("executing template: %v", err)
	}
	if err := ctxt.Write(htmlFile, buf.Bytes()); err != nil {
		return fmt.Errorf("writing html: %v", err)
	}
	return nil
}