34 lines
667 B
Go
34 lines
667 B
Go
package github
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
var IssuesURL string
|
|
|
|
type IssuesSearchResult struct{}
|
|
|
|
// SearchIssues queries the GitHub issue tracker.
|
|
func SearchIssues(terms []string) (*IssuesSearchResult, error) {
|
|
q := url.QueryEscape(strings.Join(terms, " "))
|
|
resp, err := http.Get(IssuesURL + "?q=" + q)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
return nil, fmt.Errorf("search query failed: %s", resp.Status)
|
|
}
|
|
|
|
var result IssuesSearchResult
|
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &result, nil
|
|
}
|