30
30
using static Octokit . GraphQL . Variable ;
31
31
using CheckConclusionState = GitHub . Models . CheckConclusionState ;
32
32
using CheckStatusState = GitHub . Models . CheckStatusState ;
33
+ using PullRequestState = GitHub . Models . PullRequestState ;
33
34
using StatusState = GitHub . Models . StatusState ;
34
35
35
36
namespace GitHub . Services
@@ -84,15 +85,15 @@ public PullRequestService(
84
85
this . tempFileMappings = new Dictionary < string , ( string commitId , string repoPath ) > ( StringComparer . OrdinalIgnoreCase ) ;
85
86
}
86
87
87
- public async Task < Page < PullRequestListItemModel > > ReadPullRequests (
88
- HostAddress address ,
88
+ public async Task < Page < PullRequestListItemModel > > ReadPullRequests ( HostAddress address ,
89
89
string owner ,
90
90
string name ,
91
91
string after ,
92
- Models . PullRequestState [ ] states )
92
+ PullRequestState [ ] states , string author )
93
93
{
94
-
94
+ string filter = null ;
95
95
ICompiledQuery < Page < PullRequestListItemModel > > query ;
96
+ ICompiledQuery < Page < PullRequestListItemModel > > query2 ;
96
97
97
98
if ( address . IsGitHubDotCom ( ) )
98
99
{
@@ -154,6 +155,56 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
154
155
}
155
156
156
157
query = readPullRequests ;
158
+
159
+ query2 = new Query ( ) . Search ( Var ( nameof ( filter ) ) , first : 100 , after : Var ( nameof ( after ) ) , type : SearchType . Issue )
160
+ . Select ( page => new Page < PullRequestListItemModel >
161
+ {
162
+ EndCursor = page . PageInfo . EndCursor ,
163
+ HasNextPage = page . PageInfo . HasNextPage ,
164
+ TotalCount = page . IssueCount ,
165
+ Items = page . Nodes . Select ( issueOrPr => issueOrPr
166
+ . Switch < PullRequestListItemModel > ( when => when . PullRequest ( pr => new ListItemAdapter
167
+ {
168
+ Id = pr . Id . Value ,
169
+ LastCommit = pr . Commits ( null , null , 1 , null ) . Nodes . Select ( commit =>
170
+ new LastCommitSummaryAdapter
171
+ {
172
+ CheckSuites = commit . Commit . CheckSuites ( null , null , null , null , null ) . AllPages ( 10 )
173
+ . Select ( suite => new CheckSuiteSummaryModel
174
+ {
175
+ CheckRuns = suite . CheckRuns ( null , null , null , null , null ) . AllPages ( 10 )
176
+ . Select ( run => new CheckRunSummaryModel
177
+ {
178
+ Conclusion = run . Conclusion . FromGraphQl ( ) ,
179
+ Status = run . Status . FromGraphQl ( )
180
+ } ) . ToList ( ) ,
181
+ } ) . ToList ( ) ,
182
+ Statuses = commit . Commit . Status
183
+ . Select ( context =>
184
+ context . Contexts . Select ( statusContext => new StatusSummaryModel
185
+ {
186
+ State = statusContext . State . FromGraphQl ( ) ,
187
+ } ) . ToList ( )
188
+ ) . SingleOrDefault ( )
189
+ } ) . ToList ( ) . FirstOrDefault ( ) ,
190
+ Author = new ActorModel
191
+ {
192
+ Login = pr . Author . Login ,
193
+ AvatarUrl = pr . Author . AvatarUrl ( null ) ,
194
+ } ,
195
+ CommentCount = pr . Comments ( 0 , null , null , null ) . TotalCount ,
196
+ Number = pr . Number ,
197
+ Reviews = pr . Reviews ( null , null , null , null , null , null ) . AllPages ( ) . Select ( review => new ReviewAdapter
198
+ {
199
+ Body = review . Body ,
200
+ CommentCount = review . Comments ( null , null , null , null ) . TotalCount ,
201
+ } ) . ToList ( ) ,
202
+ State = pr . State . FromGraphQl ( ) ,
203
+ Title = pr . Title ,
204
+ UpdatedAt = pr . UpdatedAt ,
205
+ } ) ) ) . ToList ( )
206
+ } )
207
+ . Compile ( ) ;
157
208
}
158
209
else
159
210
{
@@ -207,6 +258,48 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
207
258
}
208
259
209
260
query = readPullRequestsEnterprise ;
261
+
262
+ query2 = new Query ( ) . Search ( Var ( nameof ( filter ) ) , first : 100 , after : Var ( nameof ( after ) ) , type : SearchType . Issue )
263
+ . Select ( page => new Page < PullRequestListItemModel >
264
+ {
265
+ EndCursor = page . PageInfo . EndCursor ,
266
+ HasNextPage = page . PageInfo . HasNextPage ,
267
+ TotalCount = page . IssueCount ,
268
+ Items = page . Nodes . Select ( issueOrPr => issueOrPr
269
+ . Switch < PullRequestListItemModel > ( when => when . PullRequest ( pr => new ListItemAdapter
270
+ {
271
+ Id = pr . Id . Value ,
272
+ LastCommit = pr . Commits ( null , null , 1 , null ) . Nodes . Select ( commit =>
273
+ new LastCommitSummaryAdapter
274
+ {
275
+ Statuses = commit . Commit . Status . Select ( context =>
276
+ context == null
277
+ ? null
278
+ : context . Contexts
279
+ . Select ( statusContext => new StatusSummaryModel
280
+ {
281
+ State = statusContext . State . FromGraphQl ( )
282
+ } ) . ToList ( )
283
+ ) . SingleOrDefault ( )
284
+ } ) . ToList ( ) . FirstOrDefault ( ) ,
285
+ Author = new ActorModel
286
+ {
287
+ Login = pr . Author . Login ,
288
+ AvatarUrl = pr . Author . AvatarUrl ( null ) ,
289
+ } ,
290
+ CommentCount = pr . Comments ( 0 , null , null , null ) . TotalCount ,
291
+ Number = pr . Number ,
292
+ Reviews = pr . Reviews ( null , null , null , null , null , null ) . AllPages ( ) . Select ( review => new ReviewAdapter
293
+ {
294
+ Body = review . Body ,
295
+ CommentCount = review . Comments ( null , null , null , null ) . TotalCount ,
296
+ } ) . ToList ( ) ,
297
+ State = pr . State . FromGraphQl ( ) ,
298
+ Title = pr . Title ,
299
+ UpdatedAt = pr . UpdatedAt ,
300
+ } ) ) ) . ToList ( )
301
+ } )
302
+ . Compile ( ) ;
210
303
}
211
304
212
305
var graphql = await graphqlFactory . CreateConnection ( address ) ;
@@ -220,6 +313,35 @@ public async Task<Page<PullRequestListItemModel>> ReadPullRequests(
220
313
221
314
var result = await graphql . Run ( query , vars ) ;
222
315
316
+ filter = $ "type:pr repo:{ owner } /{ name } ";
317
+ if ( states . Any ( ) )
318
+ {
319
+ var filterState = states . First ( ) ;
320
+ switch ( filterState )
321
+ {
322
+ case PullRequestState . Open :
323
+ filter += " is:open" ;
324
+ break ;
325
+ case PullRequestState . Closed :
326
+ filter += " is:unmerged is:closed" ;
327
+ break ;
328
+ case PullRequestState . Merged :
329
+ filter += " is:merged is:closed" ;
330
+ break ;
331
+
332
+ default :
333
+ throw new ArgumentOutOfRangeException ( nameof ( filterState ) ) ;
334
+ }
335
+ }
336
+
337
+ var vars2 = new Dictionary < string , object >
338
+ {
339
+ { nameof ( filter ) , filter } ,
340
+ { nameof ( after ) , after } ,
341
+ } ;
342
+
343
+ var result2 = await graphql . Run ( query2 , vars2 ) ;
344
+
223
345
foreach ( var item in result . Items . Cast < ListItemAdapter > ( ) )
224
346
{
225
347
item . CommentCount += item . Reviews . Sum ( x => x . Count ) ;
0 commit comments