Fix secret set --repos for repositories that have dashes
A GraphQL alias cannot contain dashes. Instead, generate safe identifiers for GraphQL aliases.
This commit is contained in:
parent
a881c130c3
commit
f8135c15b1
1 changed files with 13 additions and 6 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/cli/cli/api"
|
||||
|
|
@ -101,14 +102,15 @@ func putRepoSecret(client *api.Client, pk *PubKey, repo ghrepo.Interface, secret
|
|||
return putSecret(client, repo.RepoHost(), path, payload)
|
||||
}
|
||||
|
||||
// This does similar logic to `api.RepoNetwork`, but without the overfetching.
|
||||
func mapRepoNameToID(client *api.Client, host, orgName string, repositoryNames []string) ([]int, error) {
|
||||
queries := make([]string, 0, len(repositoryNames))
|
||||
for _, repoName := range repositoryNames {
|
||||
for i, repoName := range repositoryNames {
|
||||
queries = append(queries, fmt.Sprintf(`
|
||||
%s: repository(owner: %q, name :%q) {
|
||||
repo_%03d: repository(owner: %q, name: %q) {
|
||||
databaseId
|
||||
}
|
||||
`, repoName, orgName, repoName))
|
||||
`, i, orgName, repoName))
|
||||
}
|
||||
|
||||
query := fmt.Sprintf(`query MapRepositoryNames { %s }`, strings.Join(queries, ""))
|
||||
|
|
@ -131,10 +133,15 @@ func mapRepoNameToID(client *api.Client, host, orgName string, repositoryNames [
|
|||
return nil, fmt.Errorf("failed to look up repositories: %w", err)
|
||||
}
|
||||
|
||||
result := make([]int, 0, len(repositoryNames))
|
||||
repoKeys := make([]string, 0, len(repositoryNames))
|
||||
for k := range graphqlResult {
|
||||
repoKeys = append(repoKeys, k)
|
||||
}
|
||||
sort.Strings(repoKeys)
|
||||
|
||||
for _, repoName := range repositoryNames {
|
||||
result = append(result, graphqlResult[repoName].DatabaseID)
|
||||
result := make([]int, len(repositoryNames))
|
||||
for i, k := range repoKeys {
|
||||
result[i] = graphqlResult[k].DatabaseID
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue