Send to github via curl command line (Windows)

后端 未结 1 1028
囚心锁ツ
囚心锁ツ 2020-12-10 18:20

I asked a related question and realized I wasn\'t asking the right question (i.e., this isn\'t about git).

The question is how to push a project to github without fi

相关标签:
1条回答
  • 2020-12-10 18:59

    EDIT - After OP offered bounty

    Ok, it turns out it is to do with some crazy windows character escaping on the command line. Essentially the problem was we were passing improperly formatted json requests to github.

    You can use shQuote to properly format the offending portion of the curl request for Windows. We can test platform type to see if we need to include special formatting for Windows cases like so:

    repo <- "NewRepository"
    json <- paste0(" { \"name\":\"" , repo , "\" } ") #string we desire formatting
    os <- .Platform$OS.type #check if we are on Windows
    if( os == "windows" ){
    json <- shQuote(json , type = "cmd" )
    cmd1 <- paste0( tempdir() ,"/curl -i -u \"" , user , ":" , password , "\" https://api.github.com/user/repos -d " , json )
    }
    

    This worked on my Windows 7 box without any problems. I can update the GitHub script if you want?

    OLD ANSWER

    I did some digging around here and here and it might be that the answer to your problem is to update the curl-ca-bundle. It may help on Windows to get R to use the internet2.dll.

    repo <- "New"
    user <- "trinker"
    password <- "password"
    
    url <- "http://curl.askapache.com/download/curl-7.23.1-win64-ssl-sspi.zip"
    tmp <- tempfile( fileext = ".zip" )
    download.file(url,tmp)
    unzip(tmp, exdir = tempdir())
    system( paste0( "curl http://curl.haxx.se/ca/cacert.pem -o " , tempdir() , "/curl-ca-bundle.crt" ) )
    system( paste0( tempdir(),"/curl", " -u \'USER:PASS\' https://api.github.com/user/repos -d \'{\"name\":\"REPO\"}\'") )
    

    Again, I can't test this as I don't have access to my Windows box, but updating the certificate authority file seems to have helped a few other people. From the curl website, the Windows version of curl should look for the curl-ca-bundle.crt file in the following order:

    1. application's directory
    2. current working directory
    3. Windows System directory (e.g. C:\windows\system32)
    4. Windows Directory (e.g. C:\windows)
    5. all directories along %PATH%
    0 讨论(0)
提交回复
热议问题