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

feat(appset): filtering repos by archived status #20736

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions applicationset/generators/scm_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (g *SCMProviderGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha
if err != nil {
return nil, fmt.Errorf("error fetching Gitea token: %w", err)
}
provider, err = scm_provider.NewGiteaProvider(ctx, providerConfig.Gitea.Owner, token, providerConfig.Gitea.API, providerConfig.Gitea.AllBranches, providerConfig.Gitea.Insecure)
provider, err = scm_provider.NewGiteaProvider(ctx, providerConfig.Gitea.Owner, token, providerConfig.Gitea.API, providerConfig.Gitea.AllBranches, providerConfig.Gitea.Insecure, providerConfig.Gitea.ExcludeArchivedRepos)
if err != nil {
return nil, fmt.Errorf("error initializing Gitea service: %w", err)
}
Expand Down Expand Up @@ -282,12 +282,13 @@ func (g *SCMProviderGenerator) githubProvider(ctx context.Context, github *argop
github.Organization,
github.API,
github.AllBranches,
github.ExcludeArchivedRepos,
)
}

token, err := utils.GetSecretRef(ctx, g.client, github.TokenRef, applicationSetInfo.Namespace, g.tokenRefStrictMode)
if err != nil {
return nil, fmt.Errorf("error fetching Github token: %w", err)
}
return scm_provider.NewGithubProvider(ctx, github.Organization, token, github.API, github.AllBranches)
return scm_provider.NewGithubProvider(ctx, github.Organization, token, github.API, github.AllBranches, github.ExcludeArchivedRepos)
}
21 changes: 14 additions & 7 deletions applicationset/services/scm_provider/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
)

type GiteaProvider struct {
client *gitea.Client
owner string
allBranches bool
client *gitea.Client
owner string
allBranches bool
excludeArchivedRepos bool
}

var _ SCMProviderService = &GiteaProvider{}

func NewGiteaProvider(ctx context.Context, owner, token, url string, allBranches, insecure bool) (*GiteaProvider, error) {
func NewGiteaProvider(ctx context.Context, owner, token, url string, allBranches, insecure bool, excludeArchivedRepos bool) (*GiteaProvider, error) {
if token == "" {
token = os.Getenv("GITEA_TOKEN")
}
Expand All @@ -40,9 +41,10 @@ func NewGiteaProvider(ctx context.Context, owner, token, url string, allBranches
return nil, fmt.Errorf("error creating a new gitea client: %w", err)
}
return &GiteaProvider{
client: client,
owner: owner,
allBranches: allBranches,
client: client,
owner: owner,
allBranches: allBranches,
excludeArchivedRepos: excludeArchivedRepos,
}, nil
}

Expand Down Expand Up @@ -114,6 +116,11 @@ func (g *GiteaProvider) ListRepos(ctx context.Context, cloneProtocol string) ([]
for _, label := range giteaLabels {
labels = append(labels, label.Name)
}

if g.excludeArchivedRepos && repo.Archived {
continue
}

repos = append(repos, &Repository{
Organization: g.owner,
Repository: repo.Name,
Expand Down
Loading
Loading