Skip to content

Commit

Permalink
add support for GitLab.com to retrieve a codecheck.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
nuest committed Oct 10, 2022
1 parent 93be145 commit f932150
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 12 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: codecheck
Title: Helper Functions for CODECHECK Project
Version: 0.1.0.9002
Version: 0.1.0.9003
Authors@R:
c(person(given = "Stephen",
family = "Eglen",
Expand Down Expand Up @@ -28,7 +28,7 @@ Imports:
httr
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.0
RoxygenNote: 7.2.1
Remotes: eblondel/zen4R
VignetteBuilder: knitr
Suggests:
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ importFrom(R.cache,getCacheRootPath)
importFrom(gh,gh)
importFrom(httr,GET)
importFrom(httr,HEAD)
importFrom(httr,content)
importFrom(httr,status_code)
importFrom(knitr,kable)
importFrom(osfr,osf_download)
Expand All @@ -37,3 +38,4 @@ importFrom(utils,read.csv)
importFrom(utils,tail)
importFrom(xtable,xtable)
importFrom(yaml,read_yaml)
importFrom(yaml,yaml.load)
35 changes: 27 additions & 8 deletions R/configuration.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ get_codecheck_yml_uncached <- function(x) {

result <- switch (spec[["type"]],
"github" = get_codecheck_yml_github(spec[["repo"]]),
"osf" = get_codecheck_yml_osf(spec[["repo"]])
"osf" = get_codecheck_yml_osf(spec[["repo"]]),
"gitlab" = get_codecheck_yml_gitlab(spec[["repo"]])
)

return(result)
Expand Down Expand Up @@ -41,7 +42,7 @@ get_codecheck_yml_github <- function(x) {
config_file <- yaml::read_yaml(text = config_file_response$message)
return(config_file)
} else {
warning("codecheck.yml not found in list of repository files for ", x)
warning("codecheck.yml not found in repository ", x)
return(NULL)
}
}
Expand All @@ -63,7 +64,28 @@ get_codecheck_yml_osf <- function(x) {
file.remove(local_file)
return(config_file)
} else {
warning("codecheck.yml not found in list of repository files for https://osf.io/", x)
warning("codecheck.yml not found in repository https://osf.io/", x)
return(NULL)
}
}

#' Retrieve a codecheck.yml file from an GitLab.com project
#'
#' It seems https://statnmap.github.io/gitlabr/ always requires authentication
#'
#' @author Daniel Nüst
#' @param x the project name on GitLab.com
#' @importFrom httr GET content
#' @importFrom yaml yaml.load
get_codecheck_yml_gitlab <- function(x) {
response <- httr::GET(paste0("https://gitlab.com/", x, "/-/raw/main/codecheck.yml?inline=false"))

if (response$status == 200) {
content <- httr::content(response, as = "text", encoding = "UTF-8")
config_file <- yaml::yaml.load(content)
return(config_file)
} else {
warning("codecheck.yml not found in repository https://gitlab.com/", x)
return(NULL)
}
}
Expand All @@ -76,25 +98,22 @@ get_codecheck_yml_osf <- function(x) {
#'
#' - `osf::ABC12`
#' - `github::codecheckers/Piccolo-2020`
#' - `gitlab::cdchck/Piccolo-2020`
#'
#' @author Daniel Nüst
#' @param x the repository specification to parse
#' @return a named character vector with the items `type` and `repo`
parse_repository_spec <- function(x) {
pieces <- strsplit(x, "::", fixed = TRUE)[[1]]

#if (length(pieces) == 1) {
#type <- "github"
#repo <- paste0("codecheckers/", pieces)
#} else
if (length(pieces) == 2) {
type <- pieces[1]
repo <- pieces[2]
} else {
stop("Malformed repository specification '", x, "'")
}

if (! type %in% c("github", "osf")) {
if (! type %in% c("github", "osf", "gitlab")) {
stop("Unsupported repository type '", type, "'")
}

Expand Down
8 changes: 8 additions & 0 deletions R/register.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ register_render <- function(register = read.csv("register.csv", as.is = TRUE),
} else if (spec[["type"]] == "osf") {
urrl <- paste0("https://osf.io/", spec[["repo"]])
paste0("[", spec[["repo"]], "](", urrl, ")")
} else if (spec[["type"]] == "gitlab") {
urrl <- paste0("https://gitlab.com/", spec[["repo"]])
paste0("[", spec[["repo"]], "](", urrl, ")")
} else {
repository
}
Expand Down Expand Up @@ -130,6 +133,9 @@ register_render <- function(register = read.csv("register.csv", as.is = TRUE),
} else if (spec[["type"]] == "osf") {
urrl <- paste0("https://osf.io/", spec[["repo"]])
paste0("<i class='ai ai-osf'></i>&nbsp;[", spec[["repo"]], "](", urrl, ")")
} else if (spec[["type"]] == "gitlab") {
urrl <- paste0("https://gitlab.com/", spec[["repo"]])
paste0("<i class='fa fa-gitlab'></i>&nbsp;[", spec[["repo"]], "](", urrl, ")")
} else {
repository
}
Expand Down Expand Up @@ -183,6 +189,8 @@ register_render <- function(register = read.csv("register.csv", as.is = TRUE),
paste0("https://github.com/", spec[["repo"]])
} else if (spec[["type"]] == "osf") {
paste0("https://osf.io/", spec[["repo"]])
} else if (spec[["type"]] == "gitlab") {
paste0("https://gitlab.com/", spec[["repo"]])
} else {
repository
}
Expand Down
10 changes: 8 additions & 2 deletions inst/tinytest/test_codecheck_yml_retrieval.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ expect_error(get_codecheck_yml("github::not_org_and_repo"),
pattern = "Incomplete repo specification for type 'github'(.*)'not_org_and_repo'")

expect_warning(get_codecheck_yml("github::codecheckers/register"),
pattern = "codecheck.yml not found in(.*)codecheckers/register")
pattern = "codecheck.yml not found (.*)codecheckers/register")
expect_warning(get_codecheck_yml("osf::6K5FH"),
pattern = "codecheck.yml not found in(.*)https://osf.io/6K5FH")
pattern = "codecheck.yml not found (.*)https://osf.io/6K5FH")
expect_warning(get_codecheck_yml("gitlab::nuest/sensebox-binder"),
pattern = "codecheck.yml not found (.*)nuest/sensebox-binder")

# GitHub ----
expect_silent({ piccolo <- get_codecheck_yml("github::codecheckers/Piccolo-2020") })
Expand All @@ -18,3 +20,7 @@ expect_equal(piccolo$report, "http://doi.org/10.5281/zenodo.3674056")
# OSF ----
expect_silent({ agile <- get_codecheck_yml("osf::5SVMT") })
expect_equal(agile$report, "https://doi.org/10.17605/OSF.IO/5SVMT")

# GitLab.com ----
expect_silent({ gigabyte <- get_codecheck_yml("gitlab::cdchck/community-codechecks/2022-svaRetro-svaNUMT") })
expect_equal(gigabyte$report, "https://doi.org/10.5281/zenodo.7084333")
17 changes: 17 additions & 0 deletions man/get_codecheck_yml_gitlab.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/parse_repository_spec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f932150

Please sign in to comment.