Skip to content

Commit

Permalink
version 3.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkaye97 authored and cran-robot committed Feb 26, 2023
1 parent d800bda commit e5ab9d9
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 20 deletions.
12 changes: 6 additions & 6 deletions DESCRIPTION
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: slackr
Title: Send Messages, Images, R Objects and Files to 'Slack'
Channels/Users
Version: 3.3.0
Version: 3.3.1
Author: Bob Rudis [aut, cre], Jay Jacobs [ctb], David Severski [ctb],
Quinn Weber [ctb], Konrad Karczewski [ctb], Shinya Uryu [ctb], Gregory
Jefferis [ctb], Ed Niles [ctb], Rick Saporta [ctb], Jonathan Sidi
Expand All @@ -23,16 +23,16 @@ URL: https://github.com/mrkaye97/slackr,
https://mrkaye97.github.io/slackr/
BugReports: https://github.com/mrkaye97/slackr/issues
Depends: R (>= 3.3.0)
Imports: cachem (>= 1.0.4), dplyr, graphics, grDevices, httr (>=
1.4.2), jsonlite, magrittr, memoise (>= 2.0.0), rlang, tibble,
utils, withr
Imports: cachem (>= 1.0.4), dplyr, grDevices, httr (>= 1.4.2),
jsonlite, magrittr, memoise (>= 2.0.0), rlang, tibble, utils,
withr
Suggests: covr, ggplot2, knitr, rmarkdown, svglite, testthat (>=
3.0.0), texPreview
VignetteBuilder: knitr
Config/testthat/edition: 3
Encoding: UTF-8
RoxygenNote: 7.2.3
NeedsCompilation: no
Packaged: 2023-02-20 16:23:04 UTC; matt
Packaged: 2023-02-25 18:30:57 UTC; matt
Repository: CRAN
Date/Publication: 2023-02-20 16:40:02 UTC
Date/Publication: 2023-02-26 01:12:06 UTC
15 changes: 8 additions & 7 deletions MD5
@@ -1,7 +1,7 @@
bb49a3120050692970fd5807fb8823ef *DESCRIPTION
87e7a2be9f37fb4f3a133fe4a10845cd *DESCRIPTION
b5c243c35e6b712ecfe223711365f790 *LICENSE
15da68dcd2cd5d6a5ba142aee2beff2b *NAMESPACE
8f2d907529aae441ac2d04c5de3593fb *NEWS.md
8492c0e44bf019d58e6c0fae53ecb86b *NEWS.md
ae44f30f17edd19187647f9a0ae00b6a *R/call_slack_api.R
8b86a70ec6f77bd7fea7c93caa3455fb *R/call_slack_internals.R
a417e2c39e0b79fe597d6ee581f64f84 *R/gg_slackr.R
Expand All @@ -13,7 +13,7 @@ a4e2674c997685ee0db41b30686ec409 *R/slackr_bot.r
4c1de13243971ef17ce80678fd429bce *R/slackr_csv.R
ba38b2c2908149c45592c39647c33c56 *R/slackr_delete.R
6b9f248a75fdca67c106f3a171a251af *R/slackr_dev.R
89cc4c92e572e93391e84f6025edeb40 *R/slackr_history.R
4392b93e379188a98f8f95a533ecf707 *R/slackr_history.R
814a2cd5ac1d09beecb7199a6b145942 *R/slackr_save.R
db707f01ae7148d27b90ecb0a9cdd369 *R/slackr_setup.r
dbe5fd32f50cd4775d05e1bca315e1a7 *R/slackr_tex.R
Expand Down Expand Up @@ -46,7 +46,7 @@ ae521ba5313abff1c2f3b0590ec47e1a *man/slackr_chtrans.Rd
d5aa72b33d2b389711edc8bef1926e85 *man/slackr_csv.Rd
7959ff38baff344d0d641c31b59f8bed *man/slackr_delete.Rd
311d9302d50d7943035417a8d7310e04 *man/slackr_dev.Rd
b9fb485017c59f5786ff1a120280a84e *man/slackr_history.Rd
18f32e410f511f47a05a2d8fb1efb1ad *man/slackr_history.Rd
658aebc8add35b573110c3da65f3102f *man/slackr_ims.Rd
74c97cecd92cbabacac469a38dd23c85 *man/slackr_msg.Rd
878a0261cc5373c65b8391ec5fc66e09 *man/slackr_save.Rd
Expand All @@ -61,9 +61,10 @@ a60ccca7306def1046c65860b91ca6f5 *tests/testthat.R
0daf7d92b763992f5b78ec3c42b48e1a *tests/testthat/Rplots.pdf
2033315e06011f6106f0bb59bc1a320b *tests/testthat/test-aaa-setup.R
ff43db2f4c2059e0da36ccc578dff71e *tests/testthat/test-connection.R
0b52cb527142b2f30e8c9412ea698a45 *tests/testthat/test-dev-tex.R
6fdf95996d5184553f1e28ea2cee6a01 *tests/testthat/test-history.R
99b4d4e33f210bc5fa3593b24a3ab64e *tests/testthat/test-internals.R
7ce93108cd5d9253f3da91de29ebdf5e *tests/testthat/test-dev-tex.R
e6b884882ab829a9c597983f1df9539d *tests/testthat/test-history.R
fc6efb52c56745a08de9bbff544b8790 *tests/testthat/test-internals.R
7c0a30dfe82fdc15e4c61f3080824003 *tests/testthat/test-onexit.R
bfcc13c29ff97f0ab123a722cc26071e *tests/testthat/test-posting.R
08c1d391d32cad08605636127a45a1c6 *tests/testthat/test-zzz-teardown.R
7c89f7dd6001659d706e7c7769886531 *vignettes/scoped-bot-setup.Rmd
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
@@ -1,3 +1,8 @@
# slackr 3.3.1
* Fixes a bug in `slackr_history` where the function fails to infer `posted_from_time` if not provided
* Adds default `message_count = 100` to `slackr_history`
* Improves test coverage

# slackr 3.3.0
User-facing changes:

Expand Down
6 changes: 3 additions & 3 deletions R/slackr_history.R
Expand Up @@ -24,15 +24,15 @@
#' @param message_count The number of messages to retrieve (only when `paginate = FALSE`).
#' Corresponds to `limit` in the \href{https://api.slack.com/methods/conversations.history}{conversations.history} docs.
#' Note: If using pagination, setting a value of (e.g.) 1 will result in paginating
#' through the channel's history one message at a time. Slack recommends using a value of 200.
#' through the channel's history one message at a time. Slack recommends using a value of 200. (Default: 100)
#' @param inclusive Include messages with oldest or latest timestamps in results. Ignored unless either timestamp is specified.
#' @export
#'
#' @return A `tibble` with message metadata
#' @references <https://api.slack.com/methods/conversations.history>
#'
slackr_history <- function(
message_count,
message_count = 100,
channel = Sys.getenv("SLACK_CHANNEL"),
token = Sys.getenv("SLACK_TOKEN"),
posted_to_time = as.numeric(Sys.time()),
Expand Down Expand Up @@ -60,7 +60,7 @@ slackr_history <- function(
.frequency_id = "slackr_history_posted_from_infer_warning"
)
}
posted_from_time <- posted_to_time - duration * 3600
posted_from_time <- as.character(as.numeric(posted_to_time) - duration * 3600)
}

if (!paginate) {
Expand Down
4 changes: 2 additions & 2 deletions man/slackr_history.Rd

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

16 changes: 15 additions & 1 deletion tests/testthat/test-dev-tex.R
Expand Up @@ -10,12 +10,26 @@ test_that("slackr_dev posts", {
expect_equal(post$file$filetype, "png")
})

test_that("slackr_tex posts", {
test_that("slackr_tex posts with no dir specified", {
skip_on_cran()
skip_on_ci()

## No path specified
post <- slackr_tex("$$e^{i \\pi} + 1 = 0$$")

expect_true(post$ok)
expect_equal(post$file$filetype, "png")
})

test_that("slackr_tex posts with dir specified", {
skip_on_cran()
skip_on_ci()

## With path specified
d <- tempdir()
post <- slackr_tex("$$e^{i \\pi} + 1 = 0$$", path = d)

unlink(d, recursive = TRUE)
expect_true(post$ok)
expect_equal(post$file$filetype, "png")
})
39 changes: 38 additions & 1 deletion tests/testthat/test-history.R
Expand Up @@ -120,7 +120,7 @@ test_that("slackr_history works when posted_from and posted_to are specified for
)
})

test_that("Specifycing post times in slackr_history correctly limits time window", {
test_that("Specifying post times in slackr_history correctly limits time window", {
skip_on_cran()

lapply(
Expand Down Expand Up @@ -148,3 +148,40 @@ test_that("Specifycing post times in slackr_history correctly limits time window
}
)
})

test_that("Expect warning for too many params", {
skip_on_cran()

from_time <- slackr_msg("History warning test start")$ts
Sys.sleep(1)
slackr_msg("History warning test")
Sys.sleep(1)
to_time <- slackr_msg("History warning test end")$ts

expect_silent(
slackr_history(
posted_to_time = to_time,
duration = 2 * (as.numeric(to_time) - as.numeric(from_time)) / (60 * 60)
)
)

expect_warning(
slackr_history(
posted_from_time = from_time,
posted_to_time = to_time,
duration = 2 * (as.numeric(to_time) - as.numeric(from_time)) / (60 * 60)
),
"You specified all three of"
)
})

test_that("Error if trying to paginate with no start time", {
skip_on_cran()

expect_error(
slackr_history(
paginate = TRUE
),
"To use pagination with `slackr_history`, you must specify a value for `posted_from_time`"
)
})
29 changes: 29 additions & 0 deletions tests/testthat/test-internals.R
Expand Up @@ -74,3 +74,32 @@ test_that("Users works", {
"mrkaye97" %in% users$name
)
})

test_that("with_retry correctly retries requests", {
skip_on_cran()

i <- 1

mock <- function() {
if (i > 1) {
httr:::response(
headers = list(`retry-after` = 2),
status_code = 200,
ok = TRUE
)
} else {
i <<- i + 1
httr:::response(
headers = list(`retry-after` = 2),
status_code = 429
)
}
}

expect_message(with_retry(mock), "Pausing for 2 seconds due to Slack API rate limit")

out <- with_retry(mock)

expect_true(out$ok)
expect_equal(out$status_code, 200)
})
13 changes: 13 additions & 0 deletions tests/testthat/test-onexit.R
@@ -0,0 +1,13 @@
test_that("onexit usage works as expected", {
skip_on_cran()

slack_lm <- register_onexit(lm, "testing onexit")

formula <- Sepal.Length ~ Sepal.Width
mod <- slack_lm(formula, data = iris)

expect_identical(
mod$coefficients,
lm(formula, data = iris)$coefficients
)
})

0 comments on commit e5ab9d9

Please sign in to comment.