From 04d1ffc971a4e58a2c4c6fa9d127c7ab01d2fb7d Mon Sep 17 00:00:00 2001 From: kjuulh Date: Thu, 15 Sep 2022 10:42:44 +0200 Subject: [PATCH] with process repos --- cmd/kraken/commands/process.go | 2 +- internal/commands/process_repos.go | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/cmd/kraken/commands/process.go b/cmd/kraken/commands/process.go index 274b299..81642ea 100644 --- a/cmd/kraken/commands/process.go +++ b/cmd/kraken/commands/process.go @@ -22,7 +22,7 @@ func CreateKrakenProcessCmd() *cobra.Command { Path string `json:"path"` }{ Repository: "git@git.front.kjuulh.io:kjuulh/kraken.git", - Branch: "feature/add-actions", + Branch: "feature/process_repos", Path: "_examples/actions/write_a_readme/", }) if err != nil { diff --git a/internal/commands/process_repos.go b/internal/commands/process_repos.go index d29a30b..614f0cf 100644 --- a/internal/commands/process_repos.go +++ b/internal/commands/process_repos.go @@ -7,6 +7,8 @@ import ( "time" "git.front.kjuulh.io/kjuulh/kraken/internal/actions" + "git.front.kjuulh.io/kjuulh/kraken/internal/gitproviders" + "git.front.kjuulh.io/kjuulh/kraken/internal/schema" "git.front.kjuulh.io/kjuulh/kraken/internal/services/providers" "git.front.kjuulh.io/kjuulh/kraken/internal/services/storage" "go.uber.org/zap" @@ -18,12 +20,14 @@ type ( storage *storage.Service git *providers.Git actionCreator *actions.ActionCreator + gitea *gitproviders.Gitea } ProcessReposDeps interface { GetStorageService() *storage.Service GetGitProvider() *providers.Git GetActionCreator() *actions.ActionCreator + GetGitea() *gitproviders.Gitea } ) @@ -33,6 +37,7 @@ func NewProcessRepos(logger *zap.Logger, deps ProcessReposDeps) *ProcessRepos { storage: deps.GetStorageService(), git: deps.GetGitProvider(), actionCreator: deps.GetActionCreator(), + gitea: deps.GetGitea(), } } @@ -48,7 +53,10 @@ func (pr *ProcessRepos) Process(ctx context.Context, repository string, branch s return err } - repositoryUrls := action.Schema.Select.Repositories + repositoryUrls, err := pr.getRepoUrls(ctx, action.Schema) + if err != nil { + return err + } wg := sync.WaitGroup{} wg.Add(len(repositoryUrls)) @@ -76,6 +84,23 @@ func (pr *ProcessRepos) Process(ctx context.Context, repository string, branch s return nil } +func (pr *ProcessRepos) getRepoUrls(ctx context.Context, schema *schema.KrakenSchema) ([]string, error) { + repoUrls := make([]string, 0) + + repoUrls = append(repoUrls, schema.Select.Repositories...) + + for _, provider := range schema.Select.Providers { + repos, err := pr.gitea.ListRepositoriesForOrganization(ctx, provider.Gitea, provider.Organisation) + if err != nil { + return nil, err + } + + repoUrls = append(repoUrls, repos...) + } + + return repoUrls, nil +} + func (pr *ProcessRepos) processRepo(ctx context.Context, repoUrl string, action *actions.Action) error { cleanup, area, err := pr.prepareAction(ctx) defer func() {