@@ -41,7 +41,8 @@ func (c *OrgRepositoriesClient) Get(ctx context.Context, ref gitprovider.OrgRepo
4141 if err := validateOrgRepositoryRef (ref , c .domain ); err != nil {
4242 return nil , err
4343 }
44- apiObj , err := getRepository (ctx , c .c , ref )
44+ // GET /repos/{owner}/{repo}
45+ apiObj , err := c .c .GetRepo (ctx , ref .GetIdentity (), ref .GetRepository ())
4546 if err != nil {
4647 return nil , err
4748 }
@@ -57,27 +58,16 @@ func (c *OrgRepositoriesClient) List(ctx context.Context, ref gitprovider.Organi
5758 return nil , err
5859 }
5960
60- // Get all of the repositories in the organization using pagination.
61- var apiObjs []* github.Repository
62- opts := & github.RepositoryListByOrgOptions {}
63- err := allPages (& opts .ListOptions , func () (* github.Response , error ) {
64- // GET /orgs/{org}/repos
65- pageObjs , resp , listErr := c .c .Repositories .ListByOrg (ctx , ref .Organization , opts )
66- apiObjs = append (apiObjs , pageObjs ... )
67- return resp , listErr
68- })
61+ // GET /orgs/{org}/repos
62+ apiObjs , err := c .c .ListOrgRepos (ctx , ref .Organization )
6963 if err != nil {
7064 return nil , err
7165 }
7266
7367 // Traverse the list, and return a list of OrgRepository objects
7468 repos := make ([]gitprovider.OrgRepository , 0 , len (apiObjs ))
7569 for _ , apiObj := range apiObjs {
76- // Make sure apiObj is valid
77- if err := validateRepositoryAPI (apiObj ); err != nil {
78- return nil , err
79- }
80-
70+ // apiObj is already validated at ListOrgRepos
8171 repos = append (repos , newOrgRepository (c .clientContext , apiObj , gitprovider.OrgRepositoryRef {
8272 OrganizationRef : ref ,
8373 RepositoryName : * apiObj .Name ,
@@ -130,13 +120,7 @@ func (c *OrgRepositoriesClient) Reconcile(ctx context.Context, ref gitprovider.O
130120 return actual , actionTaken , err
131121}
132122
133- func getRepository (ctx context.Context , c * github.Client , ref gitprovider.RepositoryRef ) (* github.Repository , error ) {
134- // GET /repos/{owner}/{repo}
135- apiObj , _ , err := c .Repositories .Get (ctx , ref .GetIdentity (), ref .GetRepository ())
136- return validateRepositoryAPIResp (apiObj , err )
137- }
138-
139- func createRepository (ctx context.Context , c * github.Client , ref gitprovider.RepositoryRef , orgName string , req gitprovider.RepositoryInfo , opts ... gitprovider.RepositoryCreateOption ) (* github.Repository , error ) {
123+ func createRepository (ctx context.Context , c githubClient , ref gitprovider.RepositoryRef , orgName string , req gitprovider.RepositoryInfo , opts ... gitprovider.RepositoryCreateOption ) (* github.Repository , error ) {
140124 // First thing, validate and default the request to ensure a valid and fully-populated object
141125 // (to minimize any possible diffs between desired and actual state)
142126 if err := gitprovider .ValidateAndDefaultInfo (& req ); err != nil {
@@ -153,15 +137,7 @@ func createRepository(ctx context.Context, c *github.Client, ref gitprovider.Rep
153137 data := repositoryToAPI (& req , ref )
154138 applyRepoCreateOptions (& data , o )
155139
156- return createRepositoryData (ctx , c , orgName , & data )
157- }
158-
159- func createRepositoryData (ctx context.Context , c * github.Client , orgName string , data * github.Repository ) (* github.Repository , error ) {
160- // POST /user/repos or
161- // POST /orgs/{org}/repos
162- // depending on orgName
163- apiObj , _ , err := c .Repositories .Create (ctx , orgName , data )
164- return validateRepositoryAPIResp (apiObj , err )
140+ return c .CreateRepo (ctx , orgName , & data )
165141}
166142
167143func reconcileRepository (ctx context.Context , actual gitprovider.UserRepository , req gitprovider.RepositoryInfo ) (bool , error ) {
0 commit comments