Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean get_repos() #5

Open
wants to merge 51 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
2a2e017
Clean get_repos()
hsonne May 25, 2021
1b7fdf9
Merge branch 'dev' into get-repos
hsonne May 25, 2021
ee7000b
Avoid helper variable "finished"
hsonne May 25, 2021
d3f8ad4
Merge branch 'get-repos' of https://github.com/kwb-r/kwb.pkgstatus in…
hsonne May 25, 2021
20886d7
Fix :bug:: actually use "page"!
hsonne May 25, 2021
539fb0f
Avoid endless loop, increment page!
hsonne May 25, 2021
525918e
Fix :bug:: actually increment!
hsonne May 25, 2021
e1b4331
Merge branch 'dev' into get-repos
hsonne Apr 29, 2024
2363e4b
Improve formatting in get_repo_infos.R
hsonne Apr 29, 2024
5a9b060
Clean the package
hsonne Apr 29, 2024
f4705ec
Simplify (e.g. use shorter names)
hsonne Apr 30, 2024
60ab4c5
Remove function duplicates!
hsonne Apr 30, 2024
b66ad91
Change interface to html_img()
hsonne Apr 30, 2024
8cd52e6
Clean badg_zenodo.R
hsonne Apr 30, 2024
73b1415
Fix documentation
hsonne Apr 30, 2024
07c13c6
Reuse url_success(), use paste0(), not sprintf()
hsonne Apr 30, 2024
06d9595
Clean check_opencpu_deploy.R
hsonne Apr 30, 2024
80e646a
Add a new line character
hsonne Apr 30, 2024
5dbf2cc
Clean badge_license.R
hsonne Apr 30, 2024
554c995
Clean check_gitlab_backup.R
hsonne Apr 30, 2024
d035916
Add list_files_in_github_repo()
hsonne Apr 30, 2024
1b262c4
Look for GITHUB_TOKEN first, GITHUB_PAT second
hsonne Apr 30, 2024
d636624
Clean get_repo_infos()
hsonne Apr 30, 2024
4baf9a7
Check for http request errors
hsonne Apr 30, 2024
f01878c
Authenticate correctly, replace all NULL with NA
hsonne Apr 30, 2024
dd64271
Add get_names_of_r_packages_on_github()
hsonne Apr 30, 2024
6d56172
Handle special case and error
hsonne Apr 30, 2024
4f5a828
Add argument "hard_coded" to get_non_r_packages()
hsonne Apr 30, 2024
31ce953
Update Rd file
hsonne Apr 30, 2024
e5619b4
Add arguments "per_page", "dbg"
hsonne Apr 30, 2024
ce7d0ef
Add arg "dbg" to get_names_of_r_packages_on_github()
hsonne Apr 30, 2024
eb96ec0
Add make_github_package_db()
hsonne Apr 30, 2024
f464e45
Add and use compose_url_codecov()
hsonne May 1, 2024
738db7a
Move compose_url() functions to its own file
hsonne May 1, 2024
c21e5e7
Add and use compose_url_cran()
hsonne May 1, 2024
ace7df2
Add and use compose_url_netlify()
hsonne May 1, 2024
bc9e916
Add and use compose_url_opencpu()
hsonne May 1, 2024
4a97379
Add and use compose_url_github()
hsonne May 1, 2024
aec8d13
Add and use compose_url_appveyor()
hsonne May 1, 2024
ff71397
Add and use compose_url_travis()
hsonne May 1, 2024
83b229e
Add and use compose_url_ocpu()
hsonne May 1, 2024
d32e16b
Add and use more compose_url_*() functions
hsonne May 1, 2024
6878544
Update Rd files
hsonne May 1, 2024
dc67b9c
Use to_full_path() instead of to_url()
hsonne May 1, 2024
33320cf
Add missing argument "group"
hsonne May 1, 2024
9740e69
Move result[index] out of if-clause
hsonne May 1, 2024
a81258d
Move url_success() to helpers.R
hsonne May 1, 2024
3d30af7
Use get_*token() to get any token
hsonne May 1, 2024
2ff1360
Omit helper variable "tokens_undefined"
hsonne May 1, 2024
318f64c
Move functions and delete url_helpers.R
hsonne May 1, 2024
000331a
Get rid of url_path() (was only used once)
hsonne May 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export(create_report_rpackages)
export(get_coverages)
export(get_github_repos)
export(get_gitlab_repos)
export(get_names_of_r_packages_on_github)
export(get_non_r_packages)
export(make_github_package_db)
export(prepare_status_rpackages)
export(process_hitter_response)
export(zen_collections)
Expand Down
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_path <- function(path) {
paste0("github/", repo_full_names, path)
}

image_link(
image_name = "codecov",
image_url = compose_url_codecov(
path = to_full_path("/branch/master/graphs/badge.svg")
),
link_url = compose_url_codecov(
path = to_full_path("")
)
)
}



26 changes: 16 additions & 10 deletions R/badge_cran.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#' 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_path <- function(path) {
paste0(path, "/", repo_names)
}

image_link(
image_name = "CRAN_Status_Badge",
image_url = compose_url_cran(
path = to_full_path("badges/version")
),
link_url = compose_url_cran(
path = to_full_path("pkg")
)
)
}




16 changes: 8 additions & 8 deletions R/badge_dependencies.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#' 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)
{
image_link(
image_name = "Dependencies_badge",
image_url = compose_url_netlify(paste0("badge/", repo_names)),
link_url = compose_url_netlify("")
)
}




25 changes: 13 additions & 12 deletions R/badge_gitlab.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#' 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) {

sprintf("<a href='%s'><img src='%s' title='Gitlab' width='%d' height = '%d'/></a>",
url,
logo_path,
size,
size)
}
badge_gitlab <- function(
url,
logo_path = compose_url_gitlab(
path = "gitlab-com/gitlab-artwork/raw/master/logo/logo-square.png"
),
size = 24
)
{
logo_path %>%
html_img(title = "Gitlab", width = size, height = size) %>%
html_a(href = url)
}
83 changes: 23 additions & 60 deletions R/badge_license.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,38 @@
#' @param license_keys one or many valid license keys from 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")
#' @param github_token github access token (default: Sys.getenv("GITHUB_TOKEN"))
#' @param github_token github access token. Default:
#' kwb.pkgstatus:::get_github_token()
#' @importFrom gh gh
#' @importFrom data.table rbindlist
#' @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)

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


badge_license <- function(license_keys, github_token = get_github_token())
{
#### 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()

gh_licenses_df <- dplyr::left_join(gh_licenses_df,
license_badges)
gh_licenses_df <- "GET /licenses" %>%
gh::gh(.token = github_token) %>%
data.table::rbindlist(fill = TRUE) %>%
dplyr::left_join(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$image_url,
link_url = gh_licenses_df$license_url
)

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


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

return(res$Badge_License)
dplyr::rename_(license_key = ~key) %>%
dplyr::left_join(
x = data.frame(
license_key = license_keys,
stringsAsFactors = FALSE
)
)

badges$Badge_License
}
23 changes: 13 additions & 10 deletions R/badge_opencpu.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
#' @param size size of logo in pixels (default: 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) {

sprintf("<a href='%s'><img src='%s' title='OpenCpu' width='%d' height = '%d'/></a>",
url,
logo_path,
size,
size)
badge_opencpu <- function(
url,
logo_path = compose_url_githubusercontent(
subdomain = "avatars2",
path = "u/28672890",
parameters = list(s = 200, v = 4)
),
size = 24
)
{
logo_path %>%
html_img(title = "OpenCpu", width = size, height = size) %>%
html_a(href = url)
}
62 changes: 41 additions & 21 deletions R/badge_zenodo.R
Original file line number Diff line number Diff line change
@@ -1,42 +1,62 @@
#' badge_zenodo
#'
#' @param repo_full_names vector with combination of username/repo (e.g.
#' c("KWB-R/kwb.utils", "KWB-R/kwb.db"))
#' @param zenodo_token zenodo authentication token (default:
#' Sys.getenv("ZENODO_TOKEN"))
#' @param zenodo_token zenodo authentication token.
#' Default: kwb.pkgstatus:::get_token("ZENODO")
#' @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 = get_token("ZENODO")
)
{
zen_data <- zen_collections(access_token = zenodo_token)

zen_badge <- rep(NA, length = length(repo_full_names))
result <- 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_github(
path = repo_full_names[index]
)
)

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

if(sum(doi_exists) == 1) {
n_existing <- sum(doi_exists)

result[index] <- if (n_existing == 1L) {

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

zen_badge[index] <- sprintf("[![DOI](%s)](%s)",
zen_data$links.badge[doi_exists],
zen_data$doi_url[doi_exists])
} else if (n_existing > 1L) {

warning(
sprintf(
"Multiple entries found for repo '%s':\n",
repo_full_names[index]
),
paste(
zen_data$metadata.related_identifiers.identifier[doi_exists],
collapse = "\n"
)
)

"Multiple badges found!"

} 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

NA
}
}
return(zen_badge)

result
}
Loading
Loading