Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PL-26239]: added api to list installation for github app #213

Merged
merged 1 commit into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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