From fc5831766ea9f8dbd53ce56773acbe1cf2a0e345 Mon Sep 17 00:00:00 2001 From: candiduslynx Date: Sun, 2 Apr 2023 09:10:30 +0300 Subject: [PATCH] Add `repository_id` to `github_issues` primary key --- .../source/github/client/mocks/mock_issues.go | 16 ++++++++++++++++ plugins/source/github/client/services.go | 1 + .../github/resources/services/issues/issues.go | 9 ++++----- .../resources/services/issues/issues_test.go | 2 +- website/tables/github/github_issues.md | 3 ++- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/plugins/source/github/client/mocks/mock_issues.go b/plugins/source/github/client/mocks/mock_issues.go index 5276195263453f..cf310e87d93e45 100644 --- a/plugins/source/github/client/mocks/mock_issues.go +++ b/plugins/source/github/client/mocks/mock_issues.go @@ -50,3 +50,19 @@ func (mr *MockIssuesServiceMockRecorder) ListByOrg(arg0, arg1, arg2 interface{}) mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListByOrg", reflect.TypeOf((*MockIssuesService)(nil).ListByOrg), arg0, arg1, arg2) } + +// ListByRepo mocks base method. +func (m *MockIssuesService) ListByRepo(arg0 context.Context, arg1, arg2 string, arg3 *github.IssueListByRepoOptions) ([]*github.Issue, *github.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListByRepo", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].([]*github.Issue) + ret1, _ := ret[1].(*github.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// ListByRepo indicates an expected call of ListByRepo. +func (mr *MockIssuesServiceMockRecorder) ListByRepo(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListByRepo", reflect.TypeOf((*MockIssuesService)(nil).ListByRepo), arg0, arg1, arg2, arg3) +} diff --git a/plugins/source/github/client/services.go b/plugins/source/github/client/services.go index ad2a91273e4b96..7dc03b3239f77b 100644 --- a/plugins/source/github/client/services.go +++ b/plugins/source/github/client/services.go @@ -59,6 +59,7 @@ type OrganizationsService interface { //go:generate mockgen -package=mocks -destination=./mocks/mock_issues.go . IssuesService type IssuesService interface { ListByOrg(ctx context.Context, org string, opts *github.IssueListOptions) ([]*github.Issue, *github.Response, error) + ListByRepo(ctx context.Context, owner string, repo string, opts *github.IssueListByRepoOptions) ([]*github.Issue, *github.Response, error) } //go:generate mockgen -package=mocks -destination=./mocks/mock_actions.go . ActionsService diff --git a/plugins/source/github/resources/services/issues/issues.go b/plugins/source/github/resources/services/issues/issues.go index b7afa59587ccbc..44a5bb30beaac2 100644 --- a/plugins/source/github/resources/services/issues/issues.go +++ b/plugins/source/github/resources/services/issues/issues.go @@ -13,21 +13,20 @@ func Issues() *schema.Table { return &schema.Table{ Name: "github_issues", Resolver: fetchIssues, - Multiplex: client.OrgMultiplex, + Multiplex: client.OrgRepositoryMultiplex, Transform: client.TransformWithStruct(&github.Issue{}, transformers.WithPrimaryKeys("ID")), - Columns: []schema.Column{client.OrgColumn}, + Columns: []schema.Column{client.OrgColumn, client.RepositoryIDColumn}, } } func fetchIssues(ctx context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan<- any) error { c := meta.(*client.Client) - opts := &github.IssueListOptions{ - Filter: "all", + opts := &github.IssueListByRepoOptions{ State: "all", ListOptions: github.ListOptions{PerPage: 100}, } for { - issues, resp, err := c.Github.Issues.ListByOrg(ctx, c.Org, opts) + issues, resp, err := c.Github.Issues.ListByRepo(ctx, c.Org, *c.Repository.Name, opts) if err != nil { return err } diff --git a/plugins/source/github/resources/services/issues/issues_test.go b/plugins/source/github/resources/services/issues/issues_test.go index 9eadb5aeedd247..6d2367dd707310 100644 --- a/plugins/source/github/resources/services/issues/issues_test.go +++ b/plugins/source/github/resources/services/issues/issues_test.go @@ -20,7 +20,7 @@ func buildIssues(t *testing.T, ctrl *gomock.Controller) client.GithubServices { someId := int64(5555555) cs.Repository = &github.Repository{ID: &someId} - mock.EXPECT().ListByOrg(gomock.Any(), "testorg", gomock.Any()).Return( + mock.EXPECT().ListByRepo(gomock.Any(), "testorg", gomock.Any(), gomock.Any()).Return( []*github.Issue{&cs}, &github.Response{}, nil) return client.GithubServices{Issues: mock} diff --git a/website/tables/github/github_issues.md b/website/tables/github/github_issues.md index 6c40ba604b50ac..6e6076b6efb53c 100644 --- a/website/tables/github/github_issues.md +++ b/website/tables/github/github_issues.md @@ -2,7 +2,7 @@ This table shows data for Github Issues. -The composite primary key for this table is (**org**, **id**). +The composite primary key for this table is (**org**, **repository_id**, **id**). ## Columns @@ -13,6 +13,7 @@ The composite primary key for this table is (**org**, **id**). |_cq_id|UUID| |_cq_parent_id|UUID| |org (PK)|String| +|repository_id (PK)|Int| |id (PK)|Int| |number|Int| |state|String|