Skip to content

Commit

Permalink
Fix branch tests and add examples
Browse files Browse the repository at this point in the history
closes issue #27
closes issue #33
  • Loading branch information
statnmap committed May 28, 2021
1 parent c82c3ea commit 16d8e8f
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 43 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export(gl_create_issue)
export(gl_create_merge_request)
export(gl_default_ci_pipeline)
export(gl_delete_branch)
export(gl_delete_issue)
export(gl_delete_merge_request)
export(gl_edit_commit_comment)
export(gl_edit_issue)
Expand Down
47 changes: 38 additions & 9 deletions R/issues.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ gl_get_issues <- function(project = NULL,
#' private_token = test_private_token
#' )
#' # list issues
#' gl_list_issues("<<your-project-id>>")
#' gl_list_issues("<<your-project-id>>", max_page = 1)
#' # list opened issues
#' gl_list_issues("<<your-project-id>>", state = "opened")
#' # Get one issue
#' gl_get_issue("<<your-project-id>>", issue_id = 1)
#' # Create new issue
Expand Down Expand Up @@ -99,8 +101,26 @@ gl_to_issue_id <- function(project, issue_id, api_version = 3, ...) {
#' @param ... further parameters passed to the API call, may
#' contain description, assignee_id, milestone_id, labels, state_event (for edit_issue).
#'
#' @rdname gl_edit_issue
#' @rdname gl_new_issue
#' @export
#' @examples
#' \dontrun{
#' # create an issue
#' new_issue_infos <- gl_create_issue(project = "<<your-project-id>>", "A simple issue")
#' new_issue_iid <- new_issue_infos$iid[1]
#' ## close issue
#' gl_close_issue("<<your-project-id>>", new_issue_iid)
#' ## reopen issue
#' gl_reopen_issue("<<your-project-id>>", new_issue_iid)
#' ## edit its description
#' gl_edit_issue("<<your-project-id>>", new_issue_iid, description = "This is a test")
#' ## assign it
#' gl_assign_issue("<<your-project-id>>", new_issue_iid, assignee_id = "<<user-id>>")
#' ## unassign it
#' gl_unassign_issue("<<your-project-id>>", new_issue_iid)
#' ## Delete issue as if it never existed
#' gl_delete_issue("<<your-project-id>>", new_issue_iid)
#' }
gl_new_issue <- function(project,
title,
...) {
Expand All @@ -111,11 +131,10 @@ gl_new_issue <- function(project,
}

#' @export
#' @rdname gl_edit_issue
#' @rdname gl_new_issue
gl_create_issue <- gl_new_issue

#' Post a new issue or edit one
#'

#' @param issue_id issue id (projectwide; for API v3 only you can use global iid when force_api_v3 is `TRUE` although this is not recommended!)
#' @param api_version a switch to force deprecated GitLab API v3 behavior that allows filtering by global iid. If `3`
#' filtering happens by global iid, if false, it happens by projectwide ID. For API v4, this must be 4 (default)
Expand All @@ -135,23 +154,23 @@ gl_edit_issue <- function(project,
...)
}

#' @rdname gl_edit_issue
#' @rdname gl_new_issue
#' @export
gl_close_issue <- function(project,
issue_id,
...) {
gl_edit_issue(project, issue_id, state_event = "close", ...)
}

#' @rdname gl_edit_issue
#' @rdname gl_new_issue
#' @export
gl_reopen_issue <- function(project,
issue_id,
...) {
gl_edit_issue(project, issue_id, state_event = "reopen", ...)
}

#' @rdname gl_edit_issue
#' @rdname gl_new_issue
#' @param assignee_id numeric id of users as returned in '/users/' API request
#' @export
gl_assign_issue <- function(project,
Expand All @@ -161,10 +180,20 @@ gl_assign_issue <- function(project,
gl_edit_issue(project, issue_id, assignee_id = assignee_id, ...)
}

#' @rdname gl_edit_issue
#' @rdname gl_new_issue
#' @export
gl_unassign_issue <- function(project,
issue_id,
...) {
gl_assign_issue(project, issue_id, assignee_id = 0, ...)
}

#' @rdname gl_new_issue
#' @export
gl_delete_issue <- function(project,
issue_id,
...) {
gitlab(req = gl_proj_req(project, c("issues", issue_id), ...),
verb = httr::DELETE,
...)
}
2 changes: 1 addition & 1 deletion R/merge_requests.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#'
#' @export
#' @examples
#' @examples \dontrun{
#' \dontrun{
#' set_gitlab_connection(
#' gitlab_url = "https://gitlab.com",
#' private_token = Sys.getenv("GITLAB_COM_TOKEN")
Expand Down
5 changes: 2 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ knitr::opts_chunk$set(

**There are multiple breaking changes in {gitlabr} v2, please refer to the corresponding vignette: https://statnmap.github.io/gitlabr/articles/gitlabr-v2.html**

_Note that the {gitlabr} package was originally created by [Jirka Lewandowski](https://github.com/jirkalewandowski/gitlabr). The present repository is a fork to be able to continue development of this package._

## Installation

You can install the most recent stable version from CRAN using:
Expand Down Expand Up @@ -147,9 +149,6 @@ unset_gitlab_connection()
- For a comprehensive overview & introduction see the `vignette("quick-start-guide-to-gitlabr")`
- When writing custom extensions ("convenience functions") for {gitlabr} or when you experience any trouble, the very extensive [GitLab API documentation](http://doc.gitlab.com/ce/api/) can be helpful.

_Note that the {gitlabr} package was originally created by [Jirka Lewandowski](https://github.com/jirkalewandowski/gitlabr). The present repository is a fork to be able to continue development of this package._


# Contributing to {gitlabr}

You're welcome to contribute to {gitlabr} by editing the source code, adding more convenience functions, filing issues, etc. [CONTRIBUTING.md](CONTRIBUTING.md) compiles some information helpful in that process.
Expand Down
4 changes: 3 additions & 1 deletion man/gl_list_issues.Rd

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

32 changes: 22 additions & 10 deletions man/gl_edit_issue.Rd → man/gl_new_issue.Rd

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

30 changes: 13 additions & 17 deletions tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,22 @@ if (file.exists("environment.yml")) {
# There must be a token
# Testers should own a project on gitlab.com named "testor"
# This part allows to test multiple versions of the API. Currently, only v4 is tested.
if (FALSE) {
if (Sys.getenv("GITLABR_TEST_TOKEN") != "") {
if (Sys.getenv("GITLABR_TEST_TOKEN") != "") {
# Skip all tests if no token
# Skip all tests if no token

if (Sys.getenv("GITLABR_TEST_API_VERSION") == "") {

# Sys.setenv(GITLABR_TEST_API_VERSION = 3)
# test_check("gitlabr")
Sys.setenv(GITLABR_TEST_API_VERSION = 4)
test_check("gitlabr")
# Sys.setenv(GITLABR_TEST_API_VERSION = "")

} else {

test_check("gitlabr")

if (Sys.getenv("GITLABR_TEST_API_VERSION") == "") {

# Sys.setenv(GITLABR_TEST_API_VERSION = 3)
# test_check("gitlabr")
Sys.setenv(GITLABR_TEST_API_VERSION = 4)
test_check("gitlabr")
# Sys.setenv(GITLABR_TEST_API_VERSION = "")

} else {

test_check("gitlabr")

}
}
} else {
# dont test on CRAN or without token available
}
}
10 changes: 8 additions & 2 deletions tests/testthat/test_issues.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Create and list issues ----
# create an issue
new_issue_infos <- gl_create_issue(project = test_project, "A simple issue")
# list issues (should be 2)
# list issues
all_issues <- gl_list_issues(test_project, max_page = 1)
# list opened issues (should be 2)
opened_issues <- gl_list_issues(test_project, state = "opened")
Expand Down Expand Up @@ -55,5 +55,11 @@ test_that("editing issues works", {
gl_unassign_issue(test_project, new_issue_iid, api_version = test_api_version)
expect_null(gl_list_issues(test_project, new_issue_iid, api_version = test_api_version)$assignee.username)
expect_null(gl_list_issues(test_project, new_issue_iid, api_version = test_api_version)$assignee.id)


## Delete issue
gl_delete_issue(test_project, new_issue_iid)
all_issues <- gl_list_issues(test_project, max_page = 1)
expect_false(any(all_issues$iid == new_issue_iid))
# clean state
expect_equal(nrow(all_issues), 1)
})

0 comments on commit 16d8e8f

Please sign in to comment.