getAndCheckGithubInstallationID returns a valid installation ID iff app is installed and user is a collaborator of the repo
(ctx context.Context, gitRemote, userID string)
| 1779 | |
| 1780 | // getAndCheckGithubInstallationID returns a valid installation ID iff app is installed and user is a collaborator of the repo |
| 1781 | func (s *Server) getAndCheckGithubInstallationID(ctx context.Context, gitRemote, userID string) (repoID, installationID int64, err error) { |
| 1782 | // Get Github installation ID for the repo |
| 1783 | installationID, err = s.admin.GetGithubInstallation(ctx, gitRemote) |
| 1784 | if err != nil { |
| 1785 | if errors.Is(err, admin.ErrGithubInstallationNotFound) { |
| 1786 | return 0, 0, status.Errorf(codes.PermissionDenied, "you have not granted Rill access to %q", gitRemote) |
| 1787 | } |
| 1788 | |
| 1789 | return 0, 0, fmt.Errorf("failed to get Github installation: %w", err) |
| 1790 | } |
| 1791 | |
| 1792 | if installationID == 0 { |
| 1793 | return 0, 0, status.Errorf(codes.PermissionDenied, "you have not granted Rill access to %q", gitRemote) |
| 1794 | } |
| 1795 | |
| 1796 | // Check that user is a collaborator on the repo |
| 1797 | user, err := s.admin.DB.FindUser(ctx, userID) |
| 1798 | if err != nil { |
| 1799 | return 0, 0, err |
| 1800 | } |
| 1801 | |
| 1802 | if user.GithubUsername == "" { |
| 1803 | return 0, 0, status.Errorf(codes.PermissionDenied, "you have not granted Rill access to your Github account") |
| 1804 | } |
| 1805 | |
| 1806 | repo, err := s.admin.LookupGithubRepoForUser(ctx, installationID, gitRemote, user.GithubUsername) |
| 1807 | if err != nil { |
| 1808 | if errors.Is(err, admin.ErrUserIsNotCollaborator) { |
| 1809 | return 0, 0, status.Errorf(codes.PermissionDenied, "you are not collaborator to the repo %q", gitRemote) |
| 1810 | } |
| 1811 | return 0, 0, err |
| 1812 | } |
| 1813 | |
| 1814 | return repo.GetID(), installationID, nil |
| 1815 | } |
| 1816 | |
| 1817 | // SudoUpdateTags updates the tags for a project in organization for superusers |
| 1818 | func (s *Server) SudoUpdateAnnotations(ctx context.Context, req *adminv1.SudoUpdateAnnotationsRequest) (*adminv1.SudoUpdateAnnotationsResponse, error) { |
no test coverage detected