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

Match hostnames case-insensitively #105

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 0 additions & 70 deletions internal/set/string_set.go

This file was deleted.

27 changes: 0 additions & 27 deletions internal/set/string_set_test.go

This file was deleted.

3 changes: 2 additions & 1 deletion internal/yamlmap/yaml_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package yamlmap

import (
"errors"
"strings"

"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -75,7 +76,7 @@ func (m *Map) FindEntry(key string) (*Map, error) {
if i%2 != 0 {
continue
}
if v.Value == key {
if strings.EqualFold(v.Value, key) {
if i+1 < len(m.Content) {
return &Map{m.Content[i+1]}, nil
}
Expand Down
24 changes: 16 additions & 8 deletions pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strconv"
"strings"

"github.com/cli/go-gh/internal/set"
"github.com/cli/go-gh/pkg/config"
"github.com/cli/safeexec"
)
Expand Down Expand Up @@ -105,20 +104,29 @@ func KnownHosts() []string {
}

func knownHosts(cfg *config.Config) []string {
hosts := set.NewStringSet()
hosts := []string{}
hostIndex := map[string]struct{}{}
add := func(h string) {
h = strings.ToLower(h)
if _, found := hostIndex[h]; !found {
hosts = append(hosts, h)
hostIndex[h] = struct{}{}
}
}

if host := os.Getenv(ghHost); host != "" {
hosts.Add(host)
add(host)
}
if token, _ := tokenForHost(cfg, github); token != "" {
hosts.Add(github)
add(github)
}
if cfg != nil {
keys, err := cfg.Keys([]string{hostsKey})
if err == nil {
hosts.AddValues(keys)
keys, _ := cfg.Keys([]string{hostsKey})
for _, k := range keys {
add(k)
}
}
return hosts.ToSlice()
return hosts
}

// DefaultHost retrieves an authenticated host and the source of host.
Expand Down