MCPcopy
hub / github.com/ossf/scorecard / ListOrgRepos

Function ListOrgRepos

cmd/internal/org/org.go:36–82  ·  view source on GitHub ↗

ListOrgRepos lists all non-archived repositories for a GitHub organization. The caller should provide an http.RoundTripper (rt). If rt is nil, the default transport will be created via roundtripper.NewTransport.

(ctx context.Context, orgName string, rt http.RoundTripper)

Source from the content-addressed store, hash-verified

34// The caller should provide an http.RoundTripper (rt). If rt is nil, the
35// default transport will be created via roundtripper.NewTransport.
36func ListOrgRepos(ctx context.Context, orgName string, rt http.RoundTripper) ([]string, error) {
37 // Parse org name if needed.
38 if len(orgName) > 0 {
39 if parsed := parseOrgName(orgName); parsed != "" {
40 orgName = parsed
41 }
42 }
43
44 // Use the centralized transport so we respect token rotation, GitHub App
45 // auth, rate limiting and instrumentation already implemented in
46 // clients/githubrepo/roundtripper.
47 logger := log.NewLogger(log.DefaultLevel)
48 if rt == nil {
49 rt = roundtripper.NewTransport(ctx, logger)
50 }
51 httpClient := &http.Client{Transport: rt}
52 client := github.NewClient(httpClient)
53
54 opt := &github.RepositoryListByOrgOptions{
55 Type: "all",
56 }
57
58 var urls []string
59 for {
60 repos, resp, err := client.Repositories.ListByOrg(ctx, orgName, opt)
61 if err != nil {
62 return nil, fmt.Errorf("failed to list repos: %w", err)
63 }
64
65 for _, r := range repos {
66 if r.GetArchived() {
67 continue
68 }
69 urls = append(urls, r.GetHTMLURL())
70 }
71
72 if resp == nil {
73 return nil, ErrNilResponse
74 }
75 if resp.NextPage == 0 {
76 break
77 }
78 opt.Page = resp.NextPage
79 }
80
81 return urls, nil
82}
83
84// parseOrgName extracts the GitHub organization from a supported input.
85// Supported:

Calls 3

NewLoggerFunction · 0.92
NewTransportFunction · 0.92
parseOrgNameFunction · 0.85

Tested by 1