MCPcopy Index your code
hub / github.com/rilldata/rill / CreateManagedRepo

Method CreateManagedRepo

admin/github.go:176–213  ·  view source on GitHub ↗
(ctx context.Context, name string, autoInit bool)

Source from the content-addressed store, hash-verified

174}
175
176func (g *githubClient) CreateManagedRepo(ctx context.Context, name string, autoInit bool) (*github.Repository, error) {
177 repoName := fmt.Sprintf("%s-%v", name, uuid.New().String()[0:8])
178
179 // get managed org client
180 id, err := g.ManagedOrgInstallationID()
181 if err != nil {
182 return nil, fmt.Errorf("failed to get managed org installation ID: %w", err)
183 }
184 client := g.InstallationClient(id, nil)
185
186 // create the repo
187 repo, _, err := client.Repositories.Create(ctx, g.managedAcct, &github.Repository{
188 Name: github.Ptr(repoName),
189 Private: github.Ptr(true),
190 AutoInit: github.Ptr(autoInit),
191 })
192 if err != nil {
193 return nil, fmt.Errorf("failed to create managed repo: %w", err)
194 }
195
196 // the create repo API does not wait for repo creation to be fully processed on server. Need to verify by making a get call in a loop
197 pollCtx, cancel := context.WithTimeout(ctx, 10*time.Minute)
198 defer cancel()
199 for {
200 select {
201 case <-pollCtx.Done():
202 return nil, pollCtx.Err()
203 case <-time.After(2 * time.Second):
204 // Ready to check again.
205 }
206 _, _, err := client.Repositories.Get(ctx, g.managedAcct, repoName)
207 if err == nil {
208 break
209 }
210 }
211
212 return repo, nil
213}
214
215func (g *githubClient) DeleteManagedRepo(ctx context.Context, repo string) error {
216 // get managed org client

Callers

nothing calls this directly

Calls 8

InstallationClientMethod · 0.95
CreateMethod · 0.80
DoneMethod · 0.80
StringMethod · 0.65
ErrorfMethod · 0.65
ErrMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected