Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Make the post_bug functional #9

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
^_pkgdown\.yml$
^docs$
^pkgdown$

r_bugzilla.sql
mysql_rbugs.R
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Type: Package
Package: bugRzilla
Title: Interact with Bugzilla
Title: Interact with Bugzilla
Version: 0.0.90001
Authors@R:
person(given = "Lluís",
family = "Revilla Sancho",
role = c("aut", "cre", "cph"),
email = "lluis.revilla@gmail.com",
comment = c(ORCID = "0000-0001-9747-2570"))
Description: Provides data from bugzilla and allows to post.
Description: Uses the Bugzilla API to retrieve bug and allows to post.
License: GPL (>= 3)
URL: https://github.com/llrs/bugRzilla
BugReports: https://github.com/llrs/bugRzilla/issues
Expand All @@ -24,10 +24,10 @@ Suggests:
reprex,
rmarkdown,
testthat (>= 3.0.0),
vcr
vcr (>= 1.2.0)
VignetteBuilder:
knitr
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
RoxygenNote: 7.3.1
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export(get_history)
export(get_user)
export(post_bug)
export(post_comment)
export(post_r_bug)
export(set_key)
export(use_key)
importFrom(cli,cat_rule)
Expand Down
16 changes: 1 addition & 15 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ missing_key <- function(key) {
#' Obtain an API key or check if it can fine one that works for this host and
#' the version of the bugzilla provided works with this package.
#' @param host URL of the bugzilla instance if missing the R bugzilla is assumed.
#' @param key API key to check.
#' @param key API key name to check. By default R_BUGZILLA.
#' @return TRUE invisibly if the actions are performed.
#' @seealso set_key() if you want to temporary use an API key.
#' @rdname authentication
Expand Down Expand Up @@ -106,20 +106,6 @@ app_file <- function() {
file.path(normalizePath(path), ".Renviron")
}


# use_key <- function(){
# path <- app_file()
# file <- strsplit(readLines(path), split = "=", fixed = TRUE)
# key <- vector("characer", length(file))
# value <- vector("character", length(file))
# for (i in seq_along(file)) {
# key[i] <- file[[i]][1]
# value[i] <- file[[i]][2]
# }
# message("choose a key:")
# key[tools::menu(key)]
# }

write_renviron <- function(key, value, file) {
if (!dir.exists(dirname(file))) {
dir.create(dirname(file), showWarnings = FALSE, recursive = TRUE)
Expand Down
3 changes: 1 addition & 2 deletions R/bugRzilla.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@
#' Consider if this has been reported on the mailing list (R-devel) or on the
#' issue tracker itself.
#'
#' @docType package
#' @name bugRzilla
NULL
"_PACKAGE"
1 change: 1 addition & 0 deletions R/get_bug.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ get_bug <- function(issue, host) {
url <- paste0(host, "rest/bug?id=", issues)
bugs <- httr::GET(url, .state$headers)
httr::stop_for_status(bugs)

bugs <- httr::content(bugs)

if ("error" %in% names(bugs)) {
Expand Down
27 changes: 20 additions & 7 deletions R/get_comments.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ get_comment <- function(issue, comment, host) {
stop("Provide an issue or a comment to retrieve from.", call. = FALSE)
}
if (!missing(issue) && !missing(comment)) {
warning("Issue ID is ignored", call. = FALSE)
warning("Comment ID is ignored", call. = FALSE)
}
host <- missing_host(host)
if (missing(issue)) {
Expand Down Expand Up @@ -70,15 +70,28 @@ get_commenti <- function(issue, host) {
#' @param comment The text you want to post.
#' @inheritParams create_bugzilla_key
#' @return The ID of the comment posted.
#' @seealso `post_bug()`, `get_comment()`
#' See the API reference: <https://bugzilla.readthedocs.io/en/latest/api/core/v1/comment.html#create-comments>
#' @export
post_comment <- function(issue, comment, is_markdown, host, key) {
stopifnot(!is.logical(is_markdown))
post_comment <- function(issue, comment, is_markdown = TRUE, host, key) {
stopifnot(is.logical(is_markdown))
host <- missing_host(host)
comment <- paste0(comment, "\n\nPosted via bugRzilla package.")
headers <- set_headers(key)
url <- paste0(host, "rest/bug/", issue, "/comment")
# comments <- httr::POST(url,
# comment = comment, is_markdown = is_markdown,
# headers)
# httr::content(comments)$id
comment_resp <- httr::POST(url,
body = list(
comment = comment,
is_markdown = is_markdown),
encode = "json",

headers)
if (httr::http_error(comment_resp)) {
stop("You probably didn't use the right columns or values.\n",
" Check the API documentation as it says:\n\t",
httr::content(comment_resp)$message, call. = FALSE)
}
bugs <- httr::content(comment_resp)
bugs$id

}
89 changes: 67 additions & 22 deletions R/post_bug.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,78 @@ components <- c("Accuracy", "Add-ons", "Analyses", "Documentation", "Graphics",
#' Open an issue.
#'
#' Guides through the process of creating an issue.
#' Requires an user and an API key.
#' Requires an user and an API key, see the vignette to know how to obtain that.
#' `post_r_bug()` is a helper with some checks
#' and advice before submitting issues to the R Bugzilla database.
#'
#' Many arguments can be passed, read the documentation on the reference to
#' know what can be added.
#' @param text A character vector with the text of the bug you want to
#' open.
#' @param title A character vector with the title of the bug.
#' @param component A character with the component of R you want to fill an issue with.
#' @param version A character of the Version you want to use eg "R 4.0.0".
#' If you omit it while using the `post_r_bug` you will be prompted to fill it.
#' @param version A character of the version you want to use eg "R 4.0.0".
#' If omitted on post_r_bug it will be automatically assumed to be from the version of R being used.
#' @param product A character of the product you want to use if missing "R" is
#' automatically filled.
#' @param ... Named arguments passed to the API [check documentation](https://bugzilla.readthedocs.io/en/latest/api/core/v1/bug.html)
#' @param is_markdown Is using markdown formatting? True by default.
#' @param ... Named arguments passed to the API [check documentation](https://bugzilla.readthedocs.io/en/latest/api/core/v1/bug.html#create-bug)
#' @inheritParams create_bugzilla_key
#' @importFrom utils menu
#' @importFrom cli cli_alert
#' @export
#' @seealso To obtain and use the API key see create_bugzilla_key().
#' [Webpage](https://bugs.r-project.org/bugzilla/enter_bug.cgi) for manual entry
#' @return The ID of the issue posted.
post_bug <- function(text, title, component, ...,
version, product, host, key) {
#' @seealso To obtain and use the API key see `create_bugzilla_key()`.
#'
#' [Webpage](https://bugs.r-project.org/bugzilla/enter_bug.cgi) for manual entry for the R project.
#' @return The ID of the issue posted. NULL if the user doesn't follow the advice.
#' @references API parameters: <https://bugzilla.readthedocs.io/en/latest/api/core/v1/bug.html#create-bug>
#' Markdown allowed: <https://bugs.r-project.org/page.cgi?id=markdown.html>
post_bug <- function(title, text, component, version, product, ..., is_markdown = TRUE,
host, key) {
title <- paste("BugRzilla:", title)
if (Sys.getenv("RBUGZILLA") == "" & product == "R") {
stop("To post to the R bugzilla use the post_r_bug function.",
call. = FALSE)
} else if (Sys.getenv("RBUGZILLA") != "" & product == "R") {
ask_final_confirmation()
} else {
ask_confirmation("Are you really sure?")
}
url <- paste0(host, "rest/bug")
bugs <- httr::POST(url,
body = list(
description = text,
product = product,
component = component,
summary = title,
version = version,
is_markdown = is_markdown,
...),
encode = "json",
config = set_headers(key))
if (httr::http_error(bugs)) {
stop("You probably didn't use the right columns or values.\n",
" Check the API documentation as it says:\n\t",
httr::content(bugs)$message, call. = FALSE)
}
bugs <- httr::content(bugs)
bugs$id
}

#' @export
#' @rdname post_bug
post_r_bug <- function(title, text, component, version, ..., key) {
# Provide some checks/questions to the users
# Fill description, version and summary
if (missing(component)) {
cli::cli_alert("Please, pick a component:")
component <- menu(components)
component <- components[component]
}
component <- components[component]
version <- missing_version(version)
host <- missing_host(host)
product <- missing_product(product)
Sys.setenv("RBUGZILLA" = "a")
on.exit(Sys.unsetenv("RBUGZILLA"), add = TRUE)
if (read_documentation() == "Cancel") {
return()
}
Expand All @@ -44,15 +88,16 @@ post_bug <- function(text, title, component, ...,
if (about_content() == "Cancel") {
return()
}
ask_final_confirmation()
url <- paste0(host, "rest/bug")
# bugs <- httr::POST(url,
# description = text,
# product = product,
# component = component,
# summary = title,
# version = version,
# ...,
# headers)
# bugs <- httr::content(bugs)
post_bug(title = title,
text = text,
component = component,
version = version,
product = "R",
# To replace when going into production by: "https://bugs.r-project.org/bugzilla/"
host = "https://rbugs-devel.urbanek.info/",
key = missing_key(key),
...)
}


# Markdown formatting is conserved (copying content from bug 18231 and directly posting it accepts markdown)
3 changes: 1 addition & 2 deletions R/post_help.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ about_content <- function() {

ask_final_confirmation <- function(message) {
cli::cli_alert_warning("This notification will reach the R-core volunteers and many more")
cli::cli_ul("Are you sure to open a bug0
?")
cli::cli_ul("Are you sure to open a bug?")
ask_confirmation()
}
18 changes: 17 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ missing_version <- function(version) {
}
version <- paste0(ver, collapse = ".")
}
version
paste("R", version)
}

missing_product <- function(product) {
Expand All @@ -30,6 +30,22 @@ missing_product <- function(product) {
product
}

missing_hardware <- function(hardware) {
if (missing(hardware)) {
arch <- R.Version()[["arch"]]
}
if (arch == "x86_64") {
arch <- "x86_64/x64/amd64"
} else {
arch <- "Other"
}
arch
}

missing_system <- function(system) {

}


flatten_list <- function(x) {
x[lengths(x) == 0] <- list(NA)
Expand Down
6 changes: 6 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
url: https://bugrzilla.llrs.dev
development:
mode: auto
template:
bootstrap: 5
opengraph:
twitter:
creator: "@Lluis_Revilla"
card: summary_large_image
2 changes: 1 addition & 1 deletion man/authentication.Rd

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

13 changes: 13 additions & 0 deletions man/bugRzilla.Rd

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

Loading
Loading