MCPcopy Index your code
hub / github.com/git-bug/git-bug / getRepositoryNodeID

Function getRepositoryNodeID

bridge/github/export.go:426–467  ·  view source on GitHub ↗

getRepositoryNodeID request github api v3 to get repository node id

(ctx context.Context, token *auth.Token, owner, project string)

Source from the content-addressed store, hash-verified

424
425// getRepositoryNodeID request github api v3 to get repository node id
426func getRepositoryNodeID(ctx context.Context, token *auth.Token, owner, project string) (string, error) {
427 url := fmt.Sprintf("%s/repos/%s/%s", githubV3Url, owner, project)
428 client := &http.Client{}
429
430 req, err := http.NewRequest("GET", url, nil)
431 if err != nil {
432 return "", err
433 }
434
435 // need the token for private repositories
436 req.Header.Set("Authorization", fmt.Sprintf("token %s", token.Value))
437
438 ctx, cancel := context.WithTimeout(ctx, defaultTimeout)
439 defer cancel()
440 req = req.WithContext(ctx)
441
442 resp, err := client.Do(req)
443 if err != nil {
444 return "", err
445 }
446
447 if resp.StatusCode != http.StatusOK {
448 return "", fmt.Errorf("HTTP error %v retrieving repository node id", resp.StatusCode)
449 }
450
451 aux := struct {
452 NodeID string `json:"node_id"`
453 }{}
454
455 data, _ := io.ReadAll(resp.Body)
456 err = resp.Body.Close()
457 if err != nil {
458 return "", err
459 }
460
461 err = json.Unmarshal(data, &aux)
462 if err != nil {
463 return "", err
464 }
465
466 return aux.NodeID, nil
467}
468
469func markOperationAsExported(b *cache.BugCache, target entity.Id, githubID, githubURL string) error {
470 _, err := b.SetMetadata(

Callers 1

ExportAllMethod · 0.85

Calls 4

SetMethod · 0.80
ErrorfMethod · 0.80
ReadAllMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected