get fetches a urlStr (a GitHub URL relative to the client's baseURL), and returns the parsed response document.
(urlStr string, a ...any)
| 93 | // get fetches a urlStr (a GitHub URL relative to the client's baseURL), and |
| 94 | // returns the parsed response document. |
| 95 | func (c *Client) get(urlStr string, a ...any) (*goquery.Document, error) { |
| 96 | u, err := c.baseURL.Parse(fmt.Sprintf(urlStr, a...)) |
| 97 | if err != nil { |
| 98 | return nil, fmt.Errorf("error parsing URL: %q: %v", urlStr, err) |
| 99 | } |
| 100 | |
| 101 | resp, err := c.Client.Get(u.String()) |
| 102 | if err != nil { |
| 103 | return nil, fmt.Errorf("error fetching url %q: %v", u, err) |
| 104 | } |
| 105 | defer resp.Body.Close() |
| 106 | |
| 107 | if resp.StatusCode == http.StatusNotFound { |
| 108 | return nil, fmt.Errorf("received %v response fetching URL %q", resp.StatusCode, u) |
| 109 | } |
| 110 | |
| 111 | doc, err := goquery.NewDocumentFromReader(resp.Body) |
| 112 | if err != nil { |
| 113 | return nil, fmt.Errorf("error parsing response: %v", err) |
| 114 | } |
| 115 | |
| 116 | return doc, nil |
| 117 | } |
| 118 | |
| 119 | // Authenticate client to GitHub with the provided username, password, and if |
| 120 | // two-factor auth is enabled for the account, otpseed. |
no test coverage detected