@@ -12,7 +12,6 @@ import (
1212
1313 "github.com/cli/cli/internal/ghinstance"
1414 "github.com/cli/cli/internal/ghrepo"
15- "github.com/cli/cli/pkg/githubsearch"
1615 "github.com/shurcooL/githubv4"
1716 "golang.org/x/sync/errgroup"
1817)
@@ -910,173 +909,6 @@ func isBlank(v interface{}) bool {
910909 }
911910}
912911
913- func PullRequestList (client * Client , repo ghrepo.Interface , vars map [string ]interface {}, limit int ) (* PullRequestAndTotalCount , error ) {
914- type prBlock struct {
915- Edges []struct {
916- Node PullRequest
917- }
918- PageInfo struct {
919- HasNextPage bool
920- EndCursor string
921- }
922- TotalCount int
923- IssueCount int
924- }
925- type response struct {
926- Repository struct {
927- PullRequests prBlock
928- }
929- Search prBlock
930- }
931-
932- fragment := `
933- fragment pr on PullRequest {
934- number
935- title
936- state
937- url
938- headRefName
939- headRepositoryOwner {
940- login
941- }
942- isCrossRepository
943- isDraft
944- }
945- `
946-
947- // If assignee wasn't specified, use `Repository.pullRequest` for ability to
948- // query by multiple labels
949- query := fragment + `
950- query PullRequestList(
951- $owner: String!,
952- $repo: String!,
953- $limit: Int!,
954- $endCursor: String,
955- $baseBranch: String,
956- $labels: [String!],
957- $state: [PullRequestState!] = OPEN
958- ) {
959- repository(owner: $owner, name: $repo) {
960- pullRequests(
961- states: $state,
962- baseRefName: $baseBranch,
963- labels: $labels,
964- first: $limit,
965- after: $endCursor,
966- orderBy: {field: CREATED_AT, direction: DESC}
967- ) {
968- totalCount
969- edges {
970- node {
971- ...pr
972- }
973- }
974- pageInfo {
975- hasNextPage
976- endCursor
977- }
978- }
979- }
980- }`
981-
982- var check = make (map [int ]struct {})
983- var prs []PullRequest
984- pageLimit := min (limit , 100 )
985- variables := map [string ]interface {}{}
986- res := PullRequestAndTotalCount {}
987-
988- // If assignee was specified, use the `search` API rather than
989- // `Repository.pullRequests`, but this mode doesn't support multiple labels
990- if assignee , ok := vars ["assignee" ].(string ); ok {
991- query = fragment + `
992- query PullRequestList(
993- $q: String!,
994- $limit: Int!,
995- $endCursor: String,
996- ) {
997- search(query: $q, type: ISSUE, first: $limit, after: $endCursor) {
998- issueCount
999- edges {
1000- node {
1001- ...pr
1002- }
1003- }
1004- pageInfo {
1005- hasNextPage
1006- endCursor
1007- }
1008- }
1009- }`
1010- q := githubsearch .NewQuery ()
1011- q .SetType (githubsearch .PullRequest )
1012- q .InRepository (ghrepo .FullName (repo ))
1013- q .AssignedTo (assignee )
1014- q .SortBy (githubsearch .CreatedAt , githubsearch .Desc )
1015- if states , ok := vars ["state" ].([]string ); ok && len (states ) == 1 {
1016- switch states [0 ] {
1017- case "OPEN" :
1018- q .SetState (githubsearch .Open )
1019- case "CLOSED" :
1020- q .SetState (githubsearch .Closed )
1021- case "MERGED" :
1022- q .SetState (githubsearch .Merged )
1023- }
1024- }
1025- if labels , ok := vars ["labels" ].([]string ); ok && len (labels ) > 0 {
1026- if len (labels ) > 1 {
1027- return nil , fmt .Errorf ("multiple labels with --assignee are not supported" )
1028- }
1029- q .AddLabel (labels [0 ])
1030- }
1031- if baseBranch , ok := vars ["baseBranch" ].(string ); ok {
1032- q .SetBaseBranch (baseBranch )
1033- }
1034- variables ["q" ] = q .String ()
1035- } else {
1036- variables ["owner" ] = repo .RepoOwner ()
1037- variables ["repo" ] = repo .RepoName ()
1038- for name , val := range vars {
1039- variables [name ] = val
1040- }
1041- }
1042- loop:
1043- for {
1044- variables ["limit" ] = pageLimit
1045- var data response
1046- err := client .GraphQL (repo .RepoHost (), query , variables , & data )
1047- if err != nil {
1048- return nil , err
1049- }
1050- prData := data .Repository .PullRequests
1051- res .TotalCount = prData .TotalCount
1052- if _ , ok := variables ["q" ]; ok {
1053- prData = data .Search
1054- res .TotalCount = prData .IssueCount
1055- }
1056-
1057- for _ , edge := range prData .Edges {
1058- if _ , exists := check [edge .Node .Number ]; exists {
1059- continue
1060- }
1061-
1062- prs = append (prs , edge .Node )
1063- check [edge .Node .Number ] = struct {}{}
1064- if len (prs ) == limit {
1065- break loop
1066- }
1067- }
1068-
1069- if prData .PageInfo .HasNextPage {
1070- variables ["endCursor" ] = prData .PageInfo .EndCursor
1071- pageLimit = min (pageLimit , limit - len (prs ))
1072- } else {
1073- break
1074- }
1075- }
1076- res .PullRequests = prs
1077- return & res , nil
1078- }
1079-
1080912func PullRequestClose (client * Client , repo ghrepo.Interface , pr * PullRequest ) error {
1081913 var mutation struct {
1082914 ClosePullRequest struct {
0 commit comments