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

Method ConnectProjectToGithub

admin/server/github.go:388–462  ·  view source on GitHub ↗
(ctx context.Context, req *adminv1.ConnectProjectToGithubRequest)

Source from the content-addressed store, hash-verified

386}
387
388func (s *Server) ConnectProjectToGithub(ctx context.Context, req *adminv1.ConnectProjectToGithubRequest) (*adminv1.ConnectProjectToGithubResponse, error) {
389 observability.AddRequestAttributes(ctx,
390 attribute.String("args.organization", req.Org),
391 attribute.String("args.project", req.Project),
392 attribute.String("args.remote", req.Remote),
393 )
394
395 // Find project
396 proj, err := s.admin.DB.FindProjectByName(ctx, req.Org, req.Project)
397 if err != nil {
398 return nil, err
399 }
400
401 // Check the request is made by an authenticated user
402 claims := auth.GetClaims(ctx)
403 if claims.OwnerType() != auth.OwnerTypeUser || !claims.ProjectPermissions(ctx, proj.OrganizationID, proj.ID).ManageProject {
404 return nil, status.Error(codes.PermissionDenied, "does not have permission to update project's github connection")
405 }
406
407 user, err := s.admin.DB.FindUser(ctx, claims.OwnerID())
408 if err != nil {
409 return nil, err
410 }
411
412 var branch string
413 if proj.PrimaryBranch != "" {
414 branch = proj.PrimaryBranch
415 } else {
416 branch = "main"
417 }
418 token, err := s.createRepo(ctx, req.Remote, branch, user)
419 if err != nil {
420 return nil, err
421 }
422
423 if proj.ArchiveAssetID != nil {
424 author := &object.Signature{
425 Name: user.GithubUsername,
426 Email: user.Email,
427 }
428 err := s.pushAssetToGit(ctx, *proj.ArchiveAssetID, req.Remote, branch, token, author)
429 if err != nil {
430 return nil, err
431 }
432 } else if proj.GitRemote != nil {
433 mgdRepoToken, _, err := s.admin.Github.InstallationToken(ctx, *proj.GithubInstallationID, *proj.GithubRepoID)
434 if err != nil {
435 return nil, err
436 }
437 err = mirrorGitRepo(ctx, *proj.GitRemote, req.Remote, mgdRepoToken, token)
438 if err != nil {
439 return nil, err
440 }
441 } else {
442 return nil, status.Error(codes.Internal, "invalid project")
443 }
444
445 org, err := s.admin.DB.FindOrganization(ctx, proj.OrganizationID)

Callers

nothing calls this directly

Calls 15

createRepoMethod · 0.95
pushAssetToGitMethod · 0.95
UpdateProjectMethod · 0.95
AddRequestAttributesFunction · 0.92
GetClaimsFunction · 0.92
mirrorGitRepoFunction · 0.85
StringMethod · 0.65
FindProjectByNameMethod · 0.65
OwnerTypeMethod · 0.65
ProjectPermissionsMethod · 0.65
FindUserMethod · 0.65
OwnerIDMethod · 0.65

Tested by

no test coverage detected