in dev/testsreporter/github.go [63:128]
func (g *ghCli) Exists(ctx context.Context, issue *githubIssue, open bool) (bool, *githubIssue, error) {
stateIssue := "open"
if !open {
stateIssue = "closed"
}
stdout, stderr, err := g.runner.Exec(ctx,
"issue",
"list",
"--json",
"title,body,number,labels,state,url,createdAt,closedAt",
"--repo",
issue.repository,
"--search",
fmt.Sprintf("%s in:title sort:created-desc", issue.title),
"--limit",
"1000",
"--jq",
"map(select((.labels | length) > 0))| map(.labels = (.labels | map(.name)))",
"--state",
stateIssue,
)
if err != nil {
return false, nil, fmt.Errorf("failed to list issues: %w\n%s", err, stderr.String())
}
type responseListIssue struct {
CreatedAt time.Time `json:"createdAt"`
ClosedAt time.Time `json:"closedAt"`
Title string `json:"title"`
Body string `json:"body"`
Number int `json:"number"`
Labels []string `json:"labels"`
State string `json:"state"`
URL string `json:"url"`
}
var list []responseListIssue
err = json.Unmarshal(stdout.Bytes(), &list)
if err != nil {
return false, nil, fmt.Errorf("failed to unmarshal list of issues: %w", err)
}
if !open {
// There is no query available to sort by closing time of issues
sort.Slice(list, func(i, j int) bool {
return list[i].ClosedAt.After(list[j].ClosedAt)
})
}
for _, i := range list {
if i.Title == issue.title {
issueGot := newGithubIssue(githubIssueOptions{
Number: i.Number,
Title: i.Title,
Description: i.Body,
Labels: i.Labels,
State: i.State,
Repository: issue.repository,
URL: i.URL,
})
return true, issueGot, nil
}
}
return false, nil, nil
}