diff --git a/pkg/config/conf.gen.go b/pkg/config/conf.gen.go index 9a1c2472..d6d0b78c 100644 --- a/pkg/config/conf.gen.go +++ b/pkg/config/conf.gen.go @@ -1,19 +1,20 @@ // Code generated by baton-sdk. DO NOT EDIT!!! package config -import "reflect" +import "reflect" type Github struct { - Token string `mapstructure:"token"` - Orgs []string `mapstructure:"orgs"` - Enterprises []string `mapstructure:"enterprises"` - InstanceUrl string `mapstructure:"instance-url"` - SyncSecrets bool `mapstructure:"sync-secrets"` - AppId string `mapstructure:"app-id"` - AppPrivatekeyPath string `mapstructure:"app-privatekey-path"` + Token string `mapstructure:"token"` + Orgs []string `mapstructure:"orgs"` + Enterprises []string `mapstructure:"enterprises"` + InstanceUrl string `mapstructure:"instance-url"` + SyncSecrets bool `mapstructure:"sync-secrets"` + OmitArchivedRepositories bool `mapstructure:"omit-archived-repositories"` + AppId string `mapstructure:"app-id"` + AppPrivatekeyPath string `mapstructure:"app-privatekey-path"` } -func (c* Github) findFieldByTag(tagValue string) (any, bool) { +func (c *Github) findFieldByTag(tagValue string) (any, bool) { v := reflect.ValueOf(c).Elem() // Dereference pointer to struct t := v.Type() diff --git a/pkg/config/config.go b/pkg/config/config.go index 50f6eb8c..2e4dd814 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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, @@ -63,6 +68,7 @@ var Config = field.NewConfiguration( EnterprisesField, instanceUrlField, syncSecrets, + omitArchivedRepositories, appIDField, appPrivateKeyPath, }, diff --git a/pkg/connector/connector.go b/pkg/connector/connector.go index 0269d214..d4c9808a 100644 --- a/pkg/connector/connector.go +++ b/pkg/connector/connector.go @@ -89,16 +89,17 @@ 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 { @@ -106,7 +107,7 @@ func (gh *GitHub) ResourceSyncers(ctx context.Context) []connectorbuilder.Resour 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, @@ -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 } diff --git a/pkg/connector/repository.go b/pkg/connector/repository.go index 2e761c88..550acd4d 100644 --- a/pkg/connector/repository.go +++ b/pkg/connector/repository.go @@ -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 { @@ -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 + } rr, err := repositoryResource(ctx, repo, parentID) if err != nil { return nil, "", nil, err @@ -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, } } diff --git a/pkg/connector/repository_test.go b/pkg/connector/repository_test.go index b6770bac..5c6ab7bc 100644 --- a/pkg/connector/repository_test.go +++ b/pkg/connector/repository_test.go @@ -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)