robots/issue-creator/sources/flakyjob-reporter.go
func (fj *FlakyJob) Body(closedIssues []*githubapi.Issue) string {
	// First check that the most recently closed issue (if any exist) was closed
	// at least a week ago (since that is the sliding window size used by the flake metric).
	cutoffTime := time.Now().AddDate(0, 0, -7)
	for _, closed := range closedIssues {
		if closed.ClosedAt.After(cutoffTime) {
			return ""
		}
	}

	// Print stats about the flaky job.
	var buf bytes.Buffer
	fmt.Fprintf(&buf, "### %s\n Flakes in the past week: **%d**\n Consistency: **%.2f%%**\n",
		fj.ID(), *fj.FlakeCount, *fj.Consistency*100)
	if len(fj.FlakyTests) > 0 {
		fmt.Fprint(&buf, "\n#### Flakiest tests by flake count:\n| Test | Flake Count |\n| --- | --- |\n")
		for _, testName := range fj.TestsSorted() {
			fmt.Fprintf(&buf, "| %s | %d |\n", testName, fj.FlakyTests[testName])
		}
	}
	// List previously closed issues if there are any.
	if len(closedIssues) > 0 {
		fmt.Fprint(&buf, "\n#### Previously closed issues for this job flaking:\n")
		for _, closed := range closedIssues {
			fmt.Fprintf(&buf, "#%d ", *closed.Number)
		}
		fmt.Fprint(&buf, "\n")
	}

	// Create /assign command.
	testsSorted := fj.TestsSorted()
	ownersMap := fj.reporter.creator.TestsOwners(testsSorted)
	if len(ownersMap) > 0 {
		fmt.Fprint(&buf, "\n/assign")
		for user := range ownersMap {
			fmt.Fprintf(&buf, " @%s", user)
		}
		fmt.Fprint(&buf, "\n")
	}

	// Explain why assignees were assigned and why sig labels were applied.
	fmt.Fprintf(&buf, "\n%s", fj.reporter.creator.ExplainTestAssignments(testsSorted))

	fmt.Fprintf(&buf, "\n[Flakiest Jobs](%s)\n", fj.reporter.flakyJobDataURL)

	fmt.Fprintf(&buf, "\n/kind flake\n")

	return buf.String()
}
func (fj *FlakyJob) Body(closedIssues []*githubapi.Issue) string {
	// First check that the most recently closed issue (if any exist) was closed
	// at least a week ago (since that is the sliding window size used by the flake metric).
	cutoffTime := time.Now().AddDate(0, 0, -7)
	for _, closed := range closedIssues {
		if closed.ClosedAt.After(cutoffTime) {
			return ""
		}
	}

	// Print stats about the flaky job.
	var buf bytes.Buffer
	fmt.Fprintf(&buf, "### %s\n Flakes in the past week: **%d**\n Consistency: **%.2f%%**\n",
		fj.ID(), *fj.FlakeCount, *fj.Consistency*100)
	if len(fj.FlakyTests) > 0 {
		fmt.Fprint(&buf, "\n#### Flakiest tests by flake count:\n| Test | Flake Count |\n| --- | --- |\n")
		for _, testName := range fj.TestsSorted() {
			fmt.Fprintf(&buf, "| %s | %d |\n", testName, fj.FlakyTests[testName])
		}
	}
	// List previously closed issues if there are any.
	if len(closedIssues) > 0 {
		fmt.Fprint(&buf, "\n#### Previously closed issues for this job flaking:\n")
		for _, closed := range closedIssues {
			fmt.Fprintf(&buf, "#%d ", *closed.Number)
		}
		fmt.Fprint(&buf, "\n")
	}

	// Create /assign command.
	testsSorted := fj.TestsSorted()
	ownersMap := fj.reporter.creator.TestsOwners(testsSorted)
	if len(ownersMap) > 0 {
		fmt.Fprint(&buf, "\n/assign")
		for user := range ownersMap {
			fmt.Fprintf(&buf, " @%s", user)
		}
		fmt.Fprint(&buf, "\n")
	}

	// Explain why assignees were assigned and why sig labels were applied.
	fmt.Fprintf(&buf, "\n%s", fj.reporter.creator.ExplainTestAssignments(testsSorted))

	fmt.Fprintf(&buf, "\n[Flakiest Jobs](%s)\n", fj.reporter.flakyJobDataURL)

	fmt.Fprintf(&buf, "\n/kind flake\n")

	return buf.String()
}
// Body returns the body text of the github issue and *must* contain the output of ID().
// closedIssues is a (potentially empty) slice containing all closed issues authored by this bot
// that contain ID() in their body.
// If Body returns an empty string no issue is created.