Skip to content

Commit

Permalink
Clean the package
Browse files Browse the repository at this point in the history
  • Loading branch information
hsonne committed Apr 29, 2024
1 parent 2363e4b commit 5a9b060
Show file tree
Hide file tree
Showing 28 changed files with 746 additions and 439 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ ByteCompile: true
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1
RoxygenNote: 7.3.1
26 changes: 16 additions & 10 deletions R/badge_codecov.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#' badge_codecov
#'
#' @param repo_full_names vector with combination of username/repo (e.g.
#' c("KWB-R/kwb.utils", "KWB-R/kwb.db"))
#' @return codecov badges for provided repo_full_names
#' @export

badge_codecov <- function(repo_full_names) {
paste0("[![codecov](https://codecov.io/github/",
repo_full_names,
"/branch/master/graphs/badge.svg)](https://codecov.io/github/",
repo_full_names,
")")

badge_codecov <- function(repo_full_names)
{
to_full_url <- function(path_pattern) {
compose_url(
protocol = "https",
domain_name = "codecov.io",
path = sprintf(path_pattern, repo_full_names)
)
}

image_link(
image_name = "codecov",
image_url = to_full_url("github/%s/branch/master/graphs/badge.svg"),
link_url = to_full_url("github/%s")
)
}



27 changes: 17 additions & 10 deletions R/badge_cran.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
#' badge_cran
#'
#' @param repo_names vector of repository names (e.g. c("kwb.utils", "kwb.db"))
#' @return crank badges for provided repo_names
#' @export
badge_cran <- function(repo_names) {
paste0("[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/",
repo_names,
")](http://www.r-pkg.org/pkg/",
repo_names,
")")
badge_cran <- function(repo_names)
{
to_full_url <- function(path) {
compose_url(
protocol = "http",
subdomain = "www",
domain_name = "r-pkg.org",
path = paste0(path, "/", repo_names)
)
}

image_link(
image_name = "CRAN_Status_Badge",
image_url = to_full_url("badges/version"),
link_url = to_full_url("pkg")
)
}




25 changes: 17 additions & 8 deletions R/badge_dependencies.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#' badge_dependencies
#'
#' @param repo_names vector of repository names (e.g. c("kwb.utils", "kwb.db"))
#' @return dependency badges for provided repo_names
#' @export
badge_dependencies <- function(repo_names) {
paste0("[![Dependencies_badge](https://kwb-githubdeps.netlify.app/badge/",
repo_names,
")](https://kwb-githubdeps.netlify.app)")
badge_dependencies <- function(repo_names)
{
to_full_url <- function(path = "") {
compose_url(
protocol = "https",
subdomain = "kwb-githubdeps",
domain_name = "netlify.app",
path = path
)
}

image_link(
image_name = "Dependencies_badge",
image_url = to_full_url(paste0("badge/", repo_names)),
link_url = to_full_url()
)
}




27 changes: 16 additions & 11 deletions R/badge_gitlab.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#' badge_gitlab
#'
#' @param url url to repository on Gitlab
#' @param logo_path path to Gitlab logo (default:
#' "https://gitlab.com/gitlab-com/gitlab-artwork/raw/master/logo/logo-square.png")
#' @param size size of logo in pixels (default: 24)
#' @return Gitlab logo in html with path to repository in Gitlab
#' @export

badge_gitlab <- function(url,
logo_path = paste0("https://gitlab.com/gitlab-com/gitlab-artwork/raw/",
"master/logo/logo-square.png"),
size = 24) {
badge_gitlab <- function(
url,
logo_path = compose_url(
protocol = "https",
domain_name = "gitlab.com",
path = "gitlab-com/gitlab-artwork/raw/master/logo/logo-square.png"
),
size = 24
)
{
img_attr <- sprintf(" title='Gitlab' width='%d' height = '%d'", size, size)

sprintf("<a href='%s'><img src='%s' title='Gitlab' width='%d' height = '%d'/></a>",
url,
logo_path,
size,
size)
}
logo_path %>%
html_img(img_attr) %>%
html_a(href = url)
}
72 changes: 19 additions & 53 deletions R/badge_license.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,35 @@
#' @importFrom dplyr left_join select_ rename_
#' @return badge for all provided license keys
#' @export
badge_license <- function(license_keys,
github_token = Sys.getenv("GITHUB_TOKEN")) {
gh_licenses <- gh::gh(endpoint = "GET /licenses",
.token = github_token)
badge_license <- function(license_keys, github_token = get_github_token())
{
gh_licenses <- gh::gh(endpoint = "GET /licenses", .token = github_token)

gh_licenses_df <- data.table::rbindlist(gh_licenses, fill=TRUE)


#### License badges from: https://gist.github.com/lukas-h/2a5d00690736b4c3a7ba
license_badges <- data.frame(key = c("agpl-3.0",
"apache-2.0",
"bsd-2-clause",
"bsd-3-clause",
"epl-2.0",
"gpl-2.0",
"gpl-3.0",
"lgpl-2.1",
"lgpl-3.0",
"mit",
"mpl-2.0",
"unlicense"),
badge_url = c("https://img.shields.io/badge/License-AGPL%20v3-blue.svg",
"https://img.shields.io/badge/License-Apache%202.0-blue.svg",
"https://img.shields.io/badge/License-BSD%202--Clause-orange.svg",
"https://img.shields.io/badge/License-BSD%203--Clause-blue.svg",
"",
"https://img.shields.io/badge/License-GPL%20v2-blue.svg",
"https://img.shields.io/badge/License-GPL%20v3-blue.svg",
"",
"https://img.shields.io/badge/License-LGPL%20v3-blue.svg",
"https://img.shields.io/badge/License-MIT-yellow.svg",
"https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg",
"https://img.shields.io/badge/license-Unlicense-blue.svg"),
license_url = c("https://opensource.org/licenses/AGPL-3.0",
"https://opensource.org/licenses/Apache-2.0",
"https://opensource.org/licenses/BSD-2-Clause",
"https://opensource.org/licenses/BSD-3-Clause",
"https://www.eclipse.org/legal/epl-2.0/",
"https://www.gnu.org/licenses/gpl-2.0",
"https://www.gnu.org/licenses/gpl-3.0",
"https://www.gnu.org/licenses/lgpl-2.1",
"https://www.gnu.org/licenses/lgpl-3.0",
"https://opensource.org/licenses/MIT",
"https://opensource.org/licenses/MPL-2.0",
"http://unlicense.org/"),
stringsAsFactors = FALSE)
license_badges <- get_license_badge_info() %>%
kwb.utils::renameColumns(list(image_url = "badge_url"))

gh_licenses_df <- dplyr::left_join(gh_licenses_df,
license_badges)
gh_licenses_df <- dplyr::left_join(gh_licenses_df, license_badges)

gh_licenses_df$Badge_License <- sprintf("[![%s](%s)](%s)",
gh_licenses_df$spdx_id,
gh_licenses_df$badge_url,
gh_licenses_df$license_url)
gh_licenses_df$Badge_License <- image_link(
image_name = gh_licenses_df$spdx_id,
image_url = gh_licenses_df$badge_url,
link_url = gh_licenses_df$license_url
)

badges <- gh_licenses_df %>%
dplyr::select_(~key, ~Badge_License) %>%
dplyr::rename_(license_key = ~key)

result <- dplyr::left_join(
x = data.frame(
license_key = license_keys,
stringsAsFactors = FALSE
),
y = badges
)

res <- dplyr::left_join(x = data.frame(license_key = license_keys,
stringsAsFactors = FALSE),
y = badges)

return(res$Badge_License)
result$Badge_License
}
27 changes: 19 additions & 8 deletions R/badge_opencpu.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@
#' @return OpenCpu logo in html with path to R package on OpenCpu
#' @export

badge_opencpu <- function(url,
logo_path = "https://avatars2.githubusercontent.com/u/28672890?s=200&v=4",
size = 24) {
badge_opencpu <- function(
url,
logo_path = compose_url(
protocol = "https",
subdomain = "avatars2",
domain_name = "githubusercontent.com",
path = "u/28672890",
parameters = list(
s = 200,
v = 4
)
),
size = 24
)
{
img_attr <- sprintf(" title='OpenCpu' width='%d' height = '%d'", size, size)

sprintf("<a href='%s'><img src='%s' title='OpenCpu' width='%d' height = '%d'/></a>",
url,
logo_path,
size,
size)
logo_path %>%
html_img(img_attr) %>%
html_a(href = url)
}
50 changes: 34 additions & 16 deletions R/badge_zenodo.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,55 @@
#' @importFrom stringr str_detect
#' @return zenodo badges for provided repo_full_names
#' @export
badge_zenodo <- function(repo_full_names,
zenodo_token = Sys.getenv("ZENODO_TOKEN")) {

badge_zenodo <- function(
repo_full_names,
zenodo_token = Sys.getenv("ZENODO_TOKEN")
)
{
zen_data <- zen_collections(access_token = zenodo_token)

zen_badge <- rep(NA, length = length(repo_full_names))
zen_badge <- na_along(repo_full_names)

for (index in seq_along(repo_full_names)) {

doi_exists <- stringr::str_detect(
string = zen_data$metadata.related_identifiers.identifier ,
pattern = sprintf("https://github.com/%s",
repo_full_names[index]))
pattern = compose_url(
protocol = "https",
domain_name = "github.com",
path = repo_full_names[index]
)
)

doi_exists[is.na(doi_exists)] <- FALSE

if(sum(doi_exists) == 1) {
if (sum(doi_exists) == 1L) {

zen_badge[index] <- image_link(
image_name = "DOI",
image_url = zen_data$links.badge[doi_exists],
link_url = zen_data$doi_url[doi_exists]
)

} else if (sum(doi_exists) > 1L) {

zen_badge[index] <- sprintf("[![DOI](%s)](%s)",
zen_data$links.badge[doi_exists],
zen_data$doi_url[doi_exists])
warn_msg <- sprintf(
"Multiple entries found for repo '%s':\n%s",
repo_full_names[index],
paste(
zen_data$metadata.related_identifiers.identifier[doi_exists],
collapse = "\n"
)
)

} else if (sum(doi_exists) > 1) {
warn_msg <- sprintf("Multiple entries found for repo '%s':\n%s",
repo_full_names[index],
paste(zen_data$metadata.related_identifiers.identifier[doi_exists],
collapse = "\n"))
warning(warn_msg)
zen_badge[index] <- "Multiple badges found!"

} else {

zen_badge[index] <- NA
}
}
return(zen_badge)

zen_badge
}
Loading

0 comments on commit 5a9b060

Please sign in to comment.