Skip to content

Commit

Permalink
Add GetByRepository for InstallationsService (palantir#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetersen authored Oct 26, 2020
1 parent 95e3422 commit 002ed1f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions githubapp/installations.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ type InstallationsService interface {
// It returns an InstallationNotFound error if no installation exists for
// the owner.
GetByOwner(ctx context.Context, owner string) (Installation, error)

// GetByRepository returns the installation for a repository.
// It returns an InstallationNotFound error if no installation exists for
// the repository.
GetByRepository(ctx context.Context, owner string, repo string) (Installation, error)
}

type defaultInstallationsService struct {
Expand Down Expand Up @@ -123,6 +128,19 @@ func (i defaultInstallationsService) GetByOwner(ctx context.Context, owner strin
return Installation{}, errors.Wrapf(err, "failed to get installation for owner %q", owner)
}

func (i defaultInstallationsService) GetByRepository(ctx context.Context, owner, repo string) (Installation, error) {
installation, _, err := i.Apps.FindRepositoryInstallation(ctx, owner, repo)
if err == nil {
return toInstallation(installation), nil
}

ownerRepo := fmt.Sprintf("%s/%s", owner, repo)
if isNotFound(err) {
return Installation{}, InstallationNotFound(ownerRepo)
}
return Installation{}, errors.Wrapf(err, "failed to get installation for repository %q", ownerRepo)
}

// InstallationNotFound is returned when no installation exists for a
// specific owner or repository.
type InstallationNotFound string
Expand Down

0 comments on commit 002ed1f

Please sign in to comment.