Skip to content

Commit

Permalink
Merge pull request #87 from ropensci/I68
Browse files Browse the repository at this point in the history
I68 check URLs
  • Loading branch information
maelle authored Apr 12, 2018
2 parents bbe0e29 + 48ce1de commit 328260f
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 18 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ Imports:
desc,
usethis,
whisker,
tibble
tibble,
crul
Suggests:
testthat,
jsonvalidate,
covr,
knitr,
rmarkdown,
crul,
magrittr,
xml2,
dplyr (>= 0.7.0),
Expand Down
3 changes: 2 additions & 1 deletion R/codemeta_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ codemeta_description <-
descr$get("Title"))


## Enforce good practice
## Get URLs
code_repo <- descr$get_urls()
if (!is.na(code_repo[1])){

if(length(code_repo) == 1){
codemeta$codeRepository <- code_repo
}else{
Expand Down
16 changes: 14 additions & 2 deletions R/give_opinions.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,26 @@ give_opinions_desc <- function(descr_path){
if(is.na(descr$get("URL"))){
url_fixme <- "URL field. Indicate the URL to your code repository."
}else{
url_fixme <- NULL
checkurls <- check_urls(descr$get("URL"))
if(checkurls != ""){
url_fixme <- checkurls
}else{
url_fixme <- NULL
}

}

# BugReports
if(is.na(descr$get("BugReports"))){
bugreports_fixme <- "BugReports field. Indicate where to report bugs, e.g. GitHub issue tracker."
}else{
bugreports_fixme <- NULL
checkurls <- check_urls(descr$get("BugReports"))
if(checkurls != ""){
bugreports_fixme <- checkurls
}else{
bugreports_fixme <- NULL
}

}

fixmes <- c(authors_fixme, url_fixme, bugreports_fixme)
Expand Down
34 changes: 34 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,37 @@ find_template <- function(template_name, package = "usethis") {
}
path
}

get_url_status_code <- function(url){
if(!is.null(url)){
if(!is.na(url)){
result <- try(crul::HttpClient$new(url)$get(), silent = TRUE)
if (!inherits(result,'try-error')){
code <- result$status_code
if(code == 200){
message <- "All good"
}else{
message <- paste("Error code:", code)
}
}else{
message <- "No connection was possible"
}
return(data.frame(message = message, url = url))
}else{
return(NULL)
}
}else{
return(NULL)
}

}

check_urls <- function(urls){
messages <- do.call(rbind, lapply(urls, get_url_status_code))
if(any(messages$message != "All good")){
paste("Problematic URLs\n", apply(messages[messages$message != "All good",],
1, toString))
}else{
""
}
}
24 changes: 12 additions & 12 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,6 @@
"url": "https://cran.r-project.org"
}
},
{
"@type": "SoftwareApplication",
"identifier": "crul",
"name": "crul",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Central R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
}
},
{
"@type": "SoftwareApplication",
"identifier": "magrittr",
Expand Down Expand Up @@ -314,11 +303,22 @@
"name": "Central R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
}
},
{
"@type": "SoftwareApplication",
"identifier": "crul",
"name": "crul",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
"name": "Central R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
}
}
],
"contIntegration": "https://travis-ci.org/ropensci/codemetar",
"developmentStatus": "active",
"releaseNotes": "https://github.com/ropensci/codemetar/blob/master/NEWS.md",
"readme": "https://github.com/ropensci/codemetar/blob/master/README.md",
"fileSize": "270.002KB"
"fileSize": "270.648KB"
}
33 changes: 33 additions & 0 deletions inst/examples/DESCRIPTION_wrongURLS
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Package: jsonlite
Version: 1.5.9000
Title: A Robust, High Performance JSON Parser and Generator for R
License: MIT + file LICENSE
NeedsCompilation: yes
Depends:
methods
Author: Jeroen Ooms, Duncan Temple Lang, Lloyd Hilaiel
URL: https://httpbin.org/status/429,
https://www.opencpu.org/posts/jsonlite-a-smarter-json-encoder
BugReports: https://httpbin.org/status/404
Maintainer: Jeroen Ooms <[email protected]>
VignetteBuilder: knitr, R.rsp
Description: A fast JSON parser and generator optimized for statistical data
and the web. Started out as a fork of 'RJSONIO', but has been completely
rewritten in recent versions. The package offers flexible, robust, high
performance tools for working with JSON in R and is particularly powerful
for building pipelines and interacting with a web API. The implementation is
based on the mapping described in the vignette (Ooms, 2014). In addition to
converting JSON data from/to R objects, 'jsonlite' contains functions to
stream, validate, and prettify JSON data. The unit tests included with the
package verify that all edge cases are encoded and decoded consistently for
use with dynamic data in systems and applications.
Suggests:
httr,
curl,
plyr,
testthat,
knitr,
rmarkdown,
R.rsp,
sp
RoxygenNote: 6.0.1.9000
8 changes: 7 additions & 1 deletion tests/testthat/test-give_opinions.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ testthat::test_that("Message if no BugReports", {
f <- system.file("examples/DESCRIPTION_no_bugreports", package = "codemetar")
desc_fixmes <- give_opinions_desc(f)
expect_is(desc_fixmes, "data.frame")
expect_equal(desc_fixmes$where, "DESCRIPTION")
expect_equal(desc_fixmes$where[1], "DESCRIPTION")
expect_true(any(grepl("BugReports", desc_fixmes$fixme)))
})

testthat::test_that("No message if ok description",{
f <- system.file("examples/DESCRIPTION_Rforge", package = "codemetar")
expect_null(give_opinions_desc(f))
})

test_that("Message if bad URLS", {
f <- system.file("examples/DESCRIPTION_wrongURLS", package = "codemetar")
desc_fixmes <- give_opinions_desc(f)
expect_true(any(grepl("Problematic URLs", desc_fixmes$fixme)))
})

0 comments on commit 328260f

Please sign in to comment.