create repository need a token with scope 'repo'
(project, token string)
| 300 | |
| 301 | // create repository need a token with scope 'repo' |
| 302 | func createRepository(project, token string) error { |
| 303 | // This function use the V3 Github API because repository creation is not supported yet on the V4 API. |
| 304 | url := fmt.Sprintf("%s/user/repos", githubV3Url) |
| 305 | |
| 306 | params := struct { |
| 307 | Name string `json:"name"` |
| 308 | Description string `json:"description"` |
| 309 | Private bool `json:"private"` |
| 310 | HasIssues bool `json:"has_issues"` |
| 311 | }{ |
| 312 | Name: project, |
| 313 | Description: "git-bug exporter temporary test repository", |
| 314 | Private: true, |
| 315 | HasIssues: true, |
| 316 | } |
| 317 | |
| 318 | data, err := json.Marshal(params) |
| 319 | if err != nil { |
| 320 | return err |
| 321 | } |
| 322 | |
| 323 | req, err := http.NewRequest("POST", url, bytes.NewBuffer(data)) |
| 324 | if err != nil { |
| 325 | return err |
| 326 | } |
| 327 | |
| 328 | // need the token for private repositories |
| 329 | req.Header.Set("Authorization", fmt.Sprintf("token %s", token)) |
| 330 | |
| 331 | client := &http.Client{ |
| 332 | Timeout: defaultTimeout, |
| 333 | } |
| 334 | |
| 335 | resp, err := client.Do(req) |
| 336 | if err != nil { |
| 337 | return err |
| 338 | } |
| 339 | |
| 340 | return resp.Body.Close() |
| 341 | } |
| 342 | |
| 343 | // delete repository need a token with scope 'delete_repo' |
| 344 | func deleteRepository(project, owner, token string) error { |
no test coverage detected