(httpClient httpClient, hostname, authToken string)
| 251 | } |
| 252 | |
| 253 | func GetCurrentLogin(httpClient httpClient, hostname, authToken string) (string, error) { |
| 254 | query := `query UserCurrent{viewer{login}}` |
| 255 | reqBody, err := json.Marshal(map[string]interface{}{"query": query}) |
| 256 | if err != nil { |
| 257 | return "", err |
| 258 | } |
| 259 | result := struct { |
| 260 | Data struct{ Viewer struct{ Login string } } |
| 261 | }{} |
| 262 | apiEndpoint, err := safeurl.JoinPathWithHostPrefix(ghinstance.GraphQLEndpoint(hostname)) |
| 263 | if err != nil { |
| 264 | return "", err |
| 265 | } |
| 266 | req, err := http.NewRequest("POST", apiEndpoint.String(), bytes.NewBuffer(reqBody)) |
| 267 | if err != nil { |
| 268 | return "", err |
| 269 | } |
| 270 | req.Header.Set("Authorization", "token "+authToken) |
| 271 | res, err := httpClient.Do(req) |
| 272 | if err != nil { |
| 273 | return "", err |
| 274 | } |
| 275 | defer res.Body.Close() |
| 276 | if res.StatusCode > 299 { |
| 277 | return "", api.HandleHTTPError(res) |
| 278 | } |
| 279 | decoder := json.NewDecoder(res.Body) |
| 280 | err = decoder.Decode(&result) |
| 281 | if err != nil { |
| 282 | return "", err |
| 283 | } |
| 284 | return result.Data.Viewer.Login, nil |
| 285 | } |
no test coverage detected