Skip to content

Commit

Permalink
Merge pull request #67 from AlayaCare/fixArchiveOnDelete
Browse files Browse the repository at this point in the history
fix archive on delete
  • Loading branch information
nzin-alayacare authored Oct 10, 2024
2 parents 5162a7c + 95d0f47 commit 43df7da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 10 additions & 7 deletions internal/engine/goliac_reconciliator.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,21 +409,24 @@ 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)
}
}

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)
}
}

Expand Down
2 changes: 2 additions & 0 deletions internal/goliac.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 43df7da

Please sign in to comment.