Skip to content

Commit

Permalink
Merge pull request #213 from bhavya181/github-app
Browse files Browse the repository at this point in the history
[PL-26239]: added api to list installation for github app
  • Loading branch information
bradrydzewski authored Aug 7, 2022
2 parents b9de5f5 + 6024f33 commit 48f05b7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scm/driver/github/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ func (s *RepositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*
return convertRepositoryList(out), res, err
}

// List returns the githubapp installation list.
func (s *RepositoryService) ListAppInstallations(ctx context.Context, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
path := fmt.Sprintf("installation/repositories?%s", encodeListOptions(opts))
out := []*repository{}
res, err := s.client.do(ctx, "GET", path, nil, &out)
return convertRepositoryList(out), res, err
}

// ListHooks returns a list or repository hooks.
func (s *RepositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
path := fmt.Sprintf("repos/%s/hooks?%s", repo, encodeListOptions(opts))
Expand Down
34 changes: 34 additions & 0 deletions scm/driver/github/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,40 @@ func TestRepositoryList(t *testing.T) {
t.Run("Page", testPage(res))
}

func TestGithubAppInstallationList(t *testing.T) {
defer gock.Off()

gock.New("https://api.github.com").
Get("/installation/repositories").
MatchParam("page", "1").
MatchParam("per_page", "30").
Reply(200).
Type("application/json").
SetHeaders(mockHeaders).
SetHeaders(mockPageHeaders).
File("testdata/repos.json")

client := NewDefault()
got, res, err := client.Repositories.(*RepositoryService).ListAppInstallations(context.Background(), scm.ListOptions{Page: 1, Size: 30})
if err != nil {
t.Error(err)
return
}

want := []*scm.Repository{}
raw, _ := ioutil.ReadFile("testdata/repos.json.golden")
_ = json.Unmarshal(raw, &want)

if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Unexpected Results")
t.Log(diff)
}

t.Run("Request", testRequest(res))
t.Run("Rate", testRate(res))
t.Run("Page", testPage(res))
}

func TestStatusList(t *testing.T) {
defer gock.Off()

Expand Down

0 comments on commit 48f05b7

Please sign in to comment.