Skip to content

Commit

Permalink
Add verbose control.
Browse files Browse the repository at this point in the history
  • Loading branch information
maciekbanas committed Nov 27, 2024
1 parent 84ac159 commit 21cea3c
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 13 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

export(add_files)
export(initialize_project)
export(is_verbose)
export(process_repos)
export(set_github_repos)
export(set_gitlab_repos)
export(set_llm)
export(set_prompt)
export(verbose_off)
export(verbose_on)
importFrom(R6,R6Class)
importFrom(httr2,with_verbosity)
17 changes: 11 additions & 6 deletions R/process_repos.R
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
#' Run LLM on `GitAI` repositories content
#' @name process_repos
#' @param gitai A \code{GitAI} object.
#' @param verbose A logical. If \code{FALSE} you won't be getting
#' additional diagnostic messages.
#' @return A list.
#' @export
process_repos <- function(gitai) {
process_repos <- function(gitai, verbose = is_verbose()) {

gitstats <- gitai$gitstats

gitai$repos_metadata <-
GitStats::get_repos(gitstats,
add_contributors = FALSE)
add_contributors = FALSE,
verbose = verbose)

GitStats::get_files_structure(
gitstats_object = gitstats,
pattern = gitai$files,
depth = 1L
depth = 1L,
verbose = verbose
)
files_content <- GitStats::get_files_content(gitstats)
files_content <- GitStats::get_files_content(gitstats, verbose = verbose)

results <-
files_content$repo_name |>
purrr::map(function(repo_name) {

cli::cli_alert_info("Processing repository: {.pkg {repo_name}}")
if (verbose) {
cli::cli_alert_info("Processing repository: {.pkg {repo_name}}")
}

content_to_process <-
files_content |>
Expand Down
14 changes: 10 additions & 4 deletions R/set_repos.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
#' @param gitai A \code{GitAI} object.
#' @param host A character, GitHub host.
#' @param repos A character vector or repositories full names.
#' @param verbose A logical. If \code{FALSE} you won't be getting
#' additional diagnostic messages.
#' @return A \code{GitAI} object.
#' @export
set_github_repos <- function(gitai,
host = NULL,
repos) {
repos,
verbose = is_verbose()) {
if (is.null(gitai$gitstats)) {
gitstats <- GitStats::create_gitstats()
} else {
Expand All @@ -17,7 +20,7 @@ set_github_repos <- function(gitai,
GitStats::set_github_host(
host = host,
repos = repos,
verbose = FALSE
verbose = verbose
)
invisible(gitai)
}
Expand All @@ -27,11 +30,14 @@ set_github_repos <- function(gitai,
#' @param gitai A \code{GitAI} object.
#' @param host A character, GitLab host.
#' @param repos A character vector or repositories full names.
#' @param verbose A logical. If \code{FALSE} you won't be getting
#' additional diagnostic messages.
#' @return A \code{GitAI} object.
#' @export
set_gitlab_repos <- function(gitai,
host = NULL,
repos) {
repos,
verbose = is_verbose()) {
if (is.null(gitai$gitstats)) {
gitstats <- GitStats::create_gitstats()
} else {
Expand All @@ -41,7 +47,7 @@ set_gitlab_repos <- function(gitai,
GitStats::set_gitlab_host(
host = host,
repos = repos,
verbose = FALSE
verbose = verbose
)
invisible(gitai)
}
37 changes: 37 additions & 0 deletions R/verbose.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' Checks if \code{GitAI} is verbose
#'
#' The function searches for \code{GITAI_VERBOSE} environmental variable
#' and tries to read it value as logical.
#'
#' @returns A logical. Default is \code{TRUE}.
#'
#' @export
is_verbose <- function() {

verbose <- Sys.getenv("GITAI_VERBOSE", TRUE)
verbose <- as.logical(verbose)
verbose <- ifelse(is.na(verbose), TRUE, verbose)
verbose
}

#' Sets \code{GitAI} to be verbose
#'
#' The function sets the \code{GITAI_VERBOSE} environmental variable
#' to \code{TRUE}.
#'
#' @export
verbose_on <- function() {

Sys.setenv("GITAI_VERBOSE" = TRUE)
}

#' Sets \code{GitAI} to be quiet.
#'
#' The function sets the \code{GITAI_VERBOSE} environmental variable
#' to \code{FALSE}.
#'
#' @export
verbose_off <- function() {

Sys.setenv("GITAI_VERBOSE" = FALSE)
}
15 changes: 15 additions & 0 deletions man/is_verbose.Rd

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

5 changes: 4 additions & 1 deletion man/process_repos.Rd

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

5 changes: 4 additions & 1 deletion man/set_github_repos.Rd

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

5 changes: 4 additions & 1 deletion man/set_gitlab_repos.Rd

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

12 changes: 12 additions & 0 deletions man/verbose_off.Rd

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

12 changes: 12 additions & 0 deletions man/verbose_on.Rd

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

0 comments on commit 21cea3c

Please sign in to comment.