28
28
# ' download_organization_repos(c("maelle-test", "maelle-test"))
29
29
# ' download_organization_repos("maelle-test", keep = "testy2") # only keep the testy2 repo
30
30
# ' }
31
- download_organization_repos <- function (organizations = NULL ,
32
- extra_repos = NULL ,
33
- keep = character (0 ),
34
- dest_folder = getwd()) {
35
-
31
+ download_organization_repos <- function (
32
+ organizations = NULL ,
33
+ extra_repos = NULL ,
34
+ keep = character (0 ),
35
+ dest_folder = getwd()
36
+ ) {
36
37
user_types <- check_users(organizations )
37
38
38
39
if (! dir.exists(dest_folder )) dir.create(dest_folder )
@@ -47,12 +48,20 @@ download_organization_repos <- function(organizations = NULL,
47
48
)
48
49
}
49
50
50
- repos <- purrr :: map2(organizations , user_types , launch_org_migrations , keep = keep , extra_repos = extra_repos ) | >
51
+ repos <- purrr :: map2(
52
+ organizations ,
53
+ user_types ,
54
+ launch_org_migrations ,
55
+ keep = keep ,
56
+ extra_repos = extra_repos
57
+ ) | >
51
58
unlist(recursive = FALSE )
52
59
53
60
repo_names <- purrr :: map_chr(repos , function (x ) x $ name )
54
61
55
- message(" Waiting one minute for things to kick off properly before downloads..." )
62
+ message(
63
+ " Waiting one minute for things to kick off properly before downloads..."
64
+ )
56
65
Sys.sleep(60 )
57
66
58
67
start_time <- Sys.time()
@@ -71,11 +80,15 @@ download_organization_repos <- function(organizations = NULL,
71
80
ready_repos <- repos [status == " exported" ]
72
81
purrr :: walk(ready_repos , function (repo ) repo $ launch_download())
73
82
repos <- repos [status != " exported" ]
74
- if (length(repos ) > 0 ) message(sprintf(" Still not saved: %s." , toString(purrr :: map_chr(repos , ~ .x [[" name" ]]))))
83
+ if (length(repos ) > 0 )
84
+ message(sprintf(
85
+ " Still not saved: %s." ,
86
+ toString(purrr :: map_chr(repos , ~ .x [[" name" ]]))
87
+ ))
75
88
}
76
89
77
90
if (length(repos ) > 0 ) {
78
- leftover <- toString(purrr :: map_chr(repos , ~ .x [[" name" ]]))
91
+ leftover <- toString(purrr :: map_chr(repos , ~ .x [[" name" ]]))
79
92
message(sprintf(" Left-over: %s." , leftover ))
80
93
} else {
81
94
leftover <- NULL
@@ -87,7 +100,12 @@ download_organization_repos <- function(organizations = NULL,
87
100
)
88
101
}
89
102
90
- launch_org_migrations <- function (username , user_type , extra_repos , keep = character (0 )) {
103
+ launch_org_migrations <- function (
104
+ username ,
105
+ user_type ,
106
+ extra_repos ,
107
+ keep = character (0 )
108
+ ) {
91
109
repo_names <- if (user_type == " organization" ) {
92
110
gh :: gh(
93
111
" /orgs/{org}/repos" ,
@@ -105,7 +123,9 @@ launch_org_migrations <- function(username, user_type, extra_repos, keep = chara
105
123
per_page = 100 ,
106
124
.limit = Inf
107
125
) | >
108
- purrr :: keep(\(x ) startsWith(x [[" full_name" ]], sprintf(" %s/" , username ))) | >
126
+ purrr :: keep(
127
+ \(x ) startsWith(x [[" full_name" ]], sprintf(" %s/" , username ))
128
+ ) | >
109
129
purrr :: map_chr(" name" )
110
130
}
111
131
@@ -125,12 +145,29 @@ launch_org_migrations <- function(username, user_type, extra_repos, keep = chara
125
145
}
126
146
127
147
message(sprintf(" Launching archive creation for username %s" , username ))
128
- purrr :: map(repo_names , repo $ new , organization = username , user_type = user_type )
129
-
148
+ purrr :: map(
149
+ repo_names ,
150
+ repo $ new ,
151
+ organization = username ,
152
+ user_type = user_type
153
+ )
130
154
}
131
155
132
- check_user <- function (username ) {
156
+ check_user <- function (username , call = rlang :: caller_env() ) {
133
157
info <- gh :: gh(" /users/{user}" , user = username )
158
+
159
+ # check the case was correct
160
+ # https://github.com/ropensci-org/gitcellar/issues/25
161
+ if (info [[" login" ]] != username ) {
162
+ cli :: cli_abort(
163
+ c(
164
+ x = ' {.arg username} {.val {username}} not equal to actual user name {.val {info[["login"]]}}' ,
165
+ i = " Please fix the case"
166
+ ),
167
+ call = call
168
+ )
169
+ }
170
+
134
171
tolower(info [[" type" ]])
135
172
}
136
173
0 commit comments