in dev/testsreporter/reporter.go [96:153]
func (r reporter) updateLinks(ctx context.Context, issue *githubIssue, currentBuild string) (*errorLinks, *githubIssue, error) {
nextIssue := issue
links := errorLinks{
currentIssueURL: "",
firstBuild: currentBuild,
previousBuilds: []string{},
closedIssueURL: "",
}
// Look for an existing issue
found, prevIssue, err := r.ghCli.Exists(ctx, issue, true)
if err != nil {
return nil, nil, fmt.Errorf("failed to check if issue already exists: %w", err)
}
if found {
nextIssue = prevIssue
fmt.Printf("Found existing open issue: %s\n", prevIssue.URL())
links.currentIssueURL = prevIssue.URL()
// Retrieve information from the Issue description (first build, closed issue, previous links)
firstBuild, err := firstBuildLinkFromDescription(prevIssue)
if err != nil {
return nil, nil, fmt.Errorf("failed to read first link from issue (title: %s): %w", issue.title, err)
}
fmt.Printf("First build found: %s\n", firstBuild)
links.firstBuild = firstBuild
closedIssueURL, err := closedIssueFromDescription(prevIssue)
if err != nil {
return nil, nil, fmt.Errorf("failed to read closed issue from issue (title: %s): %w", issue.title, err)
}
links.closedIssueURL = closedIssueURL
if firstBuild == currentBuild {
fmt.Println("First time failing, no need to update previous build links.")
} else {
previousLinks, err := previousBuildLinksFromDescription(prevIssue)
if err != nil {
return nil, nil, fmt.Errorf("failed to read previous links from issue (title: %s): %w", issue.title, err)
}
previousLinks = updatePreviousLinks(previousLinks, currentBuild, r.maxPreviousLinks)
links.previousBuilds = previousLinks
}
} else {
fmt.Println("No open issue found for this error.")
// is there any closed issue
closedIssueURL, err := r.closedIssueURL(ctx, issue)
if err != nil {
return nil, nil, fmt.Errorf("failed to check if there is a closed issue: %w", err)
}
links.closedIssueURL = closedIssueURL
}
return &links, nextIssue, nil
}