Skip to content

Commit

Permalink
fix: warn users of overlapping repositories with orgs/users/etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
lindell committed Nov 22, 2024
1 parent ca13019 commit 4d5c261
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"context"
"fmt"
"slices"
"strings"

"github.com/lindell/multi-gitter/internal/http"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions internal/scm/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/")
Expand Down
4 changes: 4 additions & 0 deletions internal/scm/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/")
Expand Down

0 comments on commit 4d5c261

Please sign in to comment.