55 "encoding/base64"
66 "encoding/json"
77 "fmt"
8+ "sort"
89 "strings"
910
1011 "github.com/cli/cli/api"
@@ -101,14 +102,15 @@ func putRepoSecret(client *api.Client, pk *PubKey, repo ghrepo.Interface, secret
101102 return putSecret (client , repo .RepoHost (), path , payload )
102103}
103104
105+ // This does similar logic to `api.RepoNetwork`, but without the overfetching.
104106func mapRepoNameToID (client * api.Client , host , orgName string , repositoryNames []string ) ([]int , error ) {
105107 queries := make ([]string , 0 , len (repositoryNames ))
106- for _ , repoName := range repositoryNames {
108+ for i , repoName := range repositoryNames {
107109 queries = append (queries , fmt .Sprintf (`
108- %s : repository(owner: %q, name : %q) {
110+ repo_%03d : repository(owner: %q, name: %q) {
109111 databaseId
110112 }
111- ` , repoName , orgName , repoName ))
113+ ` , i , orgName , repoName ))
112114 }
113115
114116 query := fmt .Sprintf (`query MapRepositoryNames { %s }` , strings .Join (queries , "" ))
@@ -131,10 +133,15 @@ func mapRepoNameToID(client *api.Client, host, orgName string, repositoryNames [
131133 return nil , fmt .Errorf ("failed to look up repositories: %w" , err )
132134 }
133135
134- result := make ([]int , 0 , len (repositoryNames ))
136+ repoKeys := make ([]string , 0 , len (repositoryNames ))
137+ for k := range graphqlResult {
138+ repoKeys = append (repoKeys , k )
139+ }
140+ sort .Strings (repoKeys )
135141
136- for _ , repoName := range repositoryNames {
137- result = append (result , graphqlResult [repoName ].DatabaseID )
142+ result := make ([]int , len (repositoryNames ))
143+ for i , k := range repoKeys {
144+ result [i ] = graphqlResult [k ].DatabaseID
138145 }
139146
140147 return result , nil
0 commit comments