From 95d0f471c1c4946e350b71b179e260b24fe48c49 Mon Sep 17 00:00:00 2001 From: Nicolas Zin Date: Thu, 10 Oct 2024 15:50:40 -0400 Subject: [PATCH] fix archive on delete --- internal/engine/goliac_reconciliator.go | 17 ++++++++++------- internal/goliac.go | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/engine/goliac_reconciliator.go b/internal/engine/goliac_reconciliator.go index 9baf7ba..7b4226e 100644 --- a/internal/engine/goliac_reconciliator.go +++ b/internal/engine/goliac_reconciliator.go @@ -409,6 +409,7 @@ func (r *GoliacReconciliatorImpl) reconciliateRepositories(ctx context.Context, if aRepo, ok := toArchive[reponame]; ok { delete(toArchive, reponame) r.UpdateRepositoryUpdateArchived(ctx, dryrun, remote, reponame, false) + // calling onChanged to update the repository permissions onChanged(reponame, aRepo, rRepo) } else { r.CreateRepository(ctx, dryrun, remote, reponame, reponame, lRepo.Writers, lRepo.Readers, lRepo.IsPublic) @@ -416,14 +417,16 @@ func (r *GoliacReconciliatorImpl) reconciliateRepositories(ctx context.Context, } onRemoved := func(reponame string, lRepo *GithubRepoComparable, rRepo *GithubRepoComparable) { - // if the repository is not archived and we want to archive on delete... - if !rRepo.IsArchived && r.repoconfig.ArchiveOnDelete { - r.UpdateRepositoryUpdateArchived(ctx, dryrun, remote, reponame, true) - toArchive[reponame] = rRepo - } else { - if _, ok := toArchive[reponame]; !ok { - r.DeleteRepository(ctx, dryrun, remote, reponame) + // here we have a repository that is not listed in the teams repository. + // we should call DeleteRepository (that will delete if AllowDestructiveRepositories is on). + // but if we have ArchiveOnDelete... + if r.repoconfig.ArchiveOnDelete { + if r.repoconfig.DestructiveOperations.AllowDestructiveRepositories { + r.UpdateRepositoryUpdateArchived(ctx, dryrun, remote, reponame, true) + toArchive[reponame] = rRepo } + } else { + r.DeleteRepository(ctx, dryrun, remote, reponame) } } diff --git a/internal/goliac.go b/internal/goliac.go index f17f493..ef1ce97 100644 --- a/internal/goliac.go +++ b/internal/goliac.go @@ -190,6 +190,8 @@ func (g *GoliacImpl) applyToGithub(dryrun bool, teamreponame string, branch stri } } + // if the repo was just archived in a previous commit and we "resume it" + // so we keep a track of all repos that we want to archive until the end of the process reposToArchive := make(map[string]*engine.GithubRepoComparable) commits, err := g.local.ListCommitsFromTag(GOLIAC_GIT_TAG)