Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions parser/ossinsight.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ type OssInsightResponse struct {
Forks string `json:"forks"`
} `json:"rows"`
} `json:"data"`
DataQuality struct {
Status string `json:"status"`
Metric string `json:"metric"`
UnavailableSince string `json:"unavailable_since"`
Reason string `json:"reason"`
} `json:"data_quality"`
}

func GetTrendingReposFromOssInsight(maxRepos int, period, language string) ([]Repository, error) {
Expand Down Expand Up @@ -87,6 +93,19 @@ func GetTrendingReposFromOssInsight(maxRepos int, period, language string) ([]Re
return nil, fmt.Errorf("failed to decode OssInsight response: %v", err)
}

// OssInsight answers with HTTP 200 and no rows when the ranking it is asked
// for cannot be computed, so the payload has to be checked explicitly.
if q := apiRes.DataQuality; q.Status != "" && q.Status != "ok" {
return nil, fmt.Errorf("OssInsight metric %q is %s since %s: %s", q.Metric, q.Status, q.UnavailableSince, q.Reason)
}
// A narrow language filter can legitimately match nothing, the same way the
// GitHub trending page can come back empty, so only an unfiltered query that
// yields nothing is treated as a failure. This keeps the empty-payload guard
// useful even if the data_quality block ever disappears from the response.
if len(apiRes.Data.Rows) == 0 && (language == "" || language == "All") {
return nil, fmt.Errorf("OssInsight returned no trending repositories for period %q", period)
}

var allRepos []Repository
for _, row := range apiRes.Data.Rows {
if !isEnglishText(row.Description) {
Expand Down