33 lines
645 B
Go
33 lines
645 B
Go
|
package github
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
"net/url"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
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
|
||
|
}
|