(ctx context.Context, req *adminv1.CreateManagedGitRepoRequest)
| 462 | } |
| 463 | |
| 464 | func (s *Server) CreateManagedGitRepo(ctx context.Context, req *adminv1.CreateManagedGitRepoRequest) (*adminv1.CreateManagedGitRepoResponse, error) { |
| 465 | observability.AddRequestAttributes(ctx, |
| 466 | attribute.String("args.organization", req.Org), |
| 467 | attribute.String("args.name", req.Name), |
| 468 | attribute.Bool("args.auto_init", req.AutoInit), |
| 469 | ) |
| 470 | |
| 471 | // Find org |
| 472 | org, err := s.admin.DB.FindOrganizationByName(ctx, req.Org) |
| 473 | if err != nil { |
| 474 | return nil, err |
| 475 | } |
| 476 | |
| 477 | claims := auth.GetClaims(ctx) |
| 478 | if !claims.OrganizationPermissions(ctx, org.ID).CreateProjects { |
| 479 | return nil, status.Error(codes.PermissionDenied, "does not have permission to create projects") |
| 480 | } |
| 481 | |
| 482 | repo, err := s.admin.CreateManagedGitRepo(ctx, org, req.Name, claims.OwnerID(), req.AutoInit) |
| 483 | if err != nil { |
| 484 | return nil, err |
| 485 | } |
| 486 | |
| 487 | id, err := s.admin.Github.ManagedOrgInstallationID() |
| 488 | if err != nil { |
| 489 | return nil, err |
| 490 | } |
| 491 | token, expiresAt, err := s.admin.Github.InstallationToken(ctx, id, *repo.ID) |
| 492 | if err != nil { |
| 493 | return nil, err |
| 494 | } |
| 495 | |
| 496 | return &adminv1.CreateManagedGitRepoResponse{ |
| 497 | Remote: *repo.CloneURL, |
| 498 | Username: "x-access-token", |
| 499 | Password: token, |
| 500 | DefaultBranch: valOrDefault(repo.DefaultBranch, "main"), |
| 501 | PasswordExpiresAt: timestamppb.New(expiresAt), |
| 502 | }, nil |
| 503 | } |
| 504 | |
| 505 | // registerGithubEndpoints registers the non-gRPC endpoints for the Github integration. |
| 506 | func (s *Server) registerGithubEndpoints(mux *http.ServeMux) { |
nothing calls this directly
no test coverage detected