@@ -21,10 +21,7 @@ func RepositoryResourceCompletionHandler(getClient GetClientFn) func(ctx context
2121
2222 argName := req .Params .Argument .Name
2323 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
2825 if resolved == nil {
2926 resolved = map [string ]string {}
3027 }
@@ -123,14 +120,23 @@ func completeRepo(ctx context.Context, client *github.Client, resolved map[strin
123120 return values , nil
124121 }
125122
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 }})
127129 if err != nil || repos == nil {
128130 return values , nil
129131 }
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+ }
133138 }
139+
134140 return values , nil
135141}
136142
@@ -144,7 +150,7 @@ func completeBranch(ctx context.Context, client *github.Client, resolved map[str
144150 branches , _ , _ := client .Repositories .ListBranches (ctx , owner , repo , nil )
145151
146152 for _ , branch := range branches {
147- if argValue == "" || strings .Contains (branch .GetName (), argValue ) {
153+ if argValue == "" || strings .HasPrefix (branch .GetName (), argValue ) {
148154 values = append (values , branch .GetName ())
149155 }
150156 }
@@ -202,7 +208,7 @@ func completePRNumber(ctx context.Context, client *github.Client, resolved map[s
202208 return values , nil
203209 }
204210 // 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 }})
206212 for _ , pr := range prs .Issues {
207213 num := fmt .Sprintf ("%d" , pr .GetNumber ())
208214 if argValue == "" || strings .HasPrefix (num , argValue ) {
0 commit comments