gh pr create duplicates targets if there are duplicate remotes (#8184)

* `gh pr create` duplicates targets if there are duplicate remotes

* De-duplicate the same remote
This commit is contained in:
EBIBO 2023-10-17 16:21:35 +08:00 committed by GitHub
parent 5916439d22
commit fd8bbf0be5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@ package context
import (
"errors"
"fmt"
"slices"
"sort"
"github.com/cli/cli/v2/api"
@ -116,9 +117,11 @@ func (r *ResolvedRemotes) HeadRepos() ([]*api.Repository, error) {
}
var results []*api.Repository
var ids []string // Check if repo duplicates
for _, repo := range r.network.Repositories {
if repo != nil && repo.ViewerCanPush() {
if repo != nil && repo.ViewerCanPush() && !slices.Contains(ids, repo.ID) {
results = append(results, repo)
ids = append(ids, repo.ID)
}
}
return results, nil