(ctx context.Context, org *database.Organization, name, ownerID string, autoInit bool)
| 248 | } |
| 249 | |
| 250 | func (s *Service) CreateManagedGitRepo(ctx context.Context, org *database.Organization, name, ownerID string, autoInit bool) (*github.Repository, error) { |
| 251 | if org.QuotaProjects >= 0 { |
| 252 | count, err := s.DB.CountManagedGitRepos(ctx, org.ID) |
| 253 | if err != nil { |
| 254 | return nil, fmt.Errorf("failed to count managed repos: %w", err) |
| 255 | } |
| 256 | |
| 257 | quota := quotaManagedRepos(org) |
| 258 | if count >= quota { |
| 259 | return nil, fmt.Errorf("managed repo quota exceeded: %d/%d", count, quota) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | repo, err := s.Github.CreateManagedRepo(ctx, fmt.Sprintf("%s-%s", org.Name, name), autoInit) |
| 264 | if err != nil { |
| 265 | return nil, fmt.Errorf("failed to create managed repo: %w", err) |
| 266 | } |
| 267 | _, err = s.DB.InsertManagedGitRepo(ctx, &database.InsertManagedGitRepoOptions{ |
| 268 | OrgID: org.ID, |
| 269 | Remote: repo.GetCloneURL(), |
| 270 | OwnerID: ownerID, |
| 271 | }) |
| 272 | if err != nil { |
| 273 | return nil, fmt.Errorf("failed to insert managed repo meta: %w", err) |
| 274 | } |
| 275 | |
| 276 | return repo, nil |
| 277 | } |
| 278 | |
| 279 | // GetGithubInstallation returns a non zero Github installation ID if the Github App is installed on the repository and is not in suspended state. |
| 280 | // The remote should be a HTTPS URL for a github.com repository with the .git suffix. |
nothing calls this directly
no test coverage detected