Skip to content
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
19 changes: 10 additions & 9 deletions pkg/config/conf.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ var (
field.WithDisplayName("Sync secrets"),
field.WithDescription(`Whether to sync secrets or not`),
)
omitArchivedRepositories = field.BoolField(
"omit-archived-repositories",
field.WithDisplayName("Omit syncing archived repositories"),
field.WithDescription("Whether to skip syncing archived repositories or not"),
)
fieldRelationships = []field.SchemaFieldRelationship{
field.FieldsMutuallyExclusive(
accessTokenField,
Expand All @@ -63,6 +68,7 @@ var Config = field.NewConfiguration(
EnterprisesField,
instanceUrlField,
syncSecrets,
omitArchivedRepositories,
appIDField,
appPrivateKeyPath,
},
Expand Down
42 changes: 22 additions & 20 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,25 @@ var (
)

type GitHub struct {
orgs []string
client *github.Client
appClient *github.Client
customClient *customclient.Client
instanceURL string
graphqlClient *githubv4.Client
hasSAMLEnabled *bool
orgCache *orgNameCache
syncSecrets bool
enterprises []string
orgs []string
client *github.Client
appClient *github.Client
customClient *customclient.Client
instanceURL string
graphqlClient *githubv4.Client
hasSAMLEnabled *bool
orgCache *orgNameCache
syncSecrets bool
omitArchivedRepositories bool
enterprises []string
}

func (gh *GitHub) ResourceSyncers(ctx context.Context) []connectorbuilder.ResourceSyncer {
resourceSyncers := []connectorbuilder.ResourceSyncer{
orgBuilder(gh.client, gh.appClient, gh.orgCache, gh.orgs, gh.syncSecrets),
teamBuilder(gh.client, gh.orgCache),
userBuilder(gh.client, gh.hasSAMLEnabled, gh.graphqlClient, gh.orgCache, gh.orgs),
repositoryBuilder(gh.client, gh.orgCache),
repositoryBuilder(gh.client, gh.orgCache, gh.omitArchivedRepositories),
orgRoleBuilder(gh.client, gh.orgCache),
invitationBuilder(invitationBuilderParams{
client: gh.client,
Expand Down Expand Up @@ -306,15 +307,16 @@ func New(ctx context.Context, ghc *cfg.Github, appKey string) (*GitHub, error) {
}

gh := &GitHub{
client: ghClient,
appClient: appClient,
customClient: customclient.New(ghClient),
instanceURL: ghc.InstanceUrl,
orgs: ghc.Orgs,
enterprises: ghc.Enterprises,
graphqlClient: graphqlClient,
orgCache: newOrgNameCache(ghClient),
syncSecrets: ghc.SyncSecrets,
client: ghClient,
appClient: appClient,
customClient: customclient.New(ghClient),
instanceURL: ghc.InstanceUrl,
orgs: ghc.Orgs,
enterprises: ghc.Enterprises,
graphqlClient: graphqlClient,
orgCache: newOrgNameCache(ghClient),
syncSecrets: ghc.SyncSecrets,
omitArchivedRepositories: ghc.OmitArchivedRepositories,
}
return gh, nil
}
Expand Down
19 changes: 12 additions & 7 deletions pkg/connector/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ func repositoryResource(ctx context.Context, repo *github.Repository, parentReso
}

type repositoryResourceType struct {
resourceType *v2.ResourceType
client *github.Client
orgCache *orgNameCache
resourceType *v2.ResourceType
client *github.Client
orgCache *orgNameCache
omitArchivedRepositories bool
}

func (o *repositoryResourceType) ResourceType(_ context.Context) *v2.ResourceType {
Expand Down Expand Up @@ -105,6 +106,9 @@ func (o *repositoryResourceType) List(ctx context.Context, parentID *v2.Resource

rv := make([]*v2.Resource, 0, len(repos))
for _, repo := range repos {
if o.omitArchivedRepositories && repo.GetArchived() {
continue
}
Comment on lines +109 to +111
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

LGTM! Verify test coverage for the filtering behavior.

The filtering logic correctly skips archived repositories when the flag is enabled. The implementation properly handles the case where archived repos are fetched from the API but filtered client-side (as noted in the PR description, there's no API-level filter available).

Run the following script to verify that tests exist for the archived repository filtering behavior:


🏁 Script executed:

#!/bin/bash
# Description: Check for test coverage of the omitArchivedRepositories filtering logic

# Search for test functions that exercise the filtering behavior
rg -n "omitArchivedRepositories" --type=go -g '*_test.go' -C 5

# Look for tests that verify archived repositories are filtered
rg -n -i "archived.*repositor" --type=go -g '*_test.go' -C 3

Length of output: 0


Let me search more broadly for test coverage:


---

🏁 Script executed:

```shell
#!/bin/bash
# Find test files related to repository.go
fd -e '_test.go' --path '*repository*' 

# Look for all test files in connector package
fd -e '_test.go' . | grep -i connector

# Search for List method tests (broader pattern)
rg -n "func.*Test.*List" --type=go -g '*_test.go'

# Check if repository.go has any tests at all
rg -n "func.*Test.*Repositor" --type=go -g '*_test.go'

Length of output: 370



---

🏁 Script executed:

```shell
#!/bin/bash
# Examine the repository_test.go file
cat pkg/connector/repository_test.go

# Also check if there are specific tests for the List method with filtering
rg -n "archived" --type=go pkg/connector/repository_test.go

Length of output: 2056



---

🏁 Script executed:

```shell
#!/bin/bash
# Examine the List method in repository.go to understand what needs testing
rg -n "func.*List" --type=go -B 2 -A 20 pkg/connector/repository.go | head -60

Length of output: 671



---

🏁 Script executed:

```shell
#!/bin/bash
# Get more of the List method, focusing on the filtering logic around lines 109-111
rg -n "func.*List" --type=go -B 2 -A 50 pkg/connector/repository.go | head -90

Length of output: 1472


Test coverage required for the omitArchivedRepositories filtering logic.

The filtering implementation is correct, but there are currently no tests for the List method or the omitArchivedRepositories flag. Tests must be added to cover:

  • List method correctly returns repositories when omitArchivedRepositories is false
  • List method filters out archived repositories when omitArchivedRepositories is true
  • Pagination still works correctly when repositories are filtered out
🤖 Prompt for AI Agents
In pkg/connector/repository.go around lines 109 to 111, add unit tests for the
List method to cover omitArchivedRepositories behavior: create test cases that
(1) set omitArchivedRepositories=false and verify archived and non-archived
repos are returned, (2) set omitArchivedRepositories=true and verify archived
repos are excluded, and (3) verify pagination still returns correct pages when
archived repos are filtered out (e.g., create >pageSize repos with mixed
archived flags, request specific pages and assert contents and counts). Use the
existing test harness/mocks for the repository store, seed deterministic repo
objects with GetArchived() true/false, assert total counts and per-page results,
and include edge cases (no repos, all archived, all unarchived).

rr, err := repositoryResource(ctx, repo, parentID)
if err != nil {
return nil, "", nil, err
Expand Down Expand Up @@ -409,11 +413,12 @@ func (o *repositoryResourceType) Revoke(ctx context.Context, grant *v2.Grant) (a
return nil, nil
}

func repositoryBuilder(client *github.Client, orgCache *orgNameCache) *repositoryResourceType {
func repositoryBuilder(client *github.Client, orgCache *orgNameCache, omitArchivedRepositories bool) *repositoryResourceType {
return &repositoryResourceType{
resourceType: resourceTypeRepository,
client: client,
orgCache: orgCache,
resourceType: resourceTypeRepository,
client: client,
orgCache: orgCache,
omitArchivedRepositories: omitArchivedRepositories,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestRepository(t *testing.T) {

githubClient := github.NewClient(mgh.Server())
cache := newOrgNameCache(githubClient)
client := repositoryBuilder(githubClient, cache)
client := repositoryBuilder(githubClient, cache, false)

organization, _ := organizationResource(ctx, githubOrganization, nil, false)
repository, _ := repositoryResource(ctx, githubRepository, organization.Id)
Expand Down