@@ -198,7 +198,7 @@ gh_user_commit_cmt_qry <- function (login = "",
198
198
}
199
199
createdAt
200
200
repository {
201
- url
201
+ nameWithOwner
202
202
stargazerCount
203
203
}
204
204
url
@@ -238,7 +238,7 @@ gh_user_commit_cmt_internal <- function (login,
238
238
)
239
239
repourl <- c (
240
240
repourl ,
241
- vapply (nodes , function (i ) i $ repository $ url , character (1L ))
241
+ vapply (nodes , function (i ) i $ repository $ nameWithOwner , character (1L ))
242
242
)
243
243
repo_stargazers <- c (
244
244
repo_stargazers ,
@@ -252,7 +252,6 @@ gh_user_commit_cmt_internal <- function (login,
252
252
}
253
253
}
254
254
255
- repourl <- gsub (" https://github.com/" , " " , repourl , fixed = TRUE )
256
255
repourl <- strsplit (repourl , " \\ /" )
257
256
org <- vapply (repourl , function (i ) i [1 ], character (1L ))
258
257
repo <- vapply (repourl , function (i ) i [2 ], character (1L ))
@@ -273,7 +272,8 @@ gh_user_commit_cmt <- memoise::memoise (gh_user_commit_cmt_internal)
273
272
gh_user_commits_qry <- function (login = " " ,
274
273
ended_at = Sys.time (),
275
274
nyears = 1 ,
276
- n_per_page = 100L ) {
275
+ n_per_page = 100L ,
276
+ end_cursor = NULL ) {
277
277
278
278
# GraphQL API here has restriction:
279
279
# "The total time spanned by 'from' and 'to' must not exceed 1 year"
@@ -282,22 +282,30 @@ gh_user_commits_qry <- function (login = "",
282
282
from <- format (ended_at - 60 * 60 * 24 * 365 * nyears , " %Y-%m-%dT%H:%M:%S" )
283
283
ended_at <- format (ended_at , " %Y-%m-%dT%H:%M:%S" )
284
284
285
+ after_txt <- " "
286
+ if (! is.null (end_cursor )) {
287
+ after_txt <- paste0 (" , after:\" " , end_cursor , " \" " )
288
+ }
289
+
285
290
q <- paste0 (" {
286
291
user(login:\" " , login , " \" ) {
287
292
login
288
293
contributionsCollection (from: \" " , from , " \" , to: \" " , ended_at , " \" ) {
289
294
startedAt
290
295
endedAt
296
+ totalCommitContributions
291
297
commitContributionsByRepository (maxRepositories: " , n_per_page , " ) {
292
- contributions (first: 1 ) {
298
+ contributions (first: " , n_per_page , after_txt , " ) {
293
299
pageInfo {
294
300
hasNextPage
295
301
endCursor
296
302
}
297
303
totalCount
298
304
nodes {
305
+ occurredAt
306
+ commitCount
299
307
repository {
300
- url
308
+ nameWithOwner
301
309
}
302
310
}
303
311
}
@@ -314,30 +322,80 @@ gh_user_commits_internal <- function (login,
314
322
nyears = 1 ,
315
323
n_per_page = 100L ) {
316
324
317
- q <- gh_user_commits_qry (
318
- login = login ,
319
- ended_at = ended_at ,
320
- nyears = nyears ,
321
- n_per_page = n_per_page
322
- )
323
- dat <- gh :: gh_gql (query = q )
325
+ is_test_env <- Sys.getenv (" REPOMETRICS_TESTS" ) == " true"
326
+ n_per_page <- n_per_page_in_tests (n_per_page )
324
327
325
- started_at <- dat $ data $ user $ contributionsCollection $ startedAt
326
- ended_at <- dat $ data $ user $ contributionsCollection $ endedAt
328
+ repos <- num_commits <- dates <- end_cursor <- end_cursors <- NULL
327
329
328
- commits <- dat $ data $ user $ contributionsCollection $ commitContributionsByRepository
330
+ has_next_page <- TRUE
329
331
330
- repos <- vapply (
331
- commits ,
332
- function (i ) i $ contributions $ nodes [[1 ]]$ repository $ url ,
333
- character (1L )
334
- )
335
- num_commits <- vapply (commits , function (i ) i $ contributions $ totalCount , integer (1L ))
332
+ while (has_next_page ) {
333
+
334
+ q <- gh_user_commits_qry (
335
+ login = login ,
336
+ ended_at = ended_at ,
337
+ nyears = nyears ,
338
+ n_per_page = n_per_page ,
339
+ end_cursor = end_cursor
340
+ )
341
+ dat <- gh :: gh_gql (query = q )
342
+
343
+ collection <- dat $ data $ user $ contributionsCollection
344
+ commits <- collection $ commitContributionsByRepository
345
+
346
+ # Query always returns `n_per_page` items, even when empty, so empty
347
+ # ones must first be removed:
348
+ lens <- vapply (
349
+ commits ,
350
+ function (i ) length (i $ contributions $ nodes ),
351
+ integer (1L )
352
+ )
353
+ commits <- commits [which (lens > 0 )]
336
354
355
+ repos_i <- vapply (
356
+ commits ,
357
+ function (i ) i $ contributions $ nodes [[1 ]]$ repository $ nameWithOwner ,
358
+ character (1L )
359
+ )
360
+
361
+ dates_i <- lapply (commits , function (i ) {
362
+ vapply (i $ contributions $ nodes , function (j ) j $ occurredAt , character (1L ))
363
+ })
364
+ n_i <- vapply (dates_i , length , integer (1L ))
365
+ dates <- c (dates , unlist (dates_i ))
366
+ commit_count_i <- lapply (commits , function (i ) {
367
+ vapply (i $ contributions $ nodes , function (j ) j $ commitCount , integer (1L ))
368
+ })
369
+ num_commits <- c (num_commits , unlist (commit_count_i ))
370
+
371
+ repos <- c (repos , rep (repos_i , times = n_i ))
372
+
373
+ has_next_pages <- vapply (commits , function (i ) {
374
+ i $ contributions $ pageInfo $ hasNextPage
375
+ }, logical (1L ))
376
+ end_cursors_these <- vapply (commits , function (i ) {
377
+ i $ contributions $ pageInfo $ endCursor
378
+ }, character (1L ))
379
+ end_cursors_these <- unique (end_cursors_these [which (has_next_pages )])
380
+ end_cursors <- c (end_cursors , end_cursors_these )
381
+ has_next_page <- length (end_cursors ) > 0L && ! is_test_env
382
+ if (has_next_page ) {
383
+ end_cursor <- end_cursors [1L ]
384
+ end_cursors <- end_cursors [- 1L ]
385
+ }
386
+ }
387
+
388
+ started_at <- dat $ data $ user $ contributionsCollection $ startedAt
389
+ ended_at <- dat $ data $ user $ contributionsCollection $ endedAt
390
+
391
+ # suppress no visible binding note:
392
+ repo <- date <- NULL
337
393
res <- data.frame (
338
- repo = gsub (" https://github.com/" , " " , repos , fixed = TRUE ),
339
- num_commits = num_commits
340
- )
394
+ repo = repos ,
395
+ num_commits = num_commits ,
396
+ date = dates
397
+ ) | >
398
+ dplyr :: arrange (repo , date )
341
399
attr (res , " started_at" ) <- started_at
342
400
attr (res , " ended_at" ) <- ended_at
343
401
0 commit comments