@@ -326,74 +326,63 @@ Content <- R6::R6Class(
326326 )
327327 },
328328 # ' @description Get Git repository details
329- # ' @return a list of repo details, or NULL if no repo is set
329+ # ' @return NULL if no repo is set, otherwise a list with fields:
330+ # ' - repository
331+ # ' - branch
332+ # ' - directory
333+ # ' - polling
334+ # ' - last_error
335+ # ' - last_known_commit
330336 repository = function () {
331- GET <- self $ get_connect()$ GET
337+ con <- self $ get_connect()
332338 guid <- self $ get_content()$ guid
333- tryCatch(
334- # TODO: the v1 API returns 404 if no repo is set, so that means we fall
335- # back to the other API. The new API was added in October 2022, so maybe
336- # we just don't fall back.
337- GET(v1_url(" content" , guid , " repository" )),
338- error = function (e ) {
339- resp <- GET(unversioned_fallback_url(" applications" , guid ))$ git
340- if (! is.null(resp )) {
341- # NOTE: the v1 and v0 endpoints don't have identical fields
342- # Rename to match v1 naming
343- names(resp )[names(resp ) == " repository_url" ] <- " repository"
344- names(resp )[names(resp ) == " subdirectory" ] <- " directory"
345- names(resp )[names(resp ) == " enabled" ] <- " polling"
346- }
347- resp
348- }
339+ resp <- con $ GET(
340+ v1_url(" content" , guid , " repository" ),
341+ parser = NULL
349342 )
343+ if (httr :: status_code(resp ) == 404 ) {
344+ resp <- NULL
345+ } else {
346+ con $ raise_error(resp )
347+ resp <- httr :: content(resp , as = " parsed" )
348+ }
349+ resp
350350 },
351351 # ' @description Adjust Git polling.
352- # ' @param enabled Polling enabled.
353- repo_enable = function (enabled = TRUE ) {
352+ # ' @param polling Polling enabled.
353+ repo_enable = function (polling = TRUE ) {
354+ con <- self $ get_connect()
354355 guid <- self $ get_content()$ guid
355- tryCatch(
356- self $ get_connect()$ PATCH(
357- v1_url(" content" , guid , " repository" ),
358- body = list (
359- polling = enabled
360- )
361- ),
362- error = function (e ) {
363- self $ get_connect()$ PUT(
364- unversioned_fallback_url(" applications" , guid , " repo" ),
365- body = list (
366- enabled = enabled
367- )
368- )
369- }
356+ resp <- con $ PATCH(
357+ v1_url(" content" , guid , " repository" ),
358+ body = list (polling = polling )
370359 )
360+ if (httr :: status_code(resp ) == 404 ) {
361+ stop(" This content item is not git-backed" )
362+ }
363+ con $ raise_error(resp )
364+ httr :: content(resp , as = " parsed" )
371365 },
372366 # ' @description Adjust Git repository
373367 # ' @param repository Git repository URL
374368 # ' @param branch Git repository branch
375- # ' @param subdirectory Git repository directory
376- repo_set = function (repository , branch , subdirectory ) {
369+ # ' @param directory Git repository directory
370+ # ' @param polling Whether to check for updates
371+ repo_set = function (
372+ repository ,
373+ branch = " main" ,
374+ directory = " ." ,
375+ polling = FALSE
376+ ) {
377377 guid <- self $ get_content()$ guid
378- tryCatch(
379- self $ get_connect()$ PUT(
380- v1_url(" content" , guid , " repository" ),
381- body = list (
382- repository = repository ,
383- branch = branch ,
384- directory = subdirectory
385- )
386- ),
387- error = function (e ) {
388- self $ get_connect()$ POST(
389- unversioned_fallback_url(" applications" , guid , " repo" ),
390- body = list (
391- repository = repository ,
392- branch = branch ,
393- subdirectory = subdirectory
394- )
395- )
396- }
378+ self $ get_connect()$ PUT(
379+ v1_url(" content" , guid , " repository" ),
380+ body = list (
381+ repository = repository ,
382+ branch = branch ,
383+ directory = subdirectory ,
384+ polling = polling
385+ )
397386 )
398387 },
399388 # ' @description Get package dependencies
0 commit comments