Skip to content

Commit

Permalink
feat(appset): filtering repos by archived status #20736
Browse files Browse the repository at this point in the history
Signed-off-by: Prune <[email protected]>
missing returned values for github scm

Signed-off-by: Prune <[email protected]>

adding generated code

Signed-off-by: Prune <[email protected]>

correct rebase issues

correct test cases for gitlab
  • Loading branch information
prune998 committed Jan 16, 2025
1 parent 11b8665 commit f8b9123
Show file tree
Hide file tree
Showing 20 changed files with 2,571 additions and 889 deletions.
7 changes: 4 additions & 3 deletions applicationset/generators/scm_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (g *SCMProviderGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha
if err != nil {
return nil, fmt.Errorf("error fetching Gitlab token: %w", err)
}
provider, err = scm_provider.NewGitlabProvider(providerConfig.Group, token, providerConfig.API, providerConfig.AllBranches, providerConfig.IncludeSubgroups, providerConfig.WillIncludeSharedProjects(), providerConfig.Insecure, g.scmRootCAPath, providerConfig.Topic, caCerts)
provider, err = scm_provider.NewGitlabProvider(providerConfig.Group, token, providerConfig.API, providerConfig.AllBranches, providerConfig.IncludeSubgroups, providerConfig.WillIncludeSharedProjects(), providerConfig.IncludeArchivedRepos, providerConfig.Insecure, g.scmRootCAPath, providerConfig.Topic, caCerts)
if err != nil {
return nil, fmt.Errorf("error initializing Gitlab service: %w", err)
}
Expand All @@ -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(providerConfig.Gitea.Owner, token, providerConfig.Gitea.API, providerConfig.Gitea.AllBranches, providerConfig.Gitea.Insecure)
provider, err = scm_provider.NewGiteaProvider(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(github.Organization, token, github.API, github.AllBranches)
return scm_provider.NewGithubProvider(github.Organization, token, github.API, github.AllBranches, false)
}
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(owner, token, url string, allBranches, insecure bool) (*GiteaProvider, error) {
func NewGiteaProvider(owner, token, url string, allBranches, insecure, excludeArchivedRepos bool) (*GiteaProvider, error) {
if token == "" {
token = os.Getenv("GITEA_TOKEN")
}
Expand All @@ -40,9 +41,10 @@ func NewGiteaProvider(owner, token, url string, allBranches, insecure bool) (*Gi
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(_ context.Context, cloneProtocol string) ([]*R
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

0 comments on commit f8b9123

Please sign in to comment.