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

Method LookupGithubRepoForUser

admin/github.go:312–342  ·  view source on GitHub ↗

LookupGithubRepoForUser returns a Github repository iff the Github App is installed on the repository and user is a collaborator of the project. The remote should be a HTTPS URL for a github.com repository with the .git suffix.

(ctx context.Context, installationID int64, remote, gitUsername string)

Source from the content-addressed store, hash-verified

310// LookupGithubRepoForUser returns a Github repository iff the Github App is installed on the repository and user is a collaborator of the project.
311// The remote should be a HTTPS URL for a github.com repository with the .git suffix.
312func (s *Service) LookupGithubRepoForUser(ctx context.Context, installationID int64, remote, gitUsername string) (*github.Repository, error) {
313 account, repo, ok := gitutil.SplitGithubRemote(remote)
314 if !ok {
315 return nil, fmt.Errorf("invalid Github remote %q", remote)
316 }
317
318 if gitUsername == "" {
319 return nil, fmt.Errorf("invalid gitUsername %q", gitUsername)
320 }
321
322 gh := s.Github.InstallationClient(installationID, nil)
323
324 isColab, resp, err := gh.Repositories.IsCollaborator(ctx, account, repo, gitUsername)
325 if err != nil {
326 if resp.StatusCode == http.StatusUnauthorized {
327 return nil, ErrUserIsNotCollaborator
328 }
329 return nil, status.Error(codes.Internal, err.Error())
330 }
331
332 if !isColab {
333 return nil, ErrUserIsNotCollaborator
334 }
335
336 repository, _, err := gh.Repositories.Get(ctx, account, repo)
337 if err != nil {
338 return nil, fmt.Errorf("failed to get github repository: %w", err)
339 }
340
341 return repository, nil
342}
343
344// ProcessGithubEvent processes a Github event (usually received over webhooks).
345// After validating that the event is a valid Github event, it moves further processing to the background and returns a nil error.

Callers 2

GetGithubRepoStatusMethod · 0.80

Calls 5

SplitGithubRemoteFunction · 0.92
ErrorfMethod · 0.65
InstallationClientMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected