From 08cb388662c90ab5e7aabdbcb6fe137a4eaebda7 Mon Sep 17 00:00:00 2001 From: margot Date: Fri, 24 Feb 2023 11:19:50 +0000 Subject: [PATCH 1/7] feat: (wip) Add the possibility to create subgroups Fix merge conflicts and duplicate functions issue #101 --- R/groups.R | 143 +++++++++++++++++++++++++---------------- R/projects_and_repos.R | 2 +- 2 files changed, 89 insertions(+), 56 deletions(-) diff --git a/R/groups.R b/R/groups.R index 917c2b0..db4296a 100644 --- a/R/groups.R +++ b/R/groups.R @@ -1,17 +1,20 @@ -#' List groups information -#' +#' List and manage groups +#' #' @param ... passed on to [gitlab()] #' @export #' @return tibble of each group with corresponding information -#' +#' #' @details #' When using `gl_list_sub_groups()`, if you request this list as: #' - An unauthenticated user, the response returns only public groups. -#' - An authenticated user, the response returns only the groups you’re a member of and does not include public groups. -#' +#' - An authenticated user, the response returns only the groups +#' you’re a member of and does not include public groups. +#' +#' +#' #' @examples \dontrun{ #' set_gitlab_connection( -#' gitlab_url = "https://gitlab.com", +#' gitlab_url = "https://gitlab.com", #' private_token = Sys.getenv("GITLAB_COM_TOKEN") #' ) #' # List all groups @@ -23,7 +26,7 @@ gl_list_groups <- function(...) { gitlabr::gitlab("groups", ...) } -#' @param group The ID or URL-encoded path of the group +#' @param group The ID, name or URL-encoded path of the group #' @export #' @rdname gl_list_groups gl_list_sub_groups <- function(group, ...) { @@ -35,7 +38,7 @@ gl_list_sub_groups <- function(group, ...) { #' Prefixes the request location with "groups/:id/subgroups" and automatically #' translates group names into ids #' -#' @param group group name or id +#' @param group The ID, name or URL-encoded path of the group #' @param ... passed on to [gl_get_group_id()] #' @export #' @return A vector of character to be used as request for functions involving groups @@ -52,16 +55,16 @@ gl_group_req <- function(group, ...) { } #' Get a group id by name -#' +#' #' @param group_name group name #' @param ... passed on to [gitlab()] #' @importFrom dplyr mutate filter -#' -#' @details +#' +#' @details #' Number of pages searched is limited to (per_page =) 20 * (max_page =) 10 by default. -#' If the `group_name` is an old group lost in a big repository (position > 200), +#' If the `group_name` is an old group lost in a big repository (position > 200), #' `gl_get_group_id()` may not find the group id. -#' +#' #' @export #' @return Integer. ID of the group if found. #' @examples @@ -69,35 +72,42 @@ gl_group_req <- function(group, ...) { #' gl_get_group_id("<>") #' } gl_get_group_id <- function(group_name, ...) { - matching <- gitlab(req = "groups", ...) %>% - mutate(matches_name = name == group_name, - matches_path = path == group_name, - matches_full_path = full_path == group_name) %>% - filter(matches_full_path | - (sum(matches_full_path) == 0L & - matches_path | matches_name)) - + mutate( + matches_name = name == group_name, + matches_path = path == group_name, + matches_full_path = full_path == group_name + ) %>% + filter(matches_full_path || + (sum(matches_full_path) == 0L & + matches_path | matches_name)) + if (nrow(matching) == 0) { - stop("There was no matching 'id' with your group name. ", - "Either it does not exist, or most probably, ", - "it is not available in the first groups available to you. ", - "The name-matching is limited to the first pages of groups accessible. ", - "Please use directly the 'id' of your group.") + stop( + "There was no matching 'id' with your group name. ", + "Either it does not exist, or most probably, ", + "it is not available in the first groups available to you. ", + "The name-matching is limited to the first pages of groups accessible. ", + "Please use directly the 'id' of your group." + ) } else if (nrow(matching) > 1) { - warning(paste(c("Multiple groups with given name or path found,", - "please use explicit name with namespace:", - matching$path_with_namespace, - paste("Picking", matching[1,"path_with_namespace"], "as default")), - collapse = "\n")) + warning(paste( + c( + "Multiple groups with given name or path found,", + "please use explicit name with namespace:", + matching$path_with_namespace, + paste("Picking", matching[1, "path_with_namespace"], "as default") + ), + collapse = "\n" + )) } - - matching[1,"id"] %>% + + matching[1, "id"] %>% as.integer() } to_group_id <- function(x, ...) { - if (!is.na(suppressWarnings(as.numeric(x))) | is.numeric(x)) { + if (!is.na(suppressWarnings(as.numeric(x))) || is.numeric(x)) { as.numeric(x) } else { gl_get_group_id(x, ...) @@ -106,17 +116,18 @@ to_group_id <- function(x, ...) { #' Manage groups -#' @param path to the new group -#' @param name of the new group +#' @param path Path to the new group +#' @param name Name of the new group #' @param ... passed on to [gitlab()] API call for "Create group" #' @export -#' @return A tibble with the group information. `gl_delete_group()` returns an empty tibble. -#' @details +#' @return A tibble with the group information. +#' `gl_delete_group()` returns an empty tibble. +#' @details #' You can use extra parameters as proposed in the GitLab API. -#' +#' #' @examples \dontrun{ #' set_gitlab_connection( -#' gitlab_url = "https://gitlab.com", +#' gitlab_url = "https://gitlab.com", #' private_token = Sys.getenv("GITLAB_COM_TOKEN") #' ) #' # Create new group @@ -129,30 +140,52 @@ to_group_id <- function(x, ...) { gl_new_group <- function(name, path, ...) { - gitlab(req = "groups", - path = path, - name = name, - verb = httr::POST, - ...) + gitlab( + req = "groups", + path = path, + name = name, + verb = httr::POST, + ... + ) +} + +#' @param group The ID, name or URL-encoded path of the group +#' @param visibility Visibility of the new subgroup: "public", "private"... +#' @export +#' @rdname gl_new_group +gl_new_subgroup <- function(name, + visibility = c("private", "public"), + group, + ...) { + visibility <- match.arg(visibility, several.ok = FALSE) + + gitlab( + req = "groups", + name = name, + visibility = visibility, + parent_id = to_group_id(group), + verb = httr::POST, + ... + ) } -#' @param group The ID or URL-encoded path of the group. +#' @param group The ID, name or URL-encoded path of the group #' @rdname gl_new_group #' @export gl_edit_group <- function(group, ...) { - - gitlab(req = c("groups", to_group_id(group)), - verb = httr::PUT, - ...) - + gitlab( + req = c("groups", to_group_id(group)), + verb = httr::PUT, + ... + ) } #' @rdname gl_new_group #' @export gl_delete_group <- function(group) { - - gitlab(req = c("groups", to_group_id(group)), - verb = httr::DELETE) + gitlab( + req = c("groups", to_group_id(group)), + verb = httr::DELETE + ) } - diff --git a/R/projects_and_repos.R b/R/projects_and_repos.R index 66d8725..8540ac8 100644 --- a/R/projects_and_repos.R +++ b/R/projects_and_repos.R @@ -306,4 +306,4 @@ gl_list_project_members <- function(project, ...) { #' } gl_list_group_members <- function(group, ...) { gitlab(req = c("groups", group, "members")) -} \ No newline at end of file +} From 45eba867dbfc7eb4ff7b2815db5a17f65cbbfdea Mon Sep 17 00:00:00 2001 From: StatnMap Date: Wed, 15 May 2024 10:35:46 +0200 Subject: [PATCH 2/7] test: subgroups are tested on interactive mode doc updated closes issue #101 --- NAMESPACE | 1 + NEWS.md | 1 + R/groups.R | 48 ++++++++++++++++------ dev/dev_history.R | 10 ++++- man/gl_get_group_id.Rd | 6 ++- man/gl_group_req.Rd | 5 ++- man/gl_list_groups.Rd | 11 +++--- man/gl_new_group.Rd | 31 ++++++++++++--- tests/testthat/test_groups.R | 77 ++++++++++++++++++++++++++---------- 9 files changed, 140 insertions(+), 50 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 4c56006..fcc4ead 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -61,6 +61,7 @@ export(gl_list_user_projects) export(gl_new_group) export(gl_new_issue) export(gl_new_project) +export(gl_new_subgroup) export(gl_pipelines) export(gl_proj_req) export(gl_project_connection) diff --git a/NEWS.md b/NEWS.md index e19ff59..eb82a78 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ ## New features * `gl_new_group()`, `gl_edit_group()`, `gl_delete_group()`, `gl_list_groups()`, `gl_list_sub_groups()` to deal with groups on a GitLab instance (@mpolano) +* `gl_new_subgroup()` to create a subgroup in a group (@margotbrd) * `gl_delete_file()` to delete a file in a repository * `gl_list_project_members()` and `gl_list_group_members` to retrieve members of a project or a group (#61, @datawookie) * `gitlab()` queries allow for a vector of parameters to be passed to the API. This is needed when the API asks for an array (@klmr) diff --git a/R/groups.R b/R/groups.R index db4296a..3fedd04 100644 --- a/R/groups.R +++ b/R/groups.R @@ -34,15 +34,16 @@ gl_list_sub_groups <- function(group, ...) { } #' Create a group specific request -#' +#' #' Prefixes the request location with "groups/:id/subgroups" and automatically #' translates group names into ids -#' +#' #' @param group The ID, name or URL-encoded path of the group #' @param ... passed on to [gl_get_group_id()] #' @export -#' @return A vector of character to be used as request for functions involving groups -#' @examples +#' @return A vector of character to be used +#' as request for functions involving groups +#' @examples #' \dontrun{ #' gl_group_req("test_group"<>) #' } @@ -61,8 +62,10 @@ gl_group_req <- function(group, ...) { #' @importFrom dplyr mutate filter #' #' @details -#' Number of pages searched is limited to (per_page =) 20 * (max_page =) 10 by default. -#' If the `group_name` is an old group lost in a big repository (position > 200), +#' Number of pages searched is limited to +#' (per_page =) 20 * (max_page =) 10 by default. +#' If the `group_name` is an old group lost +#' in a big repository (position > 200), #' `gl_get_group_id()` may not find the group id. #' #' @export @@ -78,9 +81,11 @@ gl_get_group_id <- function(group_name, ...) { matches_path = path == group_name, matches_full_path = full_path == group_name ) %>% - filter(matches_full_path || - (sum(matches_full_path) == 0L & - matches_path | matches_name)) + filter( + matches_full_path | + (sum(matches_full_path) == 0L & + matches_path | matches_name) + ) if (nrow(matching) == 0) { stop( @@ -125,6 +130,11 @@ to_group_id <- function(x, ...) { #' @details #' You can use extra parameters as proposed in the GitLab API. #' +#' Note that on GitLab SaaS, you must use the GitLab UI to +#' create groups without a parent group. +#' You cannot use the API with [gl_new_group()] to do this, +#' but you can use [gl_new_subgroup()]. +#' #' @examples \dontrun{ #' set_gitlab_connection( #' gitlab_url = "https://gitlab.com", @@ -132,6 +142,8 @@ to_group_id <- function(x, ...) { #' ) #' # Create new group #' gl_new_group(name = "mygroup") +#' # Create new subgroup +#' gl_new_subgroup(name = "mysubgroup", group = "mygroup") #' # Edit existing group #' gl_edit_group(group = "<>", default_branch = "main") #' # Delete group @@ -139,11 +151,15 @@ to_group_id <- function(x, ...) { #' } gl_new_group <- function(name, path, + visibility = c("private", "internal", "public"), ...) { + visibility <- match.arg(visibility, several.ok = FALSE) + gitlab( req = "groups", path = path, name = name, + visibility = visibility, verb = httr::POST, ... ) @@ -153,15 +169,21 @@ gl_new_group <- function(name, #' @param visibility Visibility of the new subgroup: "public", "private"... #' @export #' @rdname gl_new_group -gl_new_subgroup <- function(name, - visibility = c("private", "public"), - group, - ...) { +gl_new_subgroup <- function( + name, + path, + visibility = c("private", "internal", "public"), + group, + ...) { visibility <- match.arg(visibility, several.ok = FALSE) + if (missing(path)) { + path <- name + } gitlab( req = "groups", name = name, + path = path, visibility = visibility, parent_id = to_group_id(group), verb = httr::POST, diff --git a/dev/dev_history.R b/dev/dev_history.R index d698609..ed16ae2 100644 --- a/dev/dev_history.R +++ b/dev/dev_history.R @@ -44,8 +44,9 @@ attachment::att_amend_desc( ) devtools::load_all() devtools::test() -devtools::check() +devtools::check() # tests are skipped as cran devtools::check(args = c("--no-tests")) +rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning") devtools::build_vignettes() # Deal with tests ---- @@ -63,10 +64,15 @@ testthat::test_file("tests/testthat/test_files.R") ## run test on one file covr::package_coverage() covr::report() -# _Check in interactive test-inflate for templates and Addins +# _Check in interactive test pkgload::load_all() devtools::test() testthat::test_dir("tests/testthat/") +# Create and suppress groups +# > On GitLab SaaS, you must use the GitLab UI to +# create groups without a parent group. You cannot use the API to do this. +# Thus, tests check GITLABR_TEST_URL to run or not +testthat::test_file("tests/testthat/test_groups.R") # Run examples in interactive mode too devtools::run_examples() diff --git a/man/gl_get_group_id.Rd b/man/gl_get_group_id.Rd index 6efffbd..837da60 100644 --- a/man/gl_get_group_id.Rd +++ b/man/gl_get_group_id.Rd @@ -18,8 +18,10 @@ Integer. ID of the group if found. Get a group id by name } \details{ -Number of pages searched is limited to (per_page =) 20 * (max_page =) 10 by default. -If the \code{group_name} is an old group lost in a big repository (position > 200), +Number of pages searched is limited to +(per_page =) 20 * (max_page =) 10 by default. +If the \code{group_name} is an old group lost +in a big repository (position > 200), \code{gl_get_group_id()} may not find the group id. } \examples{ diff --git a/man/gl_group_req.Rd b/man/gl_group_req.Rd index 27d2a31..a7263b6 100644 --- a/man/gl_group_req.Rd +++ b/man/gl_group_req.Rd @@ -7,12 +7,13 @@ gl_group_req(group, ...) } \arguments{ -\item{group}{group name or id} +\item{group}{The ID, name or URL-encoded path of the group} \item{...}{passed on to \code{\link[=gl_get_group_id]{gl_get_group_id()}}} } \value{ -A vector of character to be used as request for functions involving groups +A vector of character to be used +as request for functions involving groups } \description{ Prefixes the request location with "groups/:id/subgroups" and automatically diff --git a/man/gl_list_groups.Rd b/man/gl_list_groups.Rd index 45306b4..a0b4b12 100644 --- a/man/gl_list_groups.Rd +++ b/man/gl_list_groups.Rd @@ -3,7 +3,7 @@ \name{gl_list_groups} \alias{gl_list_groups} \alias{gl_list_sub_groups} -\title{List groups information} +\title{List and manage groups} \usage{ gl_list_groups(...) @@ -12,25 +12,26 @@ gl_list_sub_groups(group, ...) \arguments{ \item{...}{passed on to \code{\link[=gitlab]{gitlab()}}} -\item{group}{The ID or URL-encoded path of the group} +\item{group}{The ID, name or URL-encoded path of the group} } \value{ tibble of each group with corresponding information } \description{ -List groups information +List and manage groups } \details{ When using \code{gl_list_sub_groups()}, if you request this list as: \itemize{ \item An unauthenticated user, the response returns only public groups. -\item An authenticated user, the response returns only the groups you’re a member of and does not include public groups. +\item An authenticated user, the response returns only the groups +you’re a member of and does not include public groups. } } \examples{ \dontrun{ set_gitlab_connection( - gitlab_url = "https://gitlab.com", + gitlab_url = "https://gitlab.com", private_token = Sys.getenv("GITLAB_COM_TOKEN") ) # List all groups diff --git a/man/gl_new_group.Rd b/man/gl_new_group.Rd index d6f0363..e8321f8 100644 --- a/man/gl_new_group.Rd +++ b/man/gl_new_group.Rd @@ -2,42 +2,61 @@ % Please edit documentation in R/groups.R \name{gl_new_group} \alias{gl_new_group} +\alias{gl_new_subgroup} \alias{gl_edit_group} \alias{gl_delete_group} \title{Manage groups} \usage{ -gl_new_group(name, path, ...) +gl_new_group(name, path, visibility = c("private", "internal", "public"), ...) + +gl_new_subgroup( + name, + path, + visibility = c("private", "internal", "public"), + group, + ... +) gl_edit_group(group, ...) gl_delete_group(group) } \arguments{ -\item{name}{of the new group} +\item{name}{Name of the new group} -\item{path}{to the new group} +\item{path}{Path to the new group} + +\item{visibility}{Visibility of the new subgroup: "public", "private"...} \item{...}{passed on to \code{\link[=gitlab]{gitlab()}} API call for "Create group"} -\item{group}{The ID or URL-encoded path of the group.} +\item{group}{The ID, name or URL-encoded path of the group} } \value{ -A tibble with the group information. \code{gl_delete_group()} returns an empty tibble. +A tibble with the group information. +\code{gl_delete_group()} returns an empty tibble. } \description{ Manage groups } \details{ You can use extra parameters as proposed in the GitLab API. + +Note that on GitLab SaaS, you must use the GitLab UI to +create groups without a parent group. +You cannot use the API with \code{\link[=gl_new_group]{gl_new_group()}} to do this, +but you can use \code{\link[=gl_new_subgroup]{gl_new_subgroup()}}. } \examples{ \dontrun{ set_gitlab_connection( - gitlab_url = "https://gitlab.com", + gitlab_url = "https://gitlab.com", private_token = Sys.getenv("GITLAB_COM_TOKEN") ) # Create new group gl_new_group(name = "mygroup") +# Create new subgroup +gl_new_subgroup(name = "mysubgroup", group = "mygroup") # Edit existing group gl_edit_group(group = "<>", default_branch = "main") # Delete group diff --git a/tests/testthat/test_groups.R b/tests/testthat/test_groups.R index d69f9a6..e1aceba 100644 --- a/tests/testthat/test_groups.R +++ b/tests/testthat/test_groups.R @@ -1,9 +1,8 @@ - test_that("gl_list_groups works", { group_list <- gl_list_groups() expect_gte(nrow(group_list), 0) expect_true(all(c("id", "name", "path") %in% names(group_list))) - + if (test_group_name == "thinkr-open") { expect_true("thinkr-open" %in% group_list[["name"]]) } @@ -11,31 +10,69 @@ test_that("gl_list_groups works", { test_that("gl_list_sub_groups works", { subgroup_list <- gl_list_sub_groups(test_group_id) - + if (nrow(subgroup_list) >= 1) { # Only work if user is member of the group with a subgroup # expect_gte(nrow(subgroup_list), 1) expect_true(all(c("id", "name", "path") %in% names(subgroup_list))) - + if (test_group_name == "thinkr-open") { expect_true("dontdelete.subgroup.for.gitlabr" %in% subgroup_list[["name"]]) } } }) -# Dont test to avoid GitLab rejection. -# -# new_group <- gl_new_group(name = "gitlabr-temp-group", path = "gitlabr-temp-group") -# -# test_that("gl_new_group works", { -# expect_equal(nrow(new_group), 1) -# expect_true(all(c("id", "name", "path") %in% names(new_group))) -# }) -# -# test_that("gl_delete_group works", { -# res <- gl_delete_group(new_group$id) -# expect_equal(nrow(res), 1) -# expect_true( c("message") %in% names(res)) -# expect_equal(res$message, "202 Accepted") -# }) - \ No newline at end of file +test_that("gl_get_group_id works", { + expect_equal( + as.character( + gl_get_group_id(Sys.getenv("GITLABR_TEST_GROUP_NAME")) + ), + Sys.getenv("GITLABR_TEST_GROUP_ID") + ) +}) + +# Dont test to avoid GitLab rejection. +if (interactive()) { + if (!grepl("gitlab[.]com", Sys.getenv("GITLABR_TEST_URL"))) { + # Forbidden on GitLab SaaS + new_group <- gl_new_group( + name = "gitlabr-temp-group", + path = "gitlabr-temp-group" + ) + } + + new_subgroup <- gl_new_subgroup( + name = "gitlabr-tempsubgroup", + group = Sys.getenv("GITLABR_TEST_GROUP_ID") + ) + + if (!grepl("gitlab[.]com", Sys.getenv("GITLABR_TEST_URL"))) { + test_that("gl_new_group works", { + expect_equal(nrow(new_group), 1) + expect_true(all(c("id", "name", "path") %in% names(new_group))) + }) + } + + test_that("gl_new_subgroup works", { + expect_equal(nrow(new_subgroup), 1) + expect_true(all(c("id", "name", "path") %in% names(new_subgroup))) + expect_equal(new_subgroup$parent_id, Sys.getenv("GITLABR_TEST_GROUP_ID")) + expect_equal(new_subgroup$name, "gitlabr-tempsubgroup") + }) + + test_that("gl_delete_group works on subgroup", { + res <- gl_delete_group(new_subgroup$id) + expect_equal(nrow(res), 1) + expect_true(c("message") %in% names(res)) + expect_equal(res$message, "202 Accepted") + }) + + if (!grepl("gitlab[.]com", Sys.getenv("GITLABR_TEST_URL"))) { + test_that("gl_delete_group works", { + res <- gl_delete_group(new_group$id) + expect_equal(nrow(res), 1) + expect_true(c("message") %in% names(res)) + expect_equal(res$message, "202 Accepted") + }) + } +} From 5088766fe486235adfb8beff4adbd3a5ad214a76 Mon Sep 17 00:00:00 2001 From: StatnMap Date: Wed, 15 May 2024 10:54:31 +0200 Subject: [PATCH 3/7] chore: clean package code with styler --- DESCRIPTION | 2 +- R/branches.R | 60 ++++--- R/comments.R | 137 +++++++++------- R/files.R | 48 +++--- R/global_env.R | 14 +- R/groups.R | 4 +- R/issues.R | 98 ++++++------ R/merge_requests.R | 69 ++++---- R/multilist_to_tibble.R | 30 +--- R/projects_and_repos.R | 194 ++++++++++++----------- dev/dev_history.R | 3 + man/branches.Rd | 20 ++- man/gl_archive.Rd | 2 +- man/gl_comments.Rd | 18 ++- man/gl_create_merge_request.Rd | 20 ++- man/gl_group_req.Rd | 2 +- man/gl_list_files.Rd | 7 +- man/gl_list_group_members.Rd | 2 +- man/gl_list_issues.Rd | 6 +- man/gl_list_project_members.Rd | 2 +- man/gl_list_projects.Rd | 2 +- man/gl_new_issue.Rd | 2 +- man/gl_new_project.Rd | 2 +- man/gl_proj_req.Rd | 2 +- man/gl_repository.Rd | 16 +- man/onefile.Rd | 5 +- tests/testthat/helper.R | 7 +- tests/testthat/test_connection_env.R | 227 ++++++++++++++------------- tests/testthat/test_groups.R | 25 +-- tests/testthat/test_merge_requests.R | 15 +- tests/testthat/test_projects_repos.R | 26 ++- 31 files changed, 580 insertions(+), 487 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e7fd229..8b8dcd8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gitlabr Title: Access to the 'Gitlab' API -Version: 2.0.1.9004 +Version: 2.0.1.9005 Authors@R: c( person("Jirka", "Lewandowski", , "jirka.lewandowski@wzb.eu", role = "aut"), person("Sébastien", "Rochette", , "sebastien@thinkr.fr", role = c("aut", "cre"), diff --git a/R/branches.R b/R/branches.R index 9e59732..a50d024 100644 --- a/R/branches.R +++ b/R/branches.R @@ -1,39 +1,45 @@ #' List, create and delete branches -#' +#' #' @rdname branches #' @param project name or id of project (not repository!) #' @param ... passed on to [gitlab()] #' @export #' @return Tibble of branches available in the project with descriptive variables #' @examples \dontrun{ -#' set_gitlab_connection(gitlab_url = "https://gitlab.com", -#' private_token = Sys.getenv("GITLAB_COM_TOKEN")) +#' set_gitlab_connection( +#' gitlab_url = "https://gitlab.com", +#' private_token = Sys.getenv("GITLAB_COM_TOKEN") +#' ) #' project_id <- ... ## Fill in your project ID -#' +#' #' # List branches of the project -#' gl_list_branches(project_ = "<>") +#' gl_list_branches(project_ = "<>") #' # Create branch "new_feature" -#' gl_create_branch(project = "<>", -#' branch = "new_feature") +#' gl_create_branch( +#' project = "<>", +#' branch = "new_feature" +#' ) #' # Confirm that the branch was created #' gl_get_branch("<>", branch = "new_feature") #' # List all branches - this may take some time before your branch really appears there #' gl_list_branches(project = "<>") #' # Delete branch again -#' gl_delete_branch(project = "<>", -#' branch = "new_feature") +#' gl_delete_branch( +#' project = "<>", +#' branch = "new_feature" +#' ) #' # Check that we're back where we started #' gl_list_branches(project = "<>") #' } gl_list_branches <- function(project, ...) { - gl_proj_req(project, c("repository", "branches"), ...) %>% + gl_proj_req(project, c("repository", "branches"), ...) %>% gitlab(...) } #' @rdname branches #' @export gl_get_branch <- function(project, branch, ...) { - gl_proj_req(project, c("repository", "branches", branch), ...) %>% + gl_proj_req(project, c("repository", "branches", branch), ...) %>% gitlab(...) } @@ -42,24 +48,28 @@ gl_get_branch <- function(project, branch, ...) { #' @rdname branches #' @export gl_create_branch <- function(project, branch, ref = get_main(), ...) { - gl_proj_req(project, c("repository", "branches"), ...) %>% - gitlab(verb = httr::POST, - branch_name = branch, ## This is legacy for API v3 use and will be ignored by API v4 - branch = branch, - ref = ref, - auto_format = TRUE, - ...) #%>% - # tibble::as_tibble() + gl_proj_req(project, c("repository", "branches"), ...) %>% + gitlab( + verb = httr::POST, + branch_name = branch, ## This is legacy for API v3 use and will be ignored by API v4 + branch = branch, + ref = ref, + auto_format = TRUE, + ... + ) # %>% + # tibble::as_tibble() } #' List, create and delete branches -#' +#' #' @rdname branches #' @export gl_delete_branch <- function(project, branch, ...) { - gl_proj_req(project, c("repository", "branches", branch), ...) %>% - gitlab(verb = httr::DELETE, - auto_format = TRUE, - ...) #%>% - # tibble::as_tibble() + gl_proj_req(project, c("repository", "branches", branch), ...) %>% + gitlab( + verb = httr::DELETE, + auto_format = TRUE, + ... + ) # %>% + # tibble::as_tibble() } diff --git a/R/comments.R b/R/comments.R index 840a4d8..1e2ec17 100644 --- a/R/comments.R +++ b/R/comments.R @@ -1,37 +1,42 @@ #' Get the comments/notes of a commit or issue -#' +#' #' @param project project name or id #' @param object_type one of "issue" or "commit". Snippets and merge_requests are not implemented yet. -#' @param id id of object: -#' - commits: sha -#' - issues notes/comments: -#' + (project-wide) id for api version 4, -#' + (global) iid for api version 3 +#' @param id id of object: +#' - commits: sha +#' - issues notes/comments: +#' + (project-wide) id for api version 4, +#' + (global) iid for api version 3 #' @param note_id id of note #' @param ... passed on to [gitlab()] API call. See Details. #' @rdname gl_comments -#' +#' #' @details #' - `gl_comment_commit`: might also contain `path`, `line` #' and `line_type` (old or new) to attach the comment to a specific in a file. #' See https://docs.gitlab.com/ce/api/commits.html #' - `gl_get_issue_comments`: might also contain `comment_id` to get a specific #' comment of an issue. -#' +#' #' @export #' @return Tibble of comments with descriptive variables. #' @examples #' \dontrun{ #' # fill in login parameters -#' set_gitlab_connection(gitlab_url = "https://gitlab.com", -#' private_token = Sys.getenv("GITLAB_COM_TOKEN")) +#' set_gitlab_connection( +#' gitlab_url = "https://gitlab.com", +#' private_token = Sys.getenv("GITLAB_COM_TOKEN") +#' ) #' gl_get_comments(project = "<>", object_type = "issue", 1) -#' gl_get_comments(project = "<>", "commit", -#' id = "8ce5ef240123cd78c1537991e5de8d8323666b15") -#' gl_comment_issue(project = "<>", 1, -#' text = "Almost done!") +#' gl_get_comments( +#' project = "<>", "commit", +#' id = "8ce5ef240123cd78c1537991e5de8d8323666b15" +#' ) +#' gl_comment_issue( +#' project = "<>", 1, +#' text = "Almost done!" +#' ) #' } - gl_get_comments <- function(project, object_type = "issue", id, @@ -46,24 +51,29 @@ gl_comments <- function(project, note_id = c(), verb = httr::GET, api_version = 4, - ... ) { - + ...) { if (object_type == "commit" && !is.null(note_id)) { warning("Commit comments cannot be get separate by id, parameter note_id is ignored!") } - + if (object_type == "issue" && api_version == 3) { - id <- gl_to_issue_id(project, id, api_version = 3, ...) + id <- gl_to_issue_id(project, id, api_version = 3, ...) } - - gitlab(req = gl_proj_req(project, req = switch(object_type, - "issue" = c("issues", id, - "notes", note_id), - "commit" = c("repository", "commits", id, "comments")), - ...), - verb = verb, - ...) - + + gitlab( + req = gl_proj_req(project, + req = switch(object_type, + "issue" = c( + "issues", id, + "notes", note_id + ), + "commit" = c("repository", "commits", id, "comments") + ), + ... + ), + verb = verb, + ... + ) } #' @rdname gl_comments @@ -79,20 +89,22 @@ gl_get_commit_comments <- function(project, id, ...) { } #' @rdname gl_comments -#' +#' #' @param text Text of comment/note to add or edit (translates to GitLab API note/body respectively) #' @export -gl_comment_commit <- function(project, - id, - text, - ...) { - gl_comments(project = project, - object_type = "commit", - id = id, - note_id = NULL, - note = text, - verb = httr::POST, - ...) +gl_comment_commit <- function(project, + id, + text, + ...) { + gl_comments( + project = project, + object_type = "commit", + id = id, + note_id = NULL, + note = text, + verb = httr::POST, + ... + ) } #' @rdname gl_comments @@ -101,13 +113,15 @@ gl_comment_issue <- function(project, id, text, ...) { - gl_comments(project = project, - object_type = "issue", - id = id, - note_id = NULL, - body = text, - verb = httr::POST, - ...) + gl_comments( + project = project, + object_type = "issue", + id = id, + note_id = NULL, + body = text, + verb = httr::POST, + ... + ) } #' @rdname gl_comments @@ -117,17 +131,22 @@ gl_edit_comment <- function(project, text, ...) { switch(object_type, - "issue" = gl_comments(project = project, - object_type = "issue", - body = text, - verb = httr::PUT, - ...), - "commit" = gl_comments(project = project, - object_type = "commit", - note_id = NULL, ## prevent partial argument match - note = text, - verb = httr::PUT, - ...)) + "issue" = gl_comments( + project = project, + object_type = "issue", + body = text, + verb = httr::PUT, + ... + ), + "commit" = gl_comments( + project = project, + object_type = "commit", + note_id = NULL, ## prevent partial argument match + note = text, + verb = httr::PUT, + ... + ) + ) } #' @rdname gl_comments @@ -140,4 +159,4 @@ gl_edit_issue_comment <- function(project, ...) { #' @export gl_edit_commit_comment <- function(project, ...) { gl_edit_comment(project, object_type = "commit", ...) -} +} diff --git a/R/files.R b/R/files.R index d307582..405460e 100644 --- a/R/files.R +++ b/R/files.R @@ -1,5 +1,5 @@ #' Access to repository files in GitLab -#' +#' #' @param project name or id of project (not repository!) #' @param req request to perform on repository (everything after '/repository/' #' in GitLab API, as vector or part of URL) @@ -10,21 +10,23 @@ #' @examples \dontrun{ #' # Set GitLab connection for examples #' set_gitlab_connection( -#' gitlab_url = "https://gitlab.com", -#' private_token = Sys.getenv("GITLAB_COM_TOKEN")) -#' +#' gitlab_url = "https://gitlab.com", +#' private_token = Sys.getenv("GITLAB_COM_TOKEN") +#' ) +#' #' # Access repository #' # _All files -#' gl_repository(project = <>) +#' gl_repository(project = "<>") #' # _All contributors -#' gl_repository(project = <>, "contributors") +#' gl_repository(project = "<>", "contributors") #' # _Get content of one file -#' gl_get_file(project = <>, file_path = "README.md") +#' gl_get_file(project = "<>", file_path = "README.md") #' # _Test if file exists #' gl_file_exists( -#' project = <>, +#' project = "<>", #' file_path = "README.md", -#' ref = "main") +#' ref = "main" +#' ) #' } gl_repository <- function(project, req = c("tree"), ref = get_main(), ...) { gitlab(gl_proj_req(project, c("repository", req), ...), ref = ref, ...) @@ -32,20 +34,21 @@ gl_repository <- function(project, req = c("tree"), ref = get_main(), ...) { #' List of files in a folder -#' +#' #' @param project name or id of project (not repository!) #' @param path path of the folder -#' @param ref name of ref (commit branch or tag) +#' @param ref name of ref (commit branch or tag) #' @param ... passed on to [gitlab()] API call #' @importFrom purrr partial #' @export #' @examples \dontrun{ #' # Set GitLab connection for examples #' set_gitlab_connection( -#' gitlab_url = "https://gitlab.com", -#' private_token = Sys.getenv("GITLAB_COM_TOKEN")) +#' gitlab_url = "https://gitlab.com", +#' private_token = Sys.getenv("GITLAB_COM_TOKEN") +#' ) #' -#' gl_list_files(project = <>, path = <>) +#' gl_list_files(project = "<>", path = "<>") #' } gl_list_files <- function(project, path = "", ref = get_main(), ...) { gitlab(gl_proj_req(project, c("repository", "tree"), ...), @@ -100,7 +103,7 @@ gl_file_exists <- function(project, file_path, ref, ...) { } #' Get a file from a GitLab repository -#' +#' #' @param file_path path to file #' @param ref name of ref (commit branch or tag) #' @param to_char flag if output should be converted to char; @@ -159,17 +162,18 @@ gl_get_file <- function(project, #' @param ... passed on to [gitlab()] #' @export #' @rdname onefile -#' +#' #' @examples \dontrun{ #' # Create fake dataset #' tmpfile <- tempfile(fileext = ".csv") #' write.csv(mtcars, file = tmpfile) #' # Push content to repository with a commit #' gl_push_file( -#' project = <>, +#' project = "<>", #' file_path = "test_data.csv", #' content = paste(readLines(tmpfile), collapse = "\n"), -#' commit_message = "New test data") +#' commit_message = "New test data" +#' ) #' } gl_push_file <- function(project, file_path, @@ -178,7 +182,6 @@ gl_push_file <- function(project, branch = get_main(), overwrite = TRUE, ...) { - exists <- gl_file_exists(project = project, file_path, ref = branch, ...) if (!exists || overwrite) { gitlab( @@ -202,8 +205,10 @@ gl_push_file <- function(project, ... ) } else { - tibble::tibble(file_path = character(0), - branch = character(0)) + tibble::tibble( + file_path = character(0), + branch = character(0) + ) } } @@ -234,4 +239,3 @@ gl_delete_file <- function(project, ) } } - diff --git a/R/global_env.R b/R/global_env.R index 57580c6..27eef67 100644 --- a/R/global_env.R +++ b/R/global_env.R @@ -5,15 +5,15 @@ GITLAB_CON <- "gitlab_con" assign(GITLAB_CON, NULL, gitlabr_env) #' Get/set a GitLab connection for all calls -#' -#' This sets the default value of `gitlab_con` +#' +#' This sets the default value of `gitlab_con` #' in a call to [gitlab()] -#' +#' #' @param gitlab_con A function used for GitLab API calls, such #' as [gitlab()] or as returned by [gl_connection()]. #' @param ... if gitlab_con is NULL, a new connection is created used the parameters #' is ... using [gl_connection()] -#' +#' #' @export #' @return Used for side effects. Set or unset global connection settings. #' @examples \dontrun{ @@ -44,11 +44,11 @@ unset_gitlab_connection <- function() { #' @param value option value #' @export #' @return Used for side effect. Populates user [options()] -#' @details +#' @details #' Options accounted for by gitlabr: -#' +#' #' - `gitlabr.main`: Name of the main branch of your repository. Default to "main" in functions. -#' @examples +#' @examples #' # Principal branch is called "master" #' gitlabr_options_set("gitlabr.main", "master") #' # Go back to default option (default branch will be "main") diff --git a/R/groups.R b/R/groups.R index 3fedd04..151ce23 100644 --- a/R/groups.R +++ b/R/groups.R @@ -45,7 +45,7 @@ gl_list_sub_groups <- function(group, ...) { #' as request for functions involving groups #' @examples #' \dontrun{ -#' gl_group_req("test_group"<>) +#' gl_group_req("test_group" = "<>") #' } gl_group_req <- function(group, ...) { if (missing(group) || is.null(group)) { @@ -84,7 +84,7 @@ gl_get_group_id <- function(group_name, ...) { filter( matches_full_path | (sum(matches_full_path) == 0L & - matches_path | matches_name) + matches_path | matches_name) ) if (nrow(matching) == 0) { diff --git a/R/issues.R b/R/issues.R index ed9e638..68aad22 100644 --- a/R/issues.R +++ b/R/issues.R @@ -3,11 +3,10 @@ gl_get_issues <- function(project = NULL, verb = httr::GET, api_version = 4, ...) { - if (api_version == 3) { issue_id <- gl_to_issue_id(issue_id, project, api_version = 3, ...) } - + (if (!missing(project) && is.null(project)) "issues" else gl_proj_req(project, req = c("issues", issue_id), ...)) %>% gitlab(...) %>% iffn(is.null(issue_id), function(issue) { @@ -19,7 +18,7 @@ gl_get_issues <- function(project = NULL, } #' Get issues of a project or user -#' +#' #' @param project project name or id, may be null for all issues created by user. #' If using the ID, set it as numeric, otherwise this is used as project name. #' @param issue_id optional issue id (projectwide; for API v3 only you can use global iid when api_version is `3`) @@ -45,14 +44,16 @@ gl_get_issues <- function(project = NULL, #' # Get one issue #' gl_get_issue("<>", issue_id = 1) #' # Create new issue -#' gl_new_issue("<>", title = "Implement new feature", -#' description = "It should be awesome.") +#' gl_new_issue("<>", +#' title = "Implement new feature", +#' description = "It should be awesome." +#' ) #' # Assign user to issue 1 #' gl_assign_issue("<>", issue_id = 1, assignee_id = "<>") #' } gl_list_issues <- gl_get_issues -#' @details +#' @details #' `gl_get_issue` provides a wrapper with swapped arguments for convenience, esp. when #' using a project connection #' @export @@ -62,29 +63,30 @@ gl_get_issue <- function(project, issue_id, ...) { } #' Translate projectwide issue id to global GitLab API issue id -#' +#' #' This functions is only intended to be used with GitLab API v3. With v4, the #' global iid is no longer functional. -#' +#' #' @param issue_id projectwide issue id (as seen by e.g. GitLab website users) #' @param api_version Since this function is no longer necessary for GitLab API v4, -#' this must be set to 3 in order to avoid deprecation warning and HTTP error. +#' this must be set to 3 in order to avoid deprecation warning and HTTP error. #' @param project project name or id #' @param ... passed on to [gitlab()] -#' +#' #' @importFrom dplyr filter select -#' +#' #' @export #' @return Global GitLab API issue id -#' @examples +#' @examples #' \dontrun{ #' gl_to_issue_id(project = "", issue_id = 1, api_version = 3) #' } gl_to_issue_id <- function(project, issue_id, api_version = 3, ...) { - - if(api_version != 3) { - .Deprecated("gl_get_issue", package = "gitlabr", - msg = "Usage deprecated! gl_to_issue_id can sensibly be used only with GitLab API v3!") + if (api_version != 3) { + .Deprecated("gl_get_issue", + package = "gitlabr", + msg = "Usage deprecated! gl_to_issue_id can sensibly be used only with GitLab API v3!" + ) } if (is.null(issue_id)) { NULL @@ -92,28 +94,31 @@ gl_to_issue_id <- function(project, issue_id, api_version = 3, ...) { (if (missing(project)) { call_filter_dots(gl_get_issues, .dots = list(...), api_version = 3) } else { - call_filter_dots(gl_get_issues, .dots = list(...), project = project, api_version = 3) + call_filter_dots(gl_get_issues, .dots = list(...), project = project, api_version = 3) }) %>% filter(iid == issue_id) %>% select(id) %>% unlist() %>% remove_names() %>% - iff(function(x){length(x) == 0}, function(x) { - stop(paste("No issue with id", issue_id, "in project", project))}) + iff(function(x) { + length(x) == 0 + }, function(x) { + stop(paste("No issue with id", issue_id, "in project", project)) + }) } } #' Post a new issue or edit one -#' +#' #' @param project project where the issue should be posted #' @param title title of the issue -#' @param ... further parameters passed to the API call, may +#' @param ... further parameters passed to the API call, may #' contain description, assignee_id, milestone_id, labels, state_event (for edit_issue). -#' +#' #' @rdname gl_new_issue #' @export #' @return Tibble with the created or remaining issues and descriptive variables. -#' @examples +#' @examples #' \dontrun{ #' # create an issue #' new_issue_infos <- gl_create_issue(project = "<>", "A simple issue") @@ -128,17 +133,19 @@ gl_to_issue_id <- function(project, issue_id, api_version = 3, ...) { #' gl_assign_issue("<>", new_issue_iid, assignee_id = "<>") #' ## unassign it #' gl_unassign_issue("<>", new_issue_iid) -#' ## Delete issue as if it never existed +#' ## Delete issue as if it never existed #' ## (please note that you must have "Owner" role on the Gitlab project) #' gl_delete_issue("<>", new_issue_iid) #' } -gl_new_issue <- function(project, +gl_new_issue <- function(project, title, ...) { - gitlab(req = gl_proj_req(project, "issues", ...), - title = title, - verb = httr::POST, - ...) + gitlab( + req = gl_proj_req(project, "issues", ...), + title = title, + verb = httr::POST, + ... + ) } #' @export @@ -151,24 +158,25 @@ gl_create_issue <- gl_new_issue #' filtering happens by global iid, if false, it happens by projectwide ID. For API v4, this must be 4 (default) #' @export #' @rdname gl_new_issue -gl_edit_issue <- function(project, +gl_edit_issue <- function(project, issue_id, api_version = 4, ...) { - if (api_version == 3) { issue_id <- gl_to_issue_id(project, issue_id, ...) } - - - gitlab(req = gl_proj_req(project, req = c("issues", issue_id), ...), - verb = httr::PUT, - ...) + + + gitlab( + req = gl_proj_req(project, req = c("issues", issue_id), ...), + verb = httr::PUT, + ... + ) } #' @rdname gl_new_issue #' @export -gl_close_issue <- function(project, +gl_close_issue <- function(project, issue_id, ...) { gl_edit_issue(project, issue_id, state_event = "close", ...) @@ -176,7 +184,7 @@ gl_close_issue <- function(project, #' @rdname gl_new_issue #' @export -gl_reopen_issue <- function(project, +gl_reopen_issue <- function(project, issue_id, ...) { gl_edit_issue(project, issue_id, state_event = "reopen", ...) @@ -185,7 +193,7 @@ gl_reopen_issue <- function(project, #' @rdname gl_new_issue #' @param assignee_id numeric id of users as returned in '/users/' API request #' @export -gl_assign_issue <- function(project, +gl_assign_issue <- function(project, issue_id, assignee_id = NULL, ...) { @@ -202,10 +210,12 @@ gl_unassign_issue <- function(project, #' @rdname gl_new_issue #' @export -gl_delete_issue <- function(project, +gl_delete_issue <- function(project, issue_id, - ...) { - gitlab(req = gl_proj_req(project, c("issues", issue_id), ...), - verb = httr::DELETE, - ...) + ...) { + gitlab( + req = gl_proj_req(project, c("issues", issue_id), ...), + verb = httr::DELETE, + ... + ) } diff --git a/R/merge_requests.R b/R/merge_requests.R index d8a2b48..9343997 100644 --- a/R/merge_requests.R +++ b/R/merge_requests.R @@ -1,52 +1,60 @@ #' Manage merge requests -#' +#' #' @param project name or id of project (not repository!) #' @param source_branch name of branch to be merged #' @param target_branch name of branch into which to merge #' @param title title of the merge request #' @param description description text for the merge request #' @param ... passed on to [gitlab()]. Might contain more fields documented in GitLab API doc. -#' +#' #' @export -#' @return Tibble of created or remaining merge requests of the project +#' @return Tibble of created or remaining merge requests of the project #' with informative variables. -#' @examples +#' @examples #' \dontrun{ #' set_gitlab_connection( -#' gitlab_url = "https://gitlab.com", +#' gitlab_url = "https://gitlab.com", #' private_token = Sys.getenv("GITLAB_COM_TOKEN") #' ) #' # Create MR and get its information -#' mr_infos <- gl_create_merge_request(project = <>, +#' mr_infos <- gl_create_merge_request( +#' project = "<>", #' source_branch = "my-extra-branch", -#' title = "Merge extra to main", description = "These modifications are wonderful") +#' title = "Merge extra to main", description = "These modifications are wonderful" +#' ) #' # List all opened MR -#' gl_list_merge_requests(project = <>, status = "opened") +#' gl_list_merge_requests(project = "<>", status = "opened") #' # Edit MR created -#' gl_edit_merge_request(project = <>, merge_request_iid = mr_infos$iid, -#' assignee_id = "<>") +#' gl_edit_merge_request( +#' project = "<>", merge_request_iid = mr_infos$iid, +#' assignee_id = "<>" +#' ) #' # Close MR -#' gl_close_merge_request(project = <>, merge_request_iid = mr_infos$iid) +#' gl_close_merge_request(project = "<>", merge_request_iid = mr_infos$iid) #' # Delete MR as it never existed -#' gl_delete_merge_request(project = <>, merge_request_iid = mr_infos$iid) +#' gl_delete_merge_request(project = "<>", merge_request_iid = mr_infos$iid) #' } gl_create_merge_request <- function(project, source_branch, target_branch = get_main(), title, description, ...) { - gl_proj_req(project = project, c("merge_requests"), ...) %>% - gitlab(source_branch = source_branch, - target_branch = target_branch, - title = title, - description = description, - verb = httr::POST, - ...) + gl_proj_req(project = project, c("merge_requests"), ...) %>% + gitlab( + source_branch = source_branch, + target_branch = target_branch, + title = title, + description = description, + verb = httr::POST, + ... + ) } #' @rdname gl_create_merge_request #' @param merge_request_iid iid of the merge request #' @export gl_edit_merge_request <- function(project, merge_request_iid, ...) { - gl_proj_req(project = project, c("merge_requests", merge_request_iid), ...) %>% - gitlab(verb = httr::PUT, - ...) + gl_proj_req(project = project, c("merge_requests", merge_request_iid), ...) %>% + gitlab( + verb = httr::PUT, + ... + ) } #' @rdname gl_create_merge_request @@ -60,16 +68,19 @@ gl_close_merge_request <- function(project, merge_request_iid) { #' @param merge_request_iid iid of the merge request #' @export gl_delete_merge_request <- function(project, merge_request_iid, ...) { - gl_proj_req(project = project, c("merge_requests", merge_request_iid), ...) %>% - gitlab(verb = httr::DELETE, - ...) + gl_proj_req(project = project, c("merge_requests", merge_request_iid), ...) %>% + gitlab( + verb = httr::DELETE, + ... + ) } #' @rdname gl_create_merge_request #' @export gl_list_merge_requests <- function(project, ...) { - gl_proj_req(project = project, c("merge_requests"), ...) %>% - gitlab(verb = httr::GET, - ...) - + gl_proj_req(project = project, c("merge_requests"), ...) %>% + gitlab( + verb = httr::GET, + ... + ) } diff --git a/R/multilist_to_tibble.R b/R/multilist_to_tibble.R index 6a62722..c723736 100644 --- a/R/multilist_to_tibble.R +++ b/R/multilist_to_tibble.R @@ -10,7 +10,7 @@ #' list(a = 5, b = list("email1"), c = list("4")), #' list(a = 3, b = NULL, c = list("3", "2")) #' ) -#' +#' #' multilist_to_tibble(reprex) multilist_to_tibble <- function(the_list) { if (!is.null(names(the_list))) { @@ -18,12 +18,12 @@ multilist_to_tibble <- function(the_list) { the_list_list[[1]] <- the_list the_list <- the_list_list } - + nullToNA <- function(x) { x[sapply(x, is.null)] <- NA return(x) } - + possible_nullToNA <- function(y) { yna <- possibly(nullToNA, otherwise = "nullToNA fails")(y) if (length(yna) == 1 && !is.na(yna) && yna == "nullToNA fails") { @@ -33,16 +33,13 @@ multilist_to_tibble <- function(the_list) { } return(res) } - + issues_nona <- lapply(the_list, possible_nullToNA) issues_nona <- lapply(issues_nona, function(x) { lapply(x, function(y) possible_nullToNA(y)) }) - - # issues_nona <- lapply(issues_nona, function(x) lapply(x, nullToNA)) - # issues_nona <- lapply(issues_nona, function(x) lapply(x, possibly(nullToNA, otherwise = "nullToNA fails))) - # issues_nona <- lapply(issues_nona, list) - + + to_tibble_list <- function(multilist) { tibble( names = names(multilist), @@ -50,20 +47,9 @@ multilist_to_tibble <- function(the_list) { ) %>% pivot_wider(names_from = names, values_from = content) } - - # issues_nona[[3]] - - # all_tibble <- map_dfr(issues_nona, to_tibble_list) - - # all_unnest <- all_tibble%>% tidyr::unnest(names(.)) # %>% - # tidyr::unnest(names(.)) - # - # all(sapply(all_tibble$url, length) == 1) - + all_tibble <- map_dfr(issues_nona, to_tibble_list) - # all(sapply(all_tibble$labels, length) == 1) - # all(!"list" %in% sapply(all_tibble$labels, is)) - + all_tibble_simple <- all_tibble %>% mutate_if( # Length 1 and not list of list diff --git a/R/projects_and_repos.R b/R/projects_and_repos.R index 8540ac8..ac80364 100644 --- a/R/projects_and_repos.R +++ b/R/projects_and_repos.R @@ -1,14 +1,14 @@ #' List projects information -#' +#' #' @param ... passed on to [gitlab()] #' @export #' @return tibble of each project with corresponding information -#' @details +#' @details #' `gl_list_projects()` is an alias for `gl_get_projects()` -#' +#' #' @examples \dontrun{ #' set_gitlab_connection( -#' gitlab_url = "https://gitlab.com", +#' gitlab_url = "https://gitlab.com", #' private_token = Sys.getenv("GITLAB_COM_TOKEN") #' ) #' # List all projects @@ -49,18 +49,18 @@ gl_get_project <- function(project, ...) { } #' Create a project specific request -#' +#' #' Prefixes the request location with "project/:id" and automatically #' translates project names into ids -#' +#' #' @param project project name or id #' @param req character vector of request location #' @param ... passed on to [gl_get_project_id()] #' @export #' @return A vector of character to be used as request for functions involving projects -#' @examples +#' @examples #' \dontrun{ -#' gl_proj_req("test_project"<>, req = "merge_requests") +#' gl_proj_req("test_project" = "<>", req = "merge_requests") #' } gl_proj_req <- function(project, req, ...) { if (missing(project) || is.null(project)) { @@ -71,16 +71,16 @@ gl_proj_req <- function(project, req, ...) { } #' Get a project id by name -#' +#' #' @param project_name project name #' @param ... passed on to [gitlab()] #' @importFrom dplyr mutate filter -#' -#' @details +#' +#' @details #' Number of pages searched is limited to (per_page =) 20 * (max_page =) 10 by default. -#' If the `project_name` is an old project lost in a big repository (position > 200), +#' If the `project_name` is an old project lost in a big repository (position > 200), #' `gl_get_project_id()` may not find the project id. -#' +#' #' @export #' @return Integer. ID of the project if found. #' @examples @@ -88,40 +88,48 @@ gl_proj_req <- function(project, req, ...) { #' gl_get_project_id("<>") #' } gl_get_project_id <- function(project_name, ...) { - if (is.null(list(...)$simple)) { req <- gitlab(req = "projects", ..., simple = TRUE) } else { req <- gitlab(req = "projects", ...) } - - + + matching <- req %>% - mutate(matches_name = name == project_name, - matches_path = path == project_name, - matches_path_with_namespace = path_with_namespace == project_name) %>% + mutate( + matches_name = name == project_name, + matches_path = path == project_name, + matches_path_with_namespace = path_with_namespace == project_name + ) %>% filter(matches_path_with_namespace | - (sum(matches_path_with_namespace) == 0L & - matches_path | matches_name)) - + (sum(matches_path_with_namespace) == 0L & + matches_path | matches_name)) + if (nrow(matching) == 0) { - stop("There was no matching 'id' with your project name. ", - "Either it does not exist, or most probably, ", - "it is not available in the first projects available to you. ", - "The name-matching is limited to the first pages of projects accessible. ", - "Please use directly the 'id' of your project.") + stop( + "There was no matching 'id' with your project name. ", + "Either it does not exist, or most probably, ", + "it is not available in the first projects available to you. ", + "The name-matching is limited to the first pages of projects accessible. ", + "Please use directly the 'id' of your project." + ) } else if (nrow(matching) > 1) { - warning(paste(c("Multiple projects with given name or path found,", - "please use explicit name with namespace:", - matching$path_with_namespace, - paste("Picking", - matching[1,"path_with_namespace"], - "as default" - )), - collapse = "\n")) + warning(paste( + c( + "Multiple projects with given name or path found,", + "please use explicit name with namespace:", + matching$path_with_namespace, + paste( + "Picking", + matching[1, "path_with_namespace"], + "as default" + ) + ), + collapse = "\n" + )) } - - matching[1,"id"] %>% + + matching[1, "id"] %>% as.integer() } @@ -137,16 +145,16 @@ to_project_id <- function(x, ...) { #' Archive a repository -#' +#' #' @param project Project name or id #' @param ... further parameters passed on to [gitlab()] API call, #' may include parameter `sha` for specifying a commit hash #' @return if save_to_file is NULL, a raw vector of the archive, else the path -#' to the saved archived file +#' to the saved archived file #' @export #' @examples \dontrun{ #' set_gitlab_connection( -#' gitlab_url = "https://gitlab.com", +#' gitlab_url = "https://gitlab.com", #' private_token = Sys.getenv("GITLAB_COM_TOKEN") #' ) #' gl_archive(project = "<>", save_to_file = "example-project.zip") @@ -157,30 +165,32 @@ gl_archive <- function(project, } #' Compare two refs from a project repository -#' +#' #' This function is currently not exported since its output's format is hard to handle -#' +#' #' @noRd -#' +#' #' @param project project name or id #' @param from commit hash or ref/branch/tag name to compare from #' @param to commit hash or ref/branch/tag name to compare to #' @param ... further parameters passed on to [gitlab()] -#' +#' #' @details https://docs.gitlab.com/ce/api/repositories.html#compare-branches-tags-or-commits gl_compare_refs <- function(project, from, to, ...) { - gl_repository(req = "compare", - project = project, - from = from, - to = to, - ...) + gl_repository( + req = "compare", + project = project, + from = from, + to = to, + ... + ) } #' Get commits and diff from a project repository -#' +#' #' @param project project name or id #' @param commit_sha if not null, get only the commit with the specific hash; for #' `gl_get_diff()` this must be specified @@ -188,7 +198,7 @@ gl_compare_refs <- function(project, #' `ref_name` for specifying a branch or tag to list commits of #' @export #' @return Tibble of commits or diff of the branch with informative variables. -#' @examples +#' @examples #' \dontrun{ #' my_commits <- gl_get_commits("<>") #' gl_get_commits("<>", my_commits$id[1]) @@ -196,21 +206,23 @@ gl_compare_refs <- function(project, gl_get_commits <- function(project, commit_sha = c(), ...) { - - gl_repository(project = project, - req = c("commits", commit_sha), - ...) + gl_repository( + project = project, + req = c("commits", commit_sha), + ... + ) } #' @rdname gl_get_commits #' @export -gl_get_diff <- function(project, - commit_sha, - ...) { - - gl_repository(project = project, - req = c("commits", commit_sha, "diff"), - ...) +gl_get_diff <- function(project, + commit_sha, + ...) { + gl_repository( + project = project, + req = c("commits", commit_sha, "diff"), + ... + ) } #' Manage projects @@ -219,14 +231,14 @@ gl_get_diff <- function(project, #' @param ... passed on to [gitlab()] API call for "Create project" #' @export #' @return A tibble with the project information. `gl_delete_project()` returns an empty tibble. -#' @details +#' @details #' You can use extra parameters as proposed in the GitLab API: -#' -#' - `namespace_id`: Namespace for the new project (defaults to the current user’s namespace). -#' +#' +#' - `namespace_id`: Namespace for the new project (defaults to the current user’s namespace). +#' #' @examples \dontrun{ #' set_gitlab_connection( -#' gitlab_url = "https://gitlab.com", +#' gitlab_url = "https://gitlab.com", #' private_token = Sys.getenv("GITLAB_COM_TOKEN") #' ) #' # Create new project @@ -239,51 +251,53 @@ gl_get_diff <- function(project, gl_new_project <- function(name, path, ...) { - if (!missing(path)) { path <- gsub("[[:punct:]]", "-", tolower(path)) - gitlab(req = "projects", - path = path, - verb = httr::POST, - ...) + gitlab( + req = "projects", + path = path, + verb = httr::POST, + ... + ) } else { - gitlab(req = "projects", - name = name, - verb = httr::POST, - ...) + gitlab( + req = "projects", + name = name, + verb = httr::POST, + ... + ) } - - } #' @param project The ID or URL-encoded path of the project. #' @rdname gl_new_project #' @export gl_edit_project <- function(project, - ...) { - - gitlab(req = c("projects", to_project_id(project)), - verb = httr::PUT, - ...) - + ...) { + gitlab( + req = c("projects", to_project_id(project)), + verb = httr::PUT, + ... + ) } #' @rdname gl_new_project #' @export gl_delete_project <- function(project) { - - gitlab(req = c("projects", to_project_id(project)), - verb = httr::DELETE) + gitlab( + req = c("projects", to_project_id(project)), + verb = httr::DELETE + ) } #' List members of a specific project #' @param project The ID or URL-encoded path of the project. #' @param ... passed on to [gitlab()] API call for "project" -#' +#' #' @export #' @examples \dontrun{ #' set_gitlab_connection( -#' gitlab_url = "https://gitlab.com", +#' gitlab_url = "https://gitlab.com", #' private_token = Sys.getenv("GITLAB_COM_TOKEN") #' ) #' gl_list_project_members(project = "<>") @@ -299,7 +313,7 @@ gl_list_project_members <- function(project, ...) { #' @export #' @examples \dontrun{ #' set_gitlab_connection( -#' gitlab_url = "https://gitlab.com", +#' gitlab_url = "https://gitlab.com", #' private_token = Sys.getenv("GITLAB_COM_TOKEN") #' ) #' gl_list_group_members(group = "<>") diff --git a/dev/dev_history.R b/dev/dev_history.R index ed16ae2..13dafcd 100644 --- a/dev/dev_history.R +++ b/dev/dev_history.R @@ -49,6 +49,9 @@ devtools::check(args = c("--no-tests")) rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning") devtools::build_vignettes() +# Style full package ---- +styler::style_pkg() + # Deal with tests ---- devtools::load_all() ## load test environment variables diff --git a/man/branches.Rd b/man/branches.Rd index 550a260..f6d8c41 100644 --- a/man/branches.Rd +++ b/man/branches.Rd @@ -34,22 +34,28 @@ List, create and delete branches } \examples{ \dontrun{ -set_gitlab_connection(gitlab_url = "https://gitlab.com", - private_token = Sys.getenv("GITLAB_COM_TOKEN")) +set_gitlab_connection( + gitlab_url = "https://gitlab.com", + private_token = Sys.getenv("GITLAB_COM_TOKEN") +) project_id <- ... ## Fill in your project ID # List branches of the project -gl_list_branches(project_ = "<>") +gl_list_branches(project_ = "<>") # Create branch "new_feature" -gl_create_branch(project = "<>", - branch = "new_feature") +gl_create_branch( + project = "<>", + branch = "new_feature" +) # Confirm that the branch was created gl_get_branch("<>", branch = "new_feature") # List all branches - this may take some time before your branch really appears there gl_list_branches(project = "<>") # Delete branch again -gl_delete_branch(project = "<>", - branch = "new_feature") +gl_delete_branch( + project = "<>", + branch = "new_feature" +) # Check that we're back where we started gl_list_branches(project = "<>") } diff --git a/man/gl_archive.Rd b/man/gl_archive.Rd index 46d77d6..9585ef0 100644 --- a/man/gl_archive.Rd +++ b/man/gl_archive.Rd @@ -22,7 +22,7 @@ Archive a repository \examples{ \dontrun{ set_gitlab_connection( - gitlab_url = "https://gitlab.com", + gitlab_url = "https://gitlab.com", private_token = Sys.getenv("GITLAB_COM_TOKEN") ) gl_archive(project = "<>", save_to_file = "example-project.zip") diff --git a/man/gl_comments.Rd b/man/gl_comments.Rd index f07c682..698eb0f 100644 --- a/man/gl_comments.Rd +++ b/man/gl_comments.Rd @@ -66,12 +66,18 @@ comment of an issue. \examples{ \dontrun{ # fill in login parameters -set_gitlab_connection(gitlab_url = "https://gitlab.com", - private_token = Sys.getenv("GITLAB_COM_TOKEN")) +set_gitlab_connection( + gitlab_url = "https://gitlab.com", + private_token = Sys.getenv("GITLAB_COM_TOKEN") +) gl_get_comments(project = "<>", object_type = "issue", 1) -gl_get_comments(project = "<>", "commit", - id = "8ce5ef240123cd78c1537991e5de8d8323666b15") -gl_comment_issue(project = "<>", 1, - text = "Almost done!") +gl_get_comments( + project = "<>", "commit", + id = "8ce5ef240123cd78c1537991e5de8d8323666b15" +) +gl_comment_issue( + project = "<>", 1, + text = "Almost done!" +) } } diff --git a/man/gl_create_merge_request.Rd b/man/gl_create_merge_request.Rd index 95096a5..9994579 100644 --- a/man/gl_create_merge_request.Rd +++ b/man/gl_create_merge_request.Rd @@ -50,21 +50,25 @@ Manage merge requests \examples{ \dontrun{ set_gitlab_connection( - gitlab_url = "https://gitlab.com", + gitlab_url = "https://gitlab.com", private_token = Sys.getenv("GITLAB_COM_TOKEN") ) # Create MR and get its information -mr_infos <- gl_create_merge_request(project = <>, +mr_infos <- gl_create_merge_request( + project = "<>", source_branch = "my-extra-branch", - title = "Merge extra to main", description = "These modifications are wonderful") + title = "Merge extra to main", description = "These modifications are wonderful" +) # List all opened MR -gl_list_merge_requests(project = <>, status = "opened") +gl_list_merge_requests(project = "<>", status = "opened") # Edit MR created -gl_edit_merge_request(project = <>, merge_request_iid = mr_infos$iid, - assignee_id = "<>") +gl_edit_merge_request( + project = "<>", merge_request_iid = mr_infos$iid, + assignee_id = "<>" +) # Close MR -gl_close_merge_request(project = <>, merge_request_iid = mr_infos$iid) +gl_close_merge_request(project = "<>", merge_request_iid = mr_infos$iid) # Delete MR as it never existed -gl_delete_merge_request(project = <>, merge_request_iid = mr_infos$iid) +gl_delete_merge_request(project = "<>", merge_request_iid = mr_infos$iid) } } diff --git a/man/gl_group_req.Rd b/man/gl_group_req.Rd index a7263b6..f3207af 100644 --- a/man/gl_group_req.Rd +++ b/man/gl_group_req.Rd @@ -21,6 +21,6 @@ translates group names into ids } \examples{ \dontrun{ -gl_group_req("test_group"<>) +gl_group_req("test_group" = "<>") } } diff --git a/man/gl_list_files.Rd b/man/gl_list_files.Rd index 2f7f957..af4076a 100644 --- a/man/gl_list_files.Rd +++ b/man/gl_list_files.Rd @@ -22,9 +22,10 @@ List of files in a folder \dontrun{ # Set GitLab connection for examples set_gitlab_connection( - gitlab_url = "https://gitlab.com", - private_token = Sys.getenv("GITLAB_COM_TOKEN")) + gitlab_url = "https://gitlab.com", + private_token = Sys.getenv("GITLAB_COM_TOKEN") +) -gl_list_files(project = <>, path = <>) +gl_list_files(project = "<>", path = "<>") } } diff --git a/man/gl_list_group_members.Rd b/man/gl_list_group_members.Rd index 605c1b6..936e385 100644 --- a/man/gl_list_group_members.Rd +++ b/man/gl_list_group_members.Rd @@ -17,7 +17,7 @@ List members of a specific group \examples{ \dontrun{ set_gitlab_connection( - gitlab_url = "https://gitlab.com", + gitlab_url = "https://gitlab.com", private_token = Sys.getenv("GITLAB_COM_TOKEN") ) gl_list_group_members(group = "<>") diff --git a/man/gl_list_issues.Rd b/man/gl_list_issues.Rd index 2ef3898..6b6dcce 100644 --- a/man/gl_list_issues.Rd +++ b/man/gl_list_issues.Rd @@ -54,8 +54,10 @@ gl_list_issues("<>", state = "opened") # Get one issue gl_get_issue("<>", issue_id = 1) # Create new issue -gl_new_issue("<>", title = "Implement new feature", - description = "It should be awesome.") +gl_new_issue("<>", + title = "Implement new feature", + description = "It should be awesome." +) # Assign user to issue 1 gl_assign_issue("<>", issue_id = 1, assignee_id = "<>") } diff --git a/man/gl_list_project_members.Rd b/man/gl_list_project_members.Rd index 72b4598..3f76655 100644 --- a/man/gl_list_project_members.Rd +++ b/man/gl_list_project_members.Rd @@ -17,7 +17,7 @@ List members of a specific project \examples{ \dontrun{ set_gitlab_connection( - gitlab_url = "https://gitlab.com", + gitlab_url = "https://gitlab.com", private_token = Sys.getenv("GITLAB_COM_TOKEN") ) gl_list_project_members(project = "<>") diff --git a/man/gl_list_projects.Rd b/man/gl_list_projects.Rd index 54b1de7..10a51b6 100644 --- a/man/gl_list_projects.Rd +++ b/man/gl_list_projects.Rd @@ -39,7 +39,7 @@ List projects information \examples{ \dontrun{ set_gitlab_connection( - gitlab_url = "https://gitlab.com", + gitlab_url = "https://gitlab.com", private_token = Sys.getenv("GITLAB_COM_TOKEN") ) # List all projects diff --git a/man/gl_new_issue.Rd b/man/gl_new_issue.Rd index 7814183..3e1d737 100644 --- a/man/gl_new_issue.Rd +++ b/man/gl_new_issue.Rd @@ -63,7 +63,7 @@ gl_edit_issue("<>", new_issue_iid, description = "This is a tes gl_assign_issue("<>", new_issue_iid, assignee_id = "<>") ## unassign it gl_unassign_issue("<>", new_issue_iid) -## Delete issue as if it never existed +## Delete issue as if it never existed ## (please note that you must have "Owner" role on the Gitlab project) gl_delete_issue("<>", new_issue_iid) } diff --git a/man/gl_new_project.Rd b/man/gl_new_project.Rd index 4858a66..5072230 100644 --- a/man/gl_new_project.Rd +++ b/man/gl_new_project.Rd @@ -36,7 +36,7 @@ You can use extra parameters as proposed in the GitLab API: \examples{ \dontrun{ set_gitlab_connection( - gitlab_url = "https://gitlab.com", + gitlab_url = "https://gitlab.com", private_token = Sys.getenv("GITLAB_COM_TOKEN") ) # Create new project diff --git a/man/gl_proj_req.Rd b/man/gl_proj_req.Rd index 777437f..6f0c3e4 100644 --- a/man/gl_proj_req.Rd +++ b/man/gl_proj_req.Rd @@ -22,6 +22,6 @@ translates project names into ids } \examples{ \dontrun{ -gl_proj_req("test_project"<>, req = "merge_requests") +gl_proj_req("test_project" = "<>", req = "merge_requests") } } diff --git a/man/gl_repository.Rd b/man/gl_repository.Rd index fddb344..2c73475 100644 --- a/man/gl_repository.Rd +++ b/man/gl_repository.Rd @@ -52,20 +52,22 @@ Get a file from a GitLab repository \dontrun{ # Set GitLab connection for examples set_gitlab_connection( - gitlab_url = "https://gitlab.com", - private_token = Sys.getenv("GITLAB_COM_TOKEN")) + gitlab_url = "https://gitlab.com", + private_token = Sys.getenv("GITLAB_COM_TOKEN") +) # Access repository # _All files -gl_repository(project = <>) +gl_repository(project = "<>") # _All contributors -gl_repository(project = <>, "contributors") +gl_repository(project = "<>", "contributors") # _Get content of one file -gl_get_file(project = <>, file_path = "README.md") +gl_get_file(project = "<>", file_path = "README.md") # _Test if file exists gl_file_exists( - project = <>, + project = "<>", file_path = "README.md", - ref = "main") + ref = "main" +) } } diff --git a/man/onefile.Rd b/man/onefile.Rd index aa66525..c7a151c 100644 --- a/man/onefile.Rd +++ b/man/onefile.Rd @@ -48,9 +48,10 @@ tmpfile <- tempfile(fileext = ".csv") write.csv(mtcars, file = tmpfile) # Push content to repository with a commit gl_push_file( - project = <>, + project = "<>", file_path = "test_data.csv", content = paste(readLines(tmpfile), collapse = "\n"), - commit_message = "New test data") + commit_message = "New test data" +) } } diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 9af7556..b0c56b4 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -41,17 +41,18 @@ if (grepl("master", test_project_name)) { set_gitlab_connection( gitlab_url = test_url, private_token = test_private_token, - api_version = test_api_version) + api_version = test_api_version +) # Set project connection for all tests my_project <- gl_project_connection( gitlab_url = test_url, project = test_project, private_token = test_private_token, - api_version = test_api_version) + api_version = test_api_version +) # There are too many users on GitLab.com and you may not appear in the first ones, # you will need to set your ID and project ID test_user <- as.numeric(test_user_id) test_project <- as.numeric(test_project_id) - diff --git a/tests/testthat/test_connection_env.R b/tests/testthat/test_connection_env.R index 62aa65a..69af7fc 100644 --- a/tests/testthat/test_connection_env.R +++ b/tests/testthat/test_connection_env.R @@ -5,9 +5,9 @@ test_that("gitlabr_options_set works", { expect_equal(get_main(), getOption("gitlabr.main", default = "main")) old.option <- get_main() gitlabr_options_set("gitlabr.main", NULL) - expect_equal(get_main(), 'main') + expect_equal(get_main(), "main") gitlabr_options_set("gitlabr.main", "toto") - expect_equal(get_main(), 'toto') + expect_equal(get_main(), "toto") gitlabr_options_set("gitlabr.main", old.option) }) @@ -19,7 +19,8 @@ unset_gitlab_connection() my_gitlab_test <- gl_connection( gitlab_url = test_url, private_token = test_private_token, - api_version = test_api_version) + api_version = test_api_version +) # Note that we cannot compare directly all outputs because GitLab projects are actively increasing # Instead, we will only check for project owned by the user with `owned = TRUE` @@ -29,31 +30,32 @@ my_gitlab_test <- gl_connection( # Also order may change for same reasons # Way 1 -my_gitlab_projects_output_raw <- my_gitlab_test("projects", max_page = 1, owned = TRUE) %>% +my_gitlab_projects_output_raw <- my_gitlab_test("projects", max_page = 1, owned = TRUE) %>% filter(grepl("^demo", name)) # Way_2 -my_gitlab_list_projects_output_raw <- my_gitlab_test(gl_list_projects, max_page = 1, owned = TRUE) %>% +my_gitlab_list_projects_output_raw <- my_gitlab_test(gl_list_projects, max_page = 1, owned = TRUE) %>% filter(grepl("^demo", name)) # Way_3 gitlab_projects_api_raw <- gitlab("projects", - api_root = paste0(test_url, "/api/v", test_api_version, "/"), - private_token = test_private_token, - max_page = 1, owned = TRUE) %>% + api_root = paste0(test_url, "/api/v", test_api_version, "/"), + private_token = test_private_token, + max_page = 1, owned = TRUE +) %>% filter(grepl("^demo", name)) # Way_4 -gl_list_projects_output_raw <- gl_list_projects(gitlab_con = my_gitlab_test, max_page = 1, owned = TRUE) %>% +gl_list_projects_output_raw <- gl_list_projects(gitlab_con = my_gitlab_test, max_page = 1, owned = TRUE) %>% filter(grepl("^demo", name)) -# names with dots [.] only exist if there are sub-lists. +# names with dots [.] only exist if there are sub-lists. # This is not always the case depending on projects. # Names without dots are also not always existing fields, apparently -names_1 <- names(my_gitlab_projects_output_raw)#[!grepl("[.]", names(my_gitlab_projects_output_raw))] -names_2 <- names(my_gitlab_list_projects_output_raw)#[!grepl("[.]", names(my_gitlab_list_projects_output_raw))] -names_3 <- names(gitlab_projects_api_raw)#[!grepl("[.]", names(gitlab_projects_api_raw))] -names_4 <- names(gl_list_projects_output_raw)#[!grepl("[.]", names(gl_list_projects_output_raw))] +names_1 <- names(my_gitlab_projects_output_raw) # [!grepl("[.]", names(my_gitlab_projects_output_raw))] +names_2 <- names(my_gitlab_list_projects_output_raw) # [!grepl("[.]", names(my_gitlab_list_projects_output_raw))] +names_3 <- names(gitlab_projects_api_raw) # [!grepl("[.]", names(gitlab_projects_api_raw))] +names_4 <- names(gl_list_projects_output_raw) # [!grepl("[.]", names(gl_list_projects_output_raw))] all_same <- function(.x) (isTRUE(all(is.na(.x)) || all(.x == .x[1]))) # all_same(1:4) @@ -68,32 +70,33 @@ all_same <- function(.x) (isTRUE(all(is.na(.x)) || all(.x == .x[1]))) # Retrieve all projects in common to be sure all infos are there, and missing one are empty # Get id present in all four ways -id_common <- - bind_rows(my_gitlab_projects_output_raw, - my_gitlab_list_projects_output_raw, - gitlab_projects_api_raw, - gl_list_projects_output_raw) %>% - group_by(id) %>% - mutate(n = n()) %>% +id_common <- + bind_rows( + my_gitlab_projects_output_raw, + my_gitlab_list_projects_output_raw, + gitlab_projects_api_raw, + gl_list_projects_output_raw + ) %>% + group_by(id) %>% + mutate(n = n()) %>% # id in all four ways - filter(n == 4) %>% - # ungroup() %>% - # filter(id == first(id)) %>% + filter(n == 4) %>% + # ungroup() %>% + # filter(id == first(id)) %>% # All values equal to first one - summarise_all(all_same) %>% - select(-id) %>% - summarise_all(all) %>% + summarise_all(all_same) %>% + select(-id) %>% + summarise_all(all) %>% unlist() test_that("GitLab connection creation works", { - expect_equal(class(my_gitlab_test), "function") - + expect_s3_class(my_gitlab_projects_output_raw, "data.frame") expect_s3_class(my_gitlab_list_projects_output_raw, "data.frame") expect_s3_class(gitlab_projects_api_raw, "data.frame") expect_s3_class(gl_list_projects_output_raw, "data.frame") - + # one page is 20 lines max expect_lte(nrow(my_gitlab_projects_output_raw), 20) expect_lte(nrow(my_gitlab_list_projects_output_raw), 20) @@ -114,14 +117,15 @@ test_that("GitLab connection creation works", { expect_equal(my_gitlab_projects_output_raw, my_gitlab_list_projects_output_raw) expect_equal(my_gitlab_projects_output_raw, gitlab_projects_api_raw) expect_equal(my_gitlab_projects_output_raw, gl_list_projects_output_raw) - + # All values are the same (everything should be TRUE) if (length(names(id_common[id_common == FALSE]) != 0)) { - warning("Names with not common info: ", - paste(names(id_common[id_common == FALSE]), collapse = ", ")) + warning( + "Names with not common info: ", + paste(names(id_common[id_common == FALSE]), collapse = ", ") + ) } expect_equal(names(id_common[id_common == FALSE]), character(0)) - }) # Test list ok even if not owned ---- @@ -131,7 +135,7 @@ my_gitlab_projects_all_public <- my_gitlab_test("projects", max_page = 1) test_that("Access to all public repo works", { expect_lte(nrow(my_gitlab_projects_owned), 20) expect_equal(nrow(my_gitlab_projects_all_public), 20) - + # There may be one in common because CI updates users' projects # There should be at least one difference fi user does not create 20 repo at the same time expect_true(any(my_gitlab_projects_owned[["id"]] != my_gitlab_projects_all_public[["id"]])) @@ -143,86 +147,89 @@ my_project <- gl_project_connection( gitlab_url = test_url, project = test_project, private_token = test_private_token, - api_version = test_api_version) + api_version = test_api_version +) my_project_list_files <- my_project(gl_list_files, max_page = 1) my_gl_list_files <- gl_list_files(gitlab_con = my_project, max_page = 1) test_that("Project connection creation works", { - expect_equal(class(my_project), "function") - + expect_s3_class(my_project_list_files, "data.frame") expect_s3_class(my_gl_list_files, "data.frame") - + # Use expect_equal(ignore_attr = TRUE) ? - expect_equal(my_project_list_files, - my_gl_list_files) + expect_equal( + my_project_list_files, + my_gl_list_files + ) }) # set_gitlab_connection ---- set_gitlab_connection(my_gitlab_test) # Note that we cannot compare directly all outputs because GitLab projects are actively increasing # Way_0 - gitlab_connection already set -gitlab_projects_raw <- gitlab("projects", max_page = 1, owned = TRUE) %>% +gitlab_projects_raw <- gitlab("projects", max_page = 1, owned = TRUE) %>% filter(grepl("^demo", name)) # Way 1 - gitlab_connection already set -my_gitlab_projects_self_raw <- my_gitlab_test("projects", gitlab_con = "self", max_page = 1, owned = TRUE) %>% +my_gitlab_projects_self_raw <- my_gitlab_test("projects", gitlab_con = "self", max_page = 1, owned = TRUE) %>% filter(grepl("^demo", name)) # Way_2 - gitlab_connection already set -my_gitlab_list_projects_self_raw <- my_gitlab_test(gl_list_projects, gitlab_con = "self", max_page = 1, owned = TRUE) %>% +my_gitlab_list_projects_self_raw <- my_gitlab_test(gl_list_projects, gitlab_con = "self", max_page = 1, owned = TRUE) %>% filter(grepl("^demo", name)) # Way_4 - gitlab_connection already set -gl_list_projects_empty_raw <- gl_list_projects(max_page = 1, owned = TRUE) %>% +gl_list_projects_empty_raw <- gl_list_projects(max_page = 1, owned = TRUE) %>% filter(grepl("^demo", name)) -# names with dots [.] only exist if there are sub-lists. +# names with dots [.] only exist if there are sub-lists. # This is not always the case depending on projects. # Names without dots are mandatory fields, apparently -names_0 <- names(gitlab_projects_raw)#[!grepl("[.]", names(gitlab_projects_raw))] -names_1 <- names(my_gitlab_projects_self_raw)#[!grepl("[.]", names(my_gitlab_projects_self_raw))] -names_2 <- names(my_gitlab_list_projects_self_raw)#[!grepl("[.]", names(my_gitlab_list_projects_self_raw))] -names_4 <- names(gl_list_projects_empty_raw)#[!grepl("[.]", names(gl_list_projects_empty_raw))] +names_0 <- names(gitlab_projects_raw) # [!grepl("[.]", names(gitlab_projects_raw))] +names_1 <- names(my_gitlab_projects_self_raw) # [!grepl("[.]", names(my_gitlab_projects_self_raw))] +names_2 <- names(my_gitlab_list_projects_self_raw) # [!grepl("[.]", names(my_gitlab_list_projects_self_raw))] +names_4 <- names(gl_list_projects_empty_raw) # [!grepl("[.]", names(gl_list_projects_empty_raw))] # Retrieve all projects in common to be sure all infos are there, and missing one are empty # Get id present in all four ways -id_common <- - bind_rows(gitlab_projects_raw, - my_gitlab_projects_self_raw, - my_gitlab_list_projects_self_raw, - gl_list_projects_empty_raw) %>% - group_by(id) %>% - mutate(n = n()) %>% +id_common <- + bind_rows( + gitlab_projects_raw, + my_gitlab_projects_self_raw, + my_gitlab_list_projects_self_raw, + gl_list_projects_empty_raw + ) %>% + group_by(id) %>% + mutate(n = n()) %>% # id in all four ways - filter(n == 4) %>% - # ungroup() %>% - # filter(id == first(id)) %>% + filter(n == 4) %>% + # ungroup() %>% + # filter(id == first(id)) %>% # All values equal to first one - summarise_all(all_same) %>% - select(-id) %>% - summarise_all(all) %>% + summarise_all(all_same) %>% + select(-id) %>% + summarise_all(all) %>% unlist() test_that("set_gl_connection works", { - expect_equal(class(gitlab), "function") - + expect_s3_class(gitlab_projects_raw, "data.frame") expect_s3_class(my_gitlab_projects_self_raw, "data.frame") expect_s3_class(my_gitlab_list_projects_self_raw, "data.frame") expect_s3_class(gl_list_projects_empty_raw, "data.frame") - + # one page is 20 lines max expect_lte(nrow(gitlab_projects_raw), 20) expect_lte(nrow(my_gitlab_projects_self_raw), 20) expect_lte(nrow(my_gitlab_list_projects_self_raw), 20) expect_lte(nrow(gl_list_projects_empty_raw), 20) - + # Col names in common should be greater than zero expect_gt(length(names_1[names_1 %in% names_2]), 0) expect_gt(length(names_1[names_1 %in% names_0]), 0) @@ -230,18 +237,20 @@ test_that("set_gl_connection works", { expect_gt(length(names_2[names_2 %in% names_1]), 0) expect_gt(length(names_2[names_2 %in% names_4]), 0) expect_gt(length(names_4[names_4 %in% names_0]), 0) - + # We keep only user projects # All projects should be the same (if user does not add a project during CI) # Except for last_activity_at that can change during and because of CI expect_equal(gitlab_projects_raw, my_gitlab_projects_self_raw) expect_equal(gitlab_projects_raw, my_gitlab_list_projects_self_raw) expect_equal(gitlab_projects_raw, gl_list_projects_empty_raw) - + # All values are the same (everything should be TRUE) if (length(names(id_common[id_common == FALSE]) != 0)) { - warning("Names with not common info: ", - paste(names(id_common[id_common == FALSE]), collapse = ", ")) + warning( + "Names with not common info: ", + paste(names(id_common[id_common == FALSE]), collapse = ", ") + ) } expect_equal(names(id_common[id_common == FALSE]), character(0)) }) @@ -250,69 +259,72 @@ unset_gitlab_connection() # set_gitlab_connection with dots ---- ## using dots -set_gitlab_connection(gitlab_url = test_url, - private_token = test_private_token, - api_version = test_api_version) +set_gitlab_connection( + gitlab_url = test_url, + private_token = test_private_token, + api_version = test_api_version +) # Note that we cannot compare directly all outputs because GitLab projects are actively increasing # Way_0 - gitlab_connection already set -gitlab_projects_raw <- gitlab("projects", max_page = 1, owned = TRUE) %>% +gitlab_projects_raw <- gitlab("projects", max_page = 1, owned = TRUE) %>% filter(grepl("^demo", name)) # Way 1 - gitlab_connection already set -my_gitlab_projects_self_raw <- my_gitlab_test("projects", gitlab_con = "self", max_page = 1, owned = TRUE) %>% +my_gitlab_projects_self_raw <- my_gitlab_test("projects", gitlab_con = "self", max_page = 1, owned = TRUE) %>% filter(grepl("^demo", name)) # Way_2 - gitlab_connection already set -my_gitlab_list_projects_self_raw <- my_gitlab_test(gl_list_projects, gitlab_con = "self", max_page = 1, owned = TRUE) %>% +my_gitlab_list_projects_self_raw <- my_gitlab_test(gl_list_projects, gitlab_con = "self", max_page = 1, owned = TRUE) %>% filter(grepl("^demo", name)) # Way_4 - gitlab_connection already set -gl_list_projects_empty_raw <- gl_list_projects(max_page = 1, owned = TRUE) %>% +gl_list_projects_empty_raw <- gl_list_projects(max_page = 1, owned = TRUE) %>% filter(grepl("^demo", name)) -# names with dots [.] only exist if there are sub-lists. +# names with dots [.] only exist if there are sub-lists. # This is not always the case depending on projects. # Names without dots are mandatory fields, apparently -names_0 <- names(gitlab_projects_raw)#[!grepl("[.]", names(gitlab_projects_raw))] -names_1 <- names(my_gitlab_projects_self_raw)#[!grepl("[.]", names(my_gitlab_projects_self_raw))] -names_2 <- names(my_gitlab_list_projects_self_raw)#[!grepl("[.]", names(my_gitlab_list_projects_self_raw))] -names_4 <- names(gl_list_projects_empty_raw)#[!grepl("[.]", names(gl_list_projects_empty_raw))] +names_0 <- names(gitlab_projects_raw) # [!grepl("[.]", names(gitlab_projects_raw))] +names_1 <- names(my_gitlab_projects_self_raw) # [!grepl("[.]", names(my_gitlab_projects_self_raw))] +names_2 <- names(my_gitlab_list_projects_self_raw) # [!grepl("[.]", names(my_gitlab_list_projects_self_raw))] +names_4 <- names(gl_list_projects_empty_raw) # [!grepl("[.]", names(gl_list_projects_empty_raw))] # Retrieve all projects in common to be sure all infos are there, and missing one are empty # Get id present in all four ways -id_common <- - bind_rows(gitlab_projects_raw, - my_gitlab_projects_self_raw, - my_gitlab_list_projects_self_raw, - gl_list_projects_empty_raw) %>% - group_by(id) %>% - mutate(n = n()) %>% +id_common <- + bind_rows( + gitlab_projects_raw, + my_gitlab_projects_self_raw, + my_gitlab_list_projects_self_raw, + gl_list_projects_empty_raw + ) %>% + group_by(id) %>% + mutate(n = n()) %>% # id in all four ways - filter(n == 4) %>% - # ungroup() %>% - # filter(id == first(id)) %>% + filter(n == 4) %>% + # ungroup() %>% + # filter(id == first(id)) %>% # All values equal to first one - summarise_all(all_same) %>% - select(-id) %>% - summarise_all(all) %>% + summarise_all(all_same) %>% + select(-id) %>% + summarise_all(all) %>% unlist() test_that("set_gl_connection with dots works", { - expect_equal(class(gitlab), "function") - + expect_s3_class(gitlab_projects_raw, "data.frame") expect_s3_class(my_gitlab_projects_self_raw, "data.frame") expect_s3_class(my_gitlab_list_projects_self_raw, "data.frame") expect_s3_class(gl_list_projects_empty_raw, "data.frame") - + # one page is 20 lines expect_lte(nrow(gitlab_projects_raw), 20) expect_lte(nrow(my_gitlab_projects_self_raw), 20) expect_lte(nrow(my_gitlab_list_projects_self_raw), 20) expect_lte(nrow(gl_list_projects_empty_raw), 20) - + # Col names in common should be greater than zero expect_gt(length(names_1[names_1 %in% names_2]), 0) expect_gt(length(names_1[names_1 %in% names_0]), 0) @@ -320,22 +332,23 @@ test_that("set_gl_connection with dots works", { expect_gt(length(names_2[names_2 %in% names_1]), 0) expect_gt(length(names_2[names_2 %in% names_4]), 0) expect_gt(length(names_4[names_4 %in% names_0]), 0) - + # We keep only user projects # All projects should be the same (if user does not add a project during CI) # Except for last_activity_at that can change during and because of CI expect_equal(gitlab_projects_raw, my_gitlab_projects_self_raw) expect_equal(gitlab_projects_raw, my_gitlab_list_projects_self_raw) expect_equal(gitlab_projects_raw, gl_list_projects_empty_raw) - + # All values are the same (everything should be TRUE) # expect_equal(which(!id_common[1,]), 0) if (length(names(id_common[id_common == FALSE]) != 0)) { - warning("Names with not common info: ", - paste(names(id_common[id_common == FALSE]), collapse = ", ")) + warning( + "Names with not common info: ", + paste(names(id_common[id_common == FALSE]), collapse = ", ") + ) } expect_equal(names(id_common[id_common == FALSE]), character(0)) - }) unset_gitlab_connection() @@ -343,5 +356,5 @@ unset_gitlab_connection() set_gitlab_connection( gitlab_url = test_url, private_token = test_private_token, - api_version = test_api_version) - + api_version = test_api_version +) diff --git a/tests/testthat/test_groups.R b/tests/testthat/test_groups.R index e1aceba..317a139 100644 --- a/tests/testthat/test_groups.R +++ b/tests/testthat/test_groups.R @@ -12,27 +12,30 @@ test_that("gl_list_sub_groups works", { subgroup_list <- gl_list_sub_groups(test_group_id) if (nrow(subgroup_list) >= 1) { - # Only work if user is member of the group with a subgroup - # expect_gte(nrow(subgroup_list), 1) expect_true(all(c("id", "name", "path") %in% names(subgroup_list))) if (test_group_name == "thinkr-open") { - expect_true("dontdelete.subgroup.for.gitlabr" %in% subgroup_list[["name"]]) + expect_true( + "dontdelete.subgroup.for.gitlabr" %in% subgroup_list[["name"]] + ) } } }) -test_that("gl_get_group_id works", { - expect_equal( - as.character( - gl_get_group_id(Sys.getenv("GITLABR_TEST_GROUP_NAME")) - ), - Sys.getenv("GITLABR_TEST_GROUP_ID") - ) -}) # Dont test to avoid GitLab rejection. if (interactive()) { + test_that("gl_get_group_id works", { + # This test may fail if you are member + # of a lot of groups on GitLab + expect_equal( + as.character( + gl_get_group_id(Sys.getenv("GITLABR_TEST_GROUP_NAME")) + ), + Sys.getenv("GITLABR_TEST_GROUP_ID") + ) + }) + if (!grepl("gitlab[.]com", Sys.getenv("GITLABR_TEST_URL"))) { # Forbidden on GitLab SaaS new_group <- gl_new_group( diff --git a/tests/testthat/test_merge_requests.R b/tests/testthat/test_merge_requests.R index 9ddb089..92798da 100644 --- a/tests/testthat/test_merge_requests.R +++ b/tests/testthat/test_merge_requests.R @@ -1,27 +1,28 @@ # gl_create_merge_request ---- -the_mr <- gl_create_merge_request(test_project, - source_branch = "for-tests", target_branch = get_main(), - title = "Test MR", - description = "Test description") +the_mr <- gl_create_merge_request(test_project, + source_branch = "for-tests", target_branch = get_main(), + title = "Test MR", + description = "Test description" +) all_mr <- gl_list_merge_requests(test_project) all_opened_mr <- gl_list_merge_requests(test_project, state = "opened") -test_that('mr correclty created', { +test_that("mr correclty created", { expect_true(any(the_mr$iid == all_mr$iid)) expect_equal(nrow(all_opened_mr), 1) expect_true(the_mr$iid == all_opened_mr$iid) }) -test_that('mr correclty closed and deleted', { +test_that("mr correclty closed and deleted", { # close gl_close_merge_request(project = test_project, merge_request_iid = the_mr$iid) all_opened_mr <- gl_list_merge_requests(test_project, state = "opened") expect_equal(nrow(all_opened_mr), 0) all_closed_mr <- gl_list_merge_requests(test_project, state = "closed") expect_true(any(the_mr$iid == all_closed_mr$iid)) - + # delete gl_delete_merge_request(project = test_project, merge_request_iid = the_mr$iid) all_remaining_mr <- gl_list_merge_requests(test_project) diff --git a/tests/testthat/test_projects_repos.R b/tests/testthat/test_projects_repos.R index bd3910b..e6aa172 100644 --- a/tests/testthat/test_projects_repos.R +++ b/tests/testthat/test_projects_repos.R @@ -44,13 +44,14 @@ test_that("gl_proj_req works", { # gl_get_project_id ---- # Can not be really tested because gitlab.com is too big # except with user namespace ? No -# => Assume that the last modified is the current project +# => Assume that the last modified is the current project # because of unit tests -the_retrieved_id <- gl_get_project_id(test_project_name, - max_page = 3, owned = TRUE, - order_by = "last_activity_at") -# gitlab(req = "projects", -# gitlab_url = file.path(test_url, all_user_projects$namespace.path[1]), +the_retrieved_id <- gl_get_project_id(test_project_name, + max_page = 3, owned = TRUE, + order_by = "last_activity_at" +) +# gitlab(req = "projects", +# gitlab_url = file.path(test_url, all_user_projects$namespace.path[1]), # max_page = 1, owned = TRUE) test_that("gl_get_project_id works", { expect_equal(as.character(the_retrieved_id), test_project_id) @@ -65,26 +66,24 @@ test_that("gl_get_project_id works", { # to = "6b9d22115a93ab009d64f857dca346c0e105d64a") # test_that("Compare works", { -# +# # expect_s3_class(my_gitlab(compare_refs # , test_project # , "f6a96d975d9acf708560aac120ac1712a89f2a0c" # , "ea86a3a8a22b528300c03f9bcf0dc91f81db4087") # , "data.frame") -# +# # }) # gl_get_commits ---- my_commits <- gl_get_commits(test_project, ref_name = get_main()) test_that("Commits work", { - my_commit <- gl_get_commits(test_project, commit_sha = my_commits$id[1]) - + expect_s3_class(my_commits, "data.frame") expect_s3_class(my_commit, "data.frame") expect_gt(length(intersect(names(my_commits), names(my_commit))), 0L) - }) @@ -94,11 +93,9 @@ test_that("Commits work", { the_diff <- gl_get_diff(test_project, my_commits$short_id[1]) test_that("gl_get_diff work", { - expect_s3_class(the_diff, "data.frame") expect_equal(nrow(the_diff), 1) - expect_equal(the_diff$old_path, '.gitlab-ci.yml') - + expect_equal(the_diff$old_path, ".gitlab-ci.yml") }) # gl_new_project ---- @@ -126,4 +123,3 @@ test_that("gl_edit_project work", { # gl_delete_project ---- # Dont test delete project because this example project is needed... - From b2b65fec063764d8fc9b0e50bf12f3d0ac3588dc Mon Sep 17 00:00:00 2001 From: StatnMap Date: Wed, 15 May 2024 11:03:16 +0200 Subject: [PATCH 4/7] fix: missing return values --- R/files.R | 3 +++ R/multilist_to_tibble.R | 2 ++ R/projects_and_repos.R | 3 ++- man/gl_list_files.Rd | 3 +++ man/gl_list_group_members.Rd | 3 +++ man/gl_list_project_members.Rd | 3 +++ man/multilist_to_tibble.Rd | 3 +++ 7 files changed, 19 insertions(+), 1 deletion(-) diff --git a/R/files.R b/R/files.R index 405460e..3529be7 100644 --- a/R/files.R +++ b/R/files.R @@ -39,6 +39,9 @@ gl_repository <- function(project, req = c("tree"), ref = get_main(), ...) { #' @param path path of the folder #' @param ref name of ref (commit branch or tag) #' @param ... passed on to [gitlab()] API call +#' +#' @return Tibble of files available in the branch with descriptive variables. +#' #' @importFrom purrr partial #' @export #' @examples \dontrun{ diff --git a/R/multilist_to_tibble.R b/R/multilist_to_tibble.R index c723736..c36f7fa 100644 --- a/R/multilist_to_tibble.R +++ b/R/multilist_to_tibble.R @@ -3,6 +3,8 @@ #' @importFrom purrr possibly map_dfr #' @importFrom dplyr tibble mutate_if #' @importFrom tidyr pivot_wider +#' +#' @return a tibble with columns as the names of the list #' @export #' @examples #' reprex <- list( diff --git a/R/projects_and_repos.R b/R/projects_and_repos.R index ac80364..b3bc6cc 100644 --- a/R/projects_and_repos.R +++ b/R/projects_and_repos.R @@ -294,6 +294,7 @@ gl_delete_project <- function(project) { #' @param project The ID or URL-encoded path of the project. #' @param ... passed on to [gitlab()] API call for "project" #' +#' @return A tibble with the project members information #' @export #' @examples \dontrun{ #' set_gitlab_connection( @@ -309,7 +310,7 @@ gl_list_project_members <- function(project, ...) { #' List members of a specific group #' @param group The ID or URL-encoded path of the group #' @param ... passed on to [gitlab()] API call for "groups" -#' +#' @return A tibble with the group members information #' @export #' @examples \dontrun{ #' set_gitlab_connection( diff --git a/man/gl_list_files.Rd b/man/gl_list_files.Rd index af4076a..e804342 100644 --- a/man/gl_list_files.Rd +++ b/man/gl_list_files.Rd @@ -15,6 +15,9 @@ gl_list_files(project, path = "", ref = get_main(), ...) \item{...}{passed on to \code{\link[=gitlab]{gitlab()}} API call} } +\value{ +Tibble of files available in the branch with descriptive variables. +} \description{ List of files in a folder } diff --git a/man/gl_list_group_members.Rd b/man/gl_list_group_members.Rd index 936e385..0d46797 100644 --- a/man/gl_list_group_members.Rd +++ b/man/gl_list_group_members.Rd @@ -11,6 +11,9 @@ gl_list_group_members(group, ...) \item{...}{passed on to \code{\link[=gitlab]{gitlab()}} API call for "groups"} } +\value{ +A tibble with the group members information +} \description{ List members of a specific group } diff --git a/man/gl_list_project_members.Rd b/man/gl_list_project_members.Rd index 3f76655..b1842d8 100644 --- a/man/gl_list_project_members.Rd +++ b/man/gl_list_project_members.Rd @@ -11,6 +11,9 @@ gl_list_project_members(project, ...) \item{...}{passed on to \code{\link[=gitlab]{gitlab()}} API call for "project"} } +\value{ +A tibble with the project members information +} \description{ List members of a specific project } diff --git a/man/multilist_to_tibble.Rd b/man/multilist_to_tibble.Rd index f080977..01c69c3 100644 --- a/man/multilist_to_tibble.Rd +++ b/man/multilist_to_tibble.Rd @@ -9,6 +9,9 @@ multilist_to_tibble(the_list) \arguments{ \item{the_list}{list of element as issued from a API REST call} } +\value{ +a tibble with columns as the names of the list +} \description{ Modify a multilist from API JSON output to a level 1 tibble } From 32edcd6d0c69d351bcefc460b6dba20a12d809bd Mon Sep 17 00:00:00 2001 From: StatnMap Date: Wed, 15 May 2024 11:11:10 +0200 Subject: [PATCH 5/7] fix: clean doc --- DESCRIPTION | 2 +- NEWS.md | 4 ++-- R/issues.R | 2 +- dev/dev_history.R | 2 ++ man/gitlabr-package.Rd | 2 +- man/gl_new_issue.Rd | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8b8dcd8..c69932e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: gitlabr -Title: Access to the 'Gitlab' API +Title: Access to the 'GitLab' API Version: 2.0.1.9005 Authors@R: c( person("Jirka", "Lewandowski", , "jirka.lewandowski@wzb.eu", role = "aut"), diff --git a/NEWS.md b/NEWS.md index eb82a78..f1f47dc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -73,7 +73,7 @@ # gitlabr 0.9 (2017-04-24) -* Support for Gitlab API v4 (default from Gitlab version 9.0 onward) was added. Gitlab API v4 is now the default used by gitlabr, but using the old API (v3) is still possible, see details section "API version" of the documentation of `gl_connection`. +* Support for GitLab API v4 (default from GitLab version 9.0 onward) was added. GitLab API v4 is now the default used by gitlabr, but using the old API (v3) is still possible, see details section "API version" of the documentation of `gl_connection`. * Several convenience functions now have a `force_api_v3` parameter to force old API version logic. * Issues are now identified by project-wide id and not global iid, according to API v4 logic. * Function `gl_builds` was replaced by `gl_pipelines` and `gl_jobs` to reflect API v4 logic. @@ -84,7 +84,7 @@ # gitlabr 0.8 -*There is no gitlabr 0.8. Version number 0.9 was used to align with Gitlab version 9.0, for which this version is appropriate.* +*There is no gitlabr 0.8. Version number 0.9 was used to align with GitLab version 9.0, for which this version is appropriate.* # gitlabr 0.7 (2017-03-06) diff --git a/R/issues.R b/R/issues.R index 68aad22..231872b 100644 --- a/R/issues.R +++ b/R/issues.R @@ -134,7 +134,7 @@ gl_to_issue_id <- function(project, issue_id, api_version = 3, ...) { #' ## unassign it #' gl_unassign_issue("<>", new_issue_iid) #' ## Delete issue as if it never existed -#' ## (please note that you must have "Owner" role on the Gitlab project) +#' ## (please note that you must have "Owner" role on the GitLab project) #' gl_delete_issue("<>", new_issue_iid) #' } gl_new_issue <- function(project, diff --git a/dev/dev_history.R b/dev/dev_history.R index 13dafcd..f8782f0 100644 --- a/dev/dev_history.R +++ b/dev/dev_history.R @@ -98,6 +98,8 @@ spelling::spell_check_package() # regarder s'il y a des typos # Check URL are correct - No redirection # install.packages('urlchecker', repos = 'https://r-lib.r-universe.dev') +# dont change all https://gitlab.com to about.gitlab.com, +# this would be a mistake urlchecker::url_check() urlchecker::url_update() # corrige les redirections diff --git a/man/gitlabr-package.Rd b/man/gitlabr-package.Rd index 2c8d2bf..b189919 100644 --- a/man/gitlabr-package.Rd +++ b/man/gitlabr-package.Rd @@ -4,7 +4,7 @@ \name{gitlabr-package} \alias{gitlabr} \alias{gitlabr-package} -\title{gitlabr: Access to the 'Gitlab' API} +\title{gitlabr: Access to the 'GitLab' API} \description{ \if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} diff --git a/man/gl_new_issue.Rd b/man/gl_new_issue.Rd index 3e1d737..37e7766 100644 --- a/man/gl_new_issue.Rd +++ b/man/gl_new_issue.Rd @@ -64,7 +64,7 @@ gl_assign_issue("<>", new_issue_iid, assignee_id = "<> ## unassign it gl_unassign_issue("<>", new_issue_iid) ## Delete issue as if it never existed -## (please note that you must have "Owner" role on the Gitlab project) +## (please note that you must have "Owner" role on the GitLab project) gl_delete_issue("<>", new_issue_iid) } } From 7500f2e8f95e49ba81d7d145d9ff82a8832f1178 Mon Sep 17 00:00:00 2001 From: StatnMap Date: Wed, 15 May 2024 11:11:38 +0200 Subject: [PATCH 6/7] ci: allow rhub runner --- .github/workflows/rhub.yaml | 95 +++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .github/workflows/rhub.yaml diff --git a/.github/workflows/rhub.yaml b/.github/workflows/rhub.yaml new file mode 100644 index 0000000..74ec7b0 --- /dev/null +++ b/.github/workflows/rhub.yaml @@ -0,0 +1,95 @@ +# R-hub's generic GitHub Actions workflow file. It's canonical location is at +# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml +# You can update this file to a newer version using the rhub2 package: +# +# rhub::rhub_setup() +# +# It is unlikely that you need to modify this file manually. + +name: R-hub +run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}" + +on: + workflow_dispatch: + inputs: + config: + description: 'A comma separated list of R-hub platforms to use.' + type: string + default: 'linux,windows,macos' + name: + description: 'Run name. You can leave this empty now.' + type: string + id: + description: 'Unique ID. You can leave this empty now.' + type: string + +jobs: + + setup: + runs-on: ubuntu-latest + outputs: + containers: ${{ steps.rhub-setup.outputs.containers }} + platforms: ${{ steps.rhub-setup.outputs.platforms }} + + steps: + # NO NEED TO CHECKOUT HERE + - uses: r-hub/actions/setup@v1 + with: + config: ${{ github.event.inputs.config }} + id: rhub-setup + + linux-containers: + needs: setup + if: ${{ needs.setup.outputs.containers != '[]' }} + runs-on: ubuntu-latest + name: ${{ matrix.config.label }} + strategy: + fail-fast: false + matrix: + config: ${{ fromJson(needs.setup.outputs.containers) }} + container: + image: ${{ matrix.config.container }} + + steps: + - uses: r-hub/actions/checkout@v1 + - uses: r-hub/actions/platform-info@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/setup-deps@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/run-check@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + + other-platforms: + needs: setup + if: ${{ needs.setup.outputs.platforms != '[]' }} + runs-on: ${{ matrix.config.os }} + name: ${{ matrix.config.label }} + strategy: + fail-fast: false + matrix: + config: ${{ fromJson(needs.setup.outputs.platforms) }} + + steps: + - uses: r-hub/actions/checkout@v1 + - uses: r-hub/actions/setup-r@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} + - uses: r-hub/actions/platform-info@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/setup-deps@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} + - uses: r-hub/actions/run-check@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} From 4491605425d70e42d7f8cb757741d38a97f78c62 Mon Sep 17 00:00:00 2001 From: StatnMap Date: Wed, 15 May 2024 11:15:11 +0200 Subject: [PATCH 7/7] chore: store cran-comments-history --- DESCRIPTION | 4 ++-- dev/cran-comments-history.md | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 dev/cran-comments-history.md diff --git a/DESCRIPTION b/DESCRIPTION index c69932e..ef119b0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,9 +1,9 @@ Package: gitlabr Title: Access to the 'GitLab' API -Version: 2.0.1.9005 +Version: 2.0.1.9006 Authors@R: c( person("Jirka", "Lewandowski", , "jirka.lewandowski@wzb.eu", role = "aut"), - person("Sébastien", "Rochette", , "sebastien@thinkr.fr", role = c("aut", "cre"), + person("Sébastien", "Rochette", , "sebastienrochettefr@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-1565-9313")) ) Description: Provides R functions to access the API of the project and diff --git a/dev/cran-comments-history.md b/dev/cran-comments-history.md new file mode 100644 index 0000000..dd919d6 --- /dev/null +++ b/dev/cran-comments-history.md @@ -0,0 +1,18 @@ +# gitlabr 2.0.1 + +* This release deals with notes in checks on created by the last modification of CRAN checks concerning HTML5 +* This also deals with the URL redirect problem in the vignette + +## Test environments + +* GitHub Actions: windows (release, devel), macOS (release), ubuntu-20.04 (release, devel) +* win-builder (devel, release), mac-builder +* rhub: + + Windows Server 2008 R2 SP1, R-devel, 32/64 bit + + Fedora Linux, R-devel, clang, gfortran + + Ubuntu Linux 20.04.1 LTS, R-release, GCC + + Oracle Solaris 10, x86, 32 bit, R-release + +## R CMD check results + +0 errors | 0 warnings | 0 note \ No newline at end of file