1313# ' @param email An alternative email address to use. If `NULL`, the default is
1414# ' to use the package maintainer's email.
1515# ' @param quiet If `TRUE`, suppresses output.
16+ # ' @param webform If `TRUE`, uses web form instead of passive FTP upload.
1617# ' @param ... Additional arguments passed to [pkgbuild::build()].
1718# ' @family build functions
1819# ' @name check_win
1920NULL
2021
2122# ' @describeIn check_win Check package on the development version of R.
2223# ' @export
23- check_win_devel <- function (pkg = " ." , args = NULL , manual = TRUE , email = NULL , quiet = FALSE , ... ) {
24+ check_win_devel <- function (pkg = " ." , args = NULL , manual = TRUE , email = NULL , quiet = FALSE , webform = FALSE , ... ) {
2425 check_dots_used(action = getOption(" devtools.ellipsis_action" , rlang :: warn ))
2526
2627 check_win(
2728 pkg = pkg , version = " R-devel" , args = args , manual = manual ,
28- email = email , quiet = quiet , ...
29+ email = email , quiet = quiet , webform = webform , ...
2930 )
3031}
3132
3233# ' @describeIn check_win Check package on the released version of R.
3334# ' @export
34- check_win_release <- function (pkg = " ." , args = NULL , manual = TRUE , email = NULL , quiet = FALSE , ... ) {
35+ check_win_release <- function (pkg = " ." , args = NULL , manual = TRUE , email = NULL , quiet = FALSE , webform = FALSE , ... ) {
3536 check_dots_used(action = getOption(" devtools.ellipsis_action" , rlang :: warn ))
3637
3738 check_win(
3839 pkg = pkg , version = " R-release" , args = args , manual = manual ,
39- email = email , quiet = quiet , ...
40+ email = email , quiet = quiet , webform = webform , ...
4041 )
4142}
4243
4344# ' @describeIn check_win Check package on the previous major release version of R.
4445# ' @export
45- check_win_oldrelease <- function (pkg = " ." , args = NULL , manual = TRUE , email = NULL , quiet = FALSE , ... ) {
46+ check_win_oldrelease <- function (pkg = " ." , args = NULL , manual = TRUE , email = NULL , quiet = FALSE , webform = FALSE , ... ) {
4647 check_dots_used(action = getOption(" devtools.ellipsis_action" , rlang :: warn ))
4748
4849 check_win(
4950 pkg = pkg , version = " R-oldrelease" , args = args , manual = manual ,
50- email = email , quiet = quiet , ...
51+ email = email , quiet = quiet , webform = webform , ...
5152 )
5253}
5354
5455check_win <- function (pkg = " ." , version = c(" R-devel" , " R-release" , " R-oldrelease" ),
55- args = NULL , manual = TRUE , email = NULL , quiet = FALSE , ... ) {
56+ args = NULL , manual = TRUE , email = NULL , quiet = FALSE ,
57+ webform = FALSE , ... ) {
5658 pkg <- as.package(pkg )
5759
5860 if (! is.null(email )) {
@@ -81,16 +83,16 @@ check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelea
8183 }
8284
8385 built_path <- pkgbuild :: build(pkg $ path , tempdir(),
84- args = args ,
85- manual = manual , quiet = quiet , ...
86+ args = args ,
87+ manual = manual , quiet = quiet , ...
8688 )
8789 on.exit(file_delete(built_path ), add = TRUE )
8890
89- url <- paste0(
90- " ftp://win-builder.r-project.org/ " , version , " / " ,
91- path_file( built_path )
92- )
93- lapply( url , upload_ftp , file = built_path )
91+ if ( webform ) {
92+ submit_winbuilder_webform( built_path , version )
93+ } else {
94+ submit_winbuilder_ftp( built_path , version )
95+ }
9496
9597 if (! quiet ) {
9698 time <- strftime(Sys.time() + 30 * 60 , " %I:%M %p" )
@@ -105,6 +107,15 @@ check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelea
105107 invisible ()
106108}
107109
110+ submit_winbuilder_ftp <- function (path , version ) {
111+ url <- paste0(" ftp://win-builder.r-project.org/" , version , " /" , path_file(path ))
112+ lapply(url , upload_ftp , file = path )
113+ }
114+
115+ submit_winbuilder_webform <- function (path , version ) {
116+ lapply(version , upload_webform , file = path )
117+ }
118+
108119change_maintainer_email <- function (path , email , call = parent.frame()) {
109120 desc <- desc :: desc(file = path )
110121
@@ -147,3 +158,44 @@ upload_ftp <- function(file, url, verbose = FALSE) {
147158 }, verbose = verbose )
148159 curl :: curl_fetch_memory(url , handle = h )
149160}
161+
162+ extract_hidden_fields <- function (html_text ) {
163+ extract_value <- function (name ) {
164+ pattern <- sprintf(' name="%s"[^>]*value="([^"]+)"' , name )
165+ match <- regexec(pattern , html_text )
166+ result <- regmatches(html_text , match )
167+ if (length(result [[1 ]]) > = 2 ) result [[1 ]][2 ] else NA_character_
168+ }
169+
170+ list (
171+ `__VIEWSTATE` = extract_value(" __VIEWSTATE" ),
172+ `__VIEWSTATEGENERATOR` = extract_value(" __VIEWSTATEGENERATOR" ),
173+ `__EVENTVALIDATION` = extract_value(" __EVENTVALIDATION" )
174+ )
175+ }
176+
177+ upload_webform <- function (file , version ) {
178+
179+ upload_url <- " https://win-builder.r-project.org/upload.aspx"
180+ form_page <- httr :: GET(upload_url )
181+ html_text <- httr :: content(form_page , as = " text" )
182+
183+ field_map <- list (
184+ " R-release" = list (file = " FileUpload1" , button = " Button1" ),
185+ " R-devel" = list (file = " FileUpload2" , button = " Button2" ),
186+ " R-oldrelease" = list (file = " FileUpload3" , button = " Button3" )
187+ )
188+
189+ fields <- field_map [[version ]]
190+
191+ body <- extract_hidden_fields(html_text )
192+ body [[fields $ file ]] <- httr :: upload_file(file )
193+ body [[fields $ button ]] <- " Upload File"
194+
195+ r <- httr :: POST(
196+ url = upload_url ,
197+ body = body ,
198+ encode = " multipart"
199+ )
200+ httr :: stop_for_status(r )
201+ }
0 commit comments