SearchRepoAssignableActors searches assignable actors for a repository with an optional query string. Unlike RepoAssignableActors which fetches all actors with pagination, this returns up to 10 results matching the query, suitable for search-based selection.
(client *Client, repo ghrepo.Interface, query string)
| 1345 | // query string. Unlike RepoAssignableActors which fetches all actors with pagination, this |
| 1346 | // returns up to 10 results matching the query, suitable for search-based selection. |
| 1347 | func SearchRepoAssignableActors(client *Client, repo ghrepo.Interface, query string) ([]AssignableActor, int, error) { |
| 1348 | type responseData struct { |
| 1349 | Repository struct { |
| 1350 | AssignableUsers struct { |
| 1351 | TotalCount int |
| 1352 | } |
| 1353 | SuggestedActors struct { |
| 1354 | Nodes []struct { |
| 1355 | User struct { |
| 1356 | ID string |
| 1357 | Login string |
| 1358 | Name string |
| 1359 | TypeName string `graphql:"__typename"` |
| 1360 | } `graphql:"... on User"` |
| 1361 | Bot struct { |
| 1362 | ID string |
| 1363 | Login string |
| 1364 | TypeName string `graphql:"__typename"` |
| 1365 | } `graphql:"... on Bot"` |
| 1366 | } |
| 1367 | } `graphql:"suggestedActors(first: 10, query: $query, capabilities: CAN_BE_ASSIGNED)"` |
| 1368 | } `graphql:"repository(owner: $owner, name: $name)"` |
| 1369 | } |
| 1370 | |
| 1371 | var q *githubv4.String |
| 1372 | if query != "" { |
| 1373 | v := githubv4.String(query) |
| 1374 | q = &v |
| 1375 | } |
| 1376 | |
| 1377 | variables := map[string]interface{}{ |
| 1378 | "owner": githubv4.String(repo.RepoOwner()), |
| 1379 | "name": githubv4.String(repo.RepoName()), |
| 1380 | "query": q, |
| 1381 | } |
| 1382 | |
| 1383 | var result responseData |
| 1384 | if err := client.Query(repo.RepoHost(), "SearchRepoAssignableActors", &result, variables); err != nil { |
| 1385 | return nil, 0, err |
| 1386 | } |
| 1387 | |
| 1388 | var actors []AssignableActor |
| 1389 | for _, node := range result.Repository.SuggestedActors.Nodes { |
| 1390 | if node.User.TypeName == "User" { |
| 1391 | actors = append(actors, AssignableUser{ |
| 1392 | id: node.User.ID, |
| 1393 | login: node.User.Login, |
| 1394 | name: node.User.Name, |
| 1395 | }) |
| 1396 | } else if node.Bot.TypeName == "Bot" { |
| 1397 | actors = append(actors, AssignableBot{ |
| 1398 | id: node.Bot.ID, |
| 1399 | login: node.Bot.Login, |
| 1400 | }) |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | return actors, result.Repository.AssignableUsers.TotalCount, nil |