GetGithubInstallation returns a non zero Github installation ID if the Github App is installed on the repository and is not in suspended state. The remote should be a HTTPS URL for a github.com repository with the .git suffix.
(ctx context.Context, remote string)
| 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. |
| 281 | func (s *Service) GetGithubInstallation(ctx context.Context, remote string) (int64, error) { |
| 282 | account, repo, ok := gitutil.SplitGithubRemote(remote) |
| 283 | if !ok { |
| 284 | return 0, fmt.Errorf("invalid Github remote %q", remote) |
| 285 | } |
| 286 | |
| 287 | installation, resp, err := s.Github.AppClient().Apps.FindRepositoryInstallation(ctx, account, repo) |
| 288 | if err != nil { |
| 289 | if resp.StatusCode == http.StatusNotFound { |
| 290 | // We don't have an installation on the repo |
| 291 | return 0, ErrGithubInstallationNotFound |
| 292 | } |
| 293 | return 0, fmt.Errorf("failed to lookup repo info: %w", err) |
| 294 | } |
| 295 | |
| 296 | if installation.SuspendedAt != nil { |
| 297 | return 0, ErrGithubInstallationNotFound |
| 298 | } |
| 299 | |
| 300 | installationID := installation.GetID() |
| 301 | if installationID == 0 { |
| 302 | // Do we have to check for this? |
| 303 | return 0, fmt.Errorf("received invalid installation from Github") |
| 304 | } |
| 305 | |
| 306 | // The user has access to the installation |
| 307 | return installationID, nil |
| 308 | } |
| 309 | |
| 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. |
no test coverage detected