Skip to content
Closed
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
27 changes: 15 additions & 12 deletions R/post_bug.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ components <- c("Accuracy", "Add-ons", "Analyses", "Documentation", "Graphics",
#' [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) {
# Provide some checks/questions to the users
version, product, host, key) {
# Fill description, version and summary
if (missing(component)) {
cli::cli_alert("Please, pick a component:")
Expand All @@ -45,14 +44,18 @@ post_bug <- function(text, title, component, ...,
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)
url <- paste0(host, "rest/bug?")
data <- list(
product = product,
component = component,
version = version,
summary = title,
description = text
)
bugs <- httr::POST(url, body = data, encode = "json", ...,
add_headers(.headers = c(
"Content-Type"="application/json",
"Ocp-Apim-Subscription-Key"="my_subscrition_key")))
bugs <- httr::content(bugs)
return(bugs)
}
35 changes: 35 additions & 0 deletions tests/fixtures/post_bug_works.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
http_interactions:
- request:
method: post
uri: https://bugs.r-project.org/bugzilla/rest/bug
body:
encoding: ''
string: '{"product":"R","component":"Misc","version":"4.0.x","summary":"test!!!"}'
headers:
Accept: application/json, text/xml, application/xml, */*
Content-Type: application/json
response:
status:
status_code: 401
category: Client error
reason: Unauthorized
message: 'Client error: (401) Unauthorized'
headers:
date: Thu, 15 Jul 2021 17:00:35 GMT
server: gazelle
etag: 8hv3qhJNknTVRt2cjTD2dw
content-length: '157'
content-type: application/json; charset=UTF-8
access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with,
x-bugzilla-api-key, x-bugzilla-password, x-bugzilla-token, x-bugzilla-login
access-control-allow-origin: '*'
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
body:
encoding: UTF-8
file: no
string: '{"code":"410","message":"You must log in before using this part of
Bugzilla.","error":true,"documentation":"https://bugzilla.readthedocs.org/en/latest/api/"}'
recorded_at: 2021-07-15 17:00:35 GMT
recorded_with: vcr/1.0.2, webmockr/0.8.0
38 changes: 38 additions & 0 deletions tests/testthat/_snaps/post_bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# post_bug() works [plain]

Code
expect_type(pg, "list")

# post_bug() fails [plain]

Code
expect_error(post_bug("This is the test description", "TEST!!!"),
"Do it and then return please.")
Message <cliMessage>
> Please, pick a component:
Output

1: Accuracy 2: Add-ons
3: Analyses 4: Documentation
5: Graphics 6: I/O
7: Installation 8: Language
9: Low-level 10: Mac GUI/Mac specific
11: Misc 12: Models
13: S4methods 14: Startup
15: System-specific 16: Translations
17: Windows GUI/Window specific 18: Wishlist


-- Documentation ---------------------------------------------------------------
Message <cliMessage>
> Have you read the documentation recently?
Output
(0 to cancel)

1: Yup
2: Negative
3: Nope

Message <cliMessage>
v Opening documentation...

17 changes: 17 additions & 0 deletions tests/testthat/test-post_bug.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cli::test_that_cli(configs = "plain", "post_bug() works", {
skip_if_not(interactive())
vcr::use_cassette("post_bug_works", {
pg <- post_bug("This is the test description", "TEST!!!")
})
expect_snapshot(
expect_type(pg, "list")
)
})


cli::test_that_cli(configs = "plain", "post_bug() fails", {
skip_if_not(interactive())
expect_snapshot(
expect_error(post_bug("This is the test description", "TEST!!!"), "Do it and then return please.")
)
})