From 4d5c261c6e4e29a911424c953ff7bf869cf7e517 Mon Sep 17 00:00:00 2001 From: Johan Lindell Date: Fri, 22 Nov 2024 22:03:38 +0100 Subject: [PATCH] fix: warn users of overlapping repositories with orgs/users/etc. --- cmd/platform.go | 20 ++++++++++++++++++++ internal/scm/gitea/gitea.go | 4 ++++ internal/scm/gitlab/gitlab.go | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/cmd/platform.go b/cmd/platform.go index bc21bcf9..2d2ed62e 100644 --- a/cmd/platform.go +++ b/cmd/platform.go @@ -3,6 +3,7 @@ package cmd import ( "context" "fmt" + "slices" "strings" "github.com/lindell/multi-gitter/internal/http" @@ -13,6 +14,7 @@ import ( "github.com/lindell/multi-gitter/internal/scm/github" "github.com/lindell/multi-gitter/internal/scm/gitlab" "github.com/pkg/errors" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" flag "github.com/spf13/pflag" ) @@ -163,6 +165,12 @@ func createGithubClient(flag *flag.FlagSet, verifyFlags bool, readOnly bool) (mu if err != nil { return nil, err } + if slices.Contains(orgs, repoRefs[i].OwnerName) { + log.Warnf("Repository %s and organization %s are both set. This is likely a mistake", repoRefs[i].String(), repoRefs[i].OwnerName) + } + if slices.Contains(users, repoRefs[i].OwnerName) { + log.Warnf("Repository %s and user %s are both set. This is likely a mistake", repoRefs[i].String(), repoRefs[i].OwnerName) + } } mergeTypes, err := getMergeTypes(flag) @@ -222,6 +230,12 @@ func createGitlabClient(flag *flag.FlagSet, verifyFlags bool) (multigitter.Versi if err != nil { return nil, err } + if slices.Contains(groups, projRefs[i].OwnerName) { + log.Warnf("Repository %s and group %s are both set. This is likely a mistake", projRefs[i].String(), projRefs[i].OwnerName) + } + if slices.Contains(users, projRefs[i].OwnerName) { + log.Warnf("Repository %s and user %s are both set. This is likely a mistake", projRefs[i].String(), projRefs[i].OwnerName) + } } vc, err := gitlab.New(token, gitBaseURL, gitlab.RepositoryListing{ @@ -269,6 +283,12 @@ func createGiteaClient(flag *flag.FlagSet, verifyFlags bool) (multigitter.Versio if err != nil { return nil, err } + if slices.Contains(orgs, repoRefs[i].OwnerName) { + log.Warnf("Repository %s and organization %s are both set. This is likely a mistake", repoRefs[i].String(), repoRefs[i].OwnerName) + } + if slices.Contains(users, repoRefs[i].OwnerName) { + log.Warnf("Repository %s and user %s are both set. This is likely a mistake", repoRefs[i].String(), repoRefs[i].OwnerName) + } } mergeTypes, err := getMergeTypes(flag) diff --git a/internal/scm/gitea/gitea.go b/internal/scm/gitea/gitea.go index 01fbfd32..c760cecb 100644 --- a/internal/scm/gitea/gitea.go +++ b/internal/scm/gitea/gitea.go @@ -79,6 +79,10 @@ type RepositoryReference struct { Name string } +func (r RepositoryReference) String() string { + return fmt.Sprintf("%s/%s", r.OwnerName, r.Name) +} + // ParseRepositoryReference parses a repository reference from the format "ownerName/repoName" func ParseRepositoryReference(val string) (RepositoryReference, error) { split := strings.Split(val, "/") diff --git a/internal/scm/gitlab/gitlab.go b/internal/scm/gitlab/gitlab.go index bc62e904..f557321a 100644 --- a/internal/scm/gitlab/gitlab.go +++ b/internal/scm/gitlab/gitlab.go @@ -71,6 +71,10 @@ type ProjectReference struct { Name string } +func (p ProjectReference) String() string { + return fmt.Sprintf("%s/%s", p.OwnerName, p.Name) +} + // ParseProjectReference parses a repository reference from the format "ownerName/repoName" func ParseProjectReference(val string) (ProjectReference, error) { lastSlashIndex := strings.LastIndex(val, "/")