Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: warn users of overlapping repositories with orgs/users/etc. #511

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading