@@ -21,10 +21,7 @@ func RepositoryResourceCompletionHandler(getClient GetClientFn) func(ctx context
21
21
22
22
argName := req .Params .Argument .Name
23
23
argValue := req .Params .Argument .Value
24
- resolved , ok := any (req .Params .Resolved ).(map [string ]string )
25
- if ! ok && req .Params .Resolved != nil {
26
- return nil , fmt .Errorf (".Resolved must be map[string]string, got %T" , req .Params .Resolved )
27
- }
24
+ resolved := req .Params .Resolved
28
25
if resolved == nil {
29
26
resolved = map [string ]string {}
30
27
}
@@ -123,14 +120,23 @@ func completeRepo(ctx context.Context, client *github.Client, resolved map[strin
123
120
return values , nil
124
121
}
125
122
126
- repos , _ , err := client .Search .Repositories (ctx , fmt .Sprintf ("org:%s %s in:name" , owner , argValue ), & github.SearchOptions {ListOptions : github.ListOptions {PerPage : 100 }})
123
+ query := fmt .Sprintf ("org:%s" , owner )
124
+
125
+ if argValue != "" {
126
+ query = fmt .Sprintf ("%s %s" , query , argValue )
127
+ }
128
+ repos , _ , err := client .Search .Repositories (ctx , query , & github.SearchOptions {ListOptions : github.ListOptions {PerPage : 100 }})
127
129
if err != nil || repos == nil {
128
130
return values , nil
129
131
}
130
-
131
- if len (values ) > 100 {
132
- values = values [:100 ]
132
+ // filter repos based on argValue
133
+ for _ , repo := range repos .Repositories {
134
+ name := repo .GetName ()
135
+ if argValue == "" || strings .HasPrefix (name , argValue ) {
136
+ values = append (values , name )
137
+ }
133
138
}
139
+
134
140
return values , nil
135
141
}
136
142
@@ -144,7 +150,7 @@ func completeBranch(ctx context.Context, client *github.Client, resolved map[str
144
150
branches , _ , _ := client .Repositories .ListBranches (ctx , owner , repo , nil )
145
151
146
152
for _ , branch := range branches {
147
- if argValue == "" || strings .Contains (branch .GetName (), argValue ) {
153
+ if argValue == "" || strings .HasPrefix (branch .GetName (), argValue ) {
148
154
values = append (values , branch .GetName ())
149
155
}
150
156
}
@@ -202,7 +208,7 @@ func completePRNumber(ctx context.Context, client *github.Client, resolved map[s
202
208
return values , nil
203
209
}
204
210
// prs, _, _ := client.PullRequests.List(ctx, owner, repo, &github.PullRequestListOptions{})
205
- prs , _ , _ := client .Search .Issues (ctx , fmt .Sprintf ("repo:%s/%s is:open is:pr %s " , owner , repo , argValue ), & github.SearchOptions {ListOptions : github.ListOptions {PerPage : 100 }})
211
+ prs , _ , _ := client .Search .Issues (ctx , fmt .Sprintf ("repo:%s/%s is:open is:pr" , owner , repo ), & github.SearchOptions {ListOptions : github.ListOptions {PerPage : 100 }})
206
212
for _ , pr := range prs .Issues {
207
213
num := fmt .Sprintf ("%d" , pr .GetNumber ())
208
214
if argValue == "" || strings .HasPrefix (num , argValue ) {
0 commit comments