From 4fd7a792dda68af61b93b368eef953b14418a93c Mon Sep 17 00:00:00 2001 From: cebarboza Date: Sun, 16 Aug 2026 00:12:26 +0200 Subject: [PATCH] pr function done testing --- R/versionControl.R | 69 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/R/versionControl.R b/R/versionControl.R index 9bb22cf..31611c6 100644 --- a/R/versionControl.R +++ b/R/versionControl.R @@ -1,12 +1,73 @@ -#' `issueOpen()` is a wrapper for gh::gh() to swiftly post in the GitHub repository of the current project +#' `pullRequest()` is a wrapper for gh::gh() to swiftly ask merging +#' code from the current branch #' #' @param title of the issue in character #' @param body of the issue in character -#' @param newBranch Logical. Default TRUE, will open a new branch in GitHub format +#' @param base The target branch, in character. Defaults to "develop" #' #' @returns A message with the link of the issue -#' @importFrom checkmate assertCharacter assertLogical assertTRUE -#' @importFrom gh gh gh_tree_remote +#' @importFrom checkmate assertCharacter assertLogical assertTRUE checkClass +#' @importFrom gh gh gh_tree_remote gh_token_exists +#' @importFrom gert git_branch_create git_branch +#' @export +#' @examples +pullRequest <- function( + title, + body, + base = "develop" +) { + checkmate::assertCharacter( + title, + len = 1, + any.missing = FALSE + ) + title_word_count <- length( + regmatches( + title, + gregexpr( + "\\S+", + title, + perl = TRUE + ))[[1]]) + checkmate::assertTRUE(title_word_count >= 2) + checkmate::assertCharacter(body) + checkmate::assertTRUE(gh::gh_token_exists()) + prData <- gh::gh( + "POST /repos/{owner}/{repo}/pulls", + owner = gh::gh_tree_remote()$username, + repo = gh::gh_tree_remote()$repo, + head = gert::git_branch(), + base = base, + title = title, + body = body + ) + pr_created <- checkmate::checkClass( + prData, + "gh_response" + ) + if (isTRUE(pr_created)) { + cli::cli_alert_success( + "Pull request created at:" + ) + cat(prData$html_url, "\n") + invisible(prData$html_url) + } + +} + + +#' `issueOpen()` is a wrapper for gh::gh() to swiftly post +#' in the GitHub repository of the current project +#' +#' @param title of the issue in character +#' @param body of the issue in character +#' @param newBranch Logical. Default TRUE, will open a new +#' branch in GitHub format +#' +#' @returns A message with the link of the issue +#' @importFrom checkmate assertCharacter assertLogical assertTRUE checkClass +#' @importFrom gh gh gh_tree_remote gh_token_exists +#' @importFrom gert git_branch_create git_branch #' @export #' @examples issueOpen <- function(