@@ -8,88 +8,83 @@ import {
88 generateUpdateProjectNextItemFieldMutation ,
99} from './projects.js'
1010
11- async function run ( ) {
12- // Get info about the docs-content review board project
13- // and about open github/github PRs
14- const data = await graphql (
15- `
16- query ($organization: String!, $repo: String!, $projectNumber: Int!, $num_prs: Int!) {
17- organization(login: $organization) {
18- projectNext(number: $projectNumber) {
19- id
20- items(last: 100) {
11+ async function getAllOpenPRs ( ) {
12+ let prsRemaining = true
13+ let cursor
14+ let prData = [ ]
15+ while ( prsRemaining ) {
16+ const data = await graphql (
17+ `
18+ query ($organization: String!, $repo: String!) {
19+ repository(name: $repo, owner: $organization) {
20+ pullRequests(last: 100, states: OPEN${ cursor ? ` before:"${ cursor } "` : '' } ) {
21+ pageInfo{startCursor, hasPreviousPage},
2122 nodes {
2223 id
23- }
24- }
25- fields(first: 20) {
26- nodes {
27- id
28- name
29- settings
30- }
31- }
32- }
33- }
34- repository(name: $repo, owner: $organization) {
35- pullRequests(last: $num_prs, states: OPEN) {
36- nodes {
37- id
38- isDraft
39- reviewRequests(first: 10) {
40- nodes {
41- requestedReviewer {
42- ... on Team {
43- name
24+ isDraft
25+ reviewRequests(first: 10) {
26+ nodes {
27+ requestedReviewer {
28+ ... on Team {
29+ name
30+ }
4431 }
4532 }
4633 }
47- }
48- labels(first: 5) {
49- nodes {
50- name
34+ labels(first: 5) {
35+ nodes {
36+ name
37+ }
5138 }
52- }
53- reviews(first: 10) {
54- nodes {
55- onBehalfOf(first: 1) {
56- nodes {
57- name
39+ reviews(first: 10) {
40+ nodes {
41+ onBehalfOf(first: 1) {
42+ nodes {
43+ name
44+ }
5845 }
5946 }
6047 }
61- }
62- author {
63- login
48+ author {
49+ login
50+ }
6451 }
6552 }
6653 }
6754 }
55+ ` ,
56+ {
57+ organization : process . env . ORGANIZATION ,
58+ repo : process . env . REPO ,
59+ headers : {
60+ authorization : `token ${ process . env . TOKEN } ` ,
61+ } ,
6862 }
69- ` ,
70- {
71- organization : process . env . ORGANIZATION ,
72- repo : process . env . REPO ,
73- projectNumber : parseInt ( process . env . PROJECT_NUMBER ) ,
74- num_prs : parseInt ( process . env . NUM_PRS ) ,
75- headers : {
76- authorization : `token ${ process . env . TOKEN } ` ,
77- 'GraphQL-Features' : 'projects_next_graphql' ,
78- } ,
79- }
80- )
63+ )
64+
65+ prsRemaining = data . repository . pullRequests . pageInfo . hasPreviousPage
66+ cursor = data . repository . pullRequests . pageInfo . startCursor
67+ prData = [ ...prData , ...data . repository . pullRequests . nodes ]
68+ }
69+
70+ return prData
71+ }
72+
73+ async function run ( ) {
74+ // Get info about open github/github PRs
75+ const prData = await getAllOpenPRs ( )
8176
8277 // Get the PRs that are:
8378 // - not draft
8479 // - not a train
8580 // - are requesting a review by docs-reviewers
8681 // - have not already been reviewed on behalf of docs-reviewers
87- const prs = data . repository . pullRequests . nodes . filter (
82+ const prs = prData . filter (
8883 ( pr ) =>
8984 ! pr . isDraft &&
9085 ! pr . labels . nodes . find ( ( label ) => label . name === 'Deploy train 🚂' ) &&
9186 pr . reviewRequests . nodes . find (
92- ( requestedReviewers ) => requestedReviewers . requestedReviewer . name === process . env . REVIEWER
87+ ( requestedReviewers ) => requestedReviewers . requestedReviewer ? .name === process . env . REVIEWER
9388 ) &&
9489 ! pr . reviews . nodes
9590 . flatMap ( ( review ) => review . onBehalfOf . nodes )
@@ -104,28 +99,60 @@ async function run() {
10499 const prAuthors = prs . map ( ( pr ) => pr . author . login )
105100 console . log ( `PRs found: ${ prIDs } ` )
106101
102+ // Get info about the docs-content review board project
103+ const projectData = await graphql (
104+ `
105+ query ($organization: String!, $projectNumber: Int!) {
106+ organization(login: $organization) {
107+ projectNext(number: $projectNumber) {
108+ id
109+ items(last: 100) {
110+ nodes {
111+ id
112+ }
113+ }
114+ fields(first: 100) {
115+ nodes {
116+ id
117+ name
118+ settings
119+ }
120+ }
121+ }
122+ }
123+ }
124+ ` ,
125+ {
126+ organization : process . env . ORGANIZATION ,
127+ projectNumber : parseInt ( process . env . PROJECT_NUMBER ) ,
128+ headers : {
129+ authorization : `token ${ process . env . TOKEN } ` ,
130+ } ,
131+ }
132+ )
133+
107134 // Get the project ID
108- const projectID = data . organization . projectNext . id
135+ const projectID = projectData . organization . projectNext . id
109136
110137 // Get the IDs of the last 100 items on the board.
111138 // Until we have a way to check from a PR whether the PR is in a project,
112139 // this is how we (roughly) avoid overwriting PRs that are already on the board.
113140 // If we are overwriting items, query for more items.
114- const existingItemIDs = data . organization . projectNext . items . nodes . map ( ( node ) => node . id )
141+ const existingItemIDs = projectData . organization . projectNext . items . nodes . map ( ( node ) => node . id )
115142
116143 // Get the ID of the fields that we want to populate
117- const datePostedID = findFieldID ( 'Date posted' , data )
118- const reviewDueDateID = findFieldID ( 'Review due date' , data )
119- const statusID = findFieldID ( 'Status' , data )
120- const featureID = findFieldID ( 'Feature' , data )
121- const contributorTypeID = findFieldID ( 'Contributor type' , data )
122- const sizeTypeID = findFieldID ( 'Size' , data )
123- const authorID = findFieldID ( 'Contributor' , data )
144+ const datePostedID = findFieldID ( 'Date posted' , projectData )
145+ const reviewDueDateID = findFieldID ( 'Review due date' , projectData )
146+ const statusID = findFieldID ( 'Status' , projectData )
147+ const featureID = findFieldID ( 'Feature' , projectData )
148+ const contributorTypeID = findFieldID ( 'Contributor type' , projectData )
149+ const sizeTypeID = findFieldID ( 'Size' , projectData )
150+ const authorID = findFieldID ( 'Contributor' , projectData )
124151
125152 // Get the ID of the single select values that we want to set
126- const readyForReviewID = findSingleSelectID ( 'Ready for review' , 'Status' , data )
127- const hubberTypeID = findSingleSelectID ( 'Hubber or partner' , 'Contributor type' , data )
128- const docsMemberTypeID = findSingleSelectID ( 'Docs team' , 'Contributor type' , data )
153+ const readyForReviewID = findSingleSelectID ( 'Ready for review' , 'Status' , projectData )
154+ const hubberTypeID = findSingleSelectID ( 'Hubber or partner' , 'Contributor type' , projectData )
155+ const docsMemberTypeID = findSingleSelectID ( 'Docs team' , 'Contributor type' , projectData )
129156
130157 // Add the PRs to the project
131158 const itemIDs = await addItemsToProject ( prIDs , projectID )
0 commit comments