Skip to content

Commit 1d137e6

Browse files
authored
use_air() (#466)
* use_air() * Format the workspace * Add the format-suggest workflow but temporarily pin it I pinned reviewdog/[email protected] as a temporary workaround for reviewdog/action-suggester#95, but the usual version tag is just `v1`
1 parent a7401ee commit 1d137e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+583
-290
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@
2525
^\.covrignore$
2626
^tests/testthat/all-test.+
2727
^CRAN-SUBMISSION$
28+
^[.]?air[.]toml$
29+
^\.vscode$

.github/workflows/format-suggest.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Workflow derived from https://github.com/posit-dev/setup-air/tree/main/examples
2+
3+
on:
4+
# Using `pull_request_target` over `pull_request` for elevated `GITHUB_TOKEN`
5+
# privileges, otherwise we can't set `pull-requests: write` when the pull
6+
# request comes from a fork, which is our main use case (external contributors).
7+
#
8+
# `pull_request_target` runs in the context of the target branch (`main`, usually),
9+
# rather than in the context of the pull request like `pull_request` does. Due
10+
# to this, we must explicitly checkout `ref: ${{ github.event.pull_request.head.sha }}`.
11+
# This is typically frowned upon by GitHub, as it exposes you to potentially running
12+
# untrusted code in a context where you have elevated privileges, but they explicitly
13+
# call out the use case of reformatting and committing back / commenting on the PR
14+
# as a situation that should be safe (because we aren't actually running the untrusted
15+
# code, we are just treating it as passive data).
16+
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
17+
pull_request_target:
18+
19+
name: format-suggest.yaml
20+
21+
jobs:
22+
format-suggest:
23+
name: format-suggest
24+
runs-on: ubuntu-latest
25+
26+
permissions:
27+
# Required to push suggestion comments to the PR
28+
pull-requests: write
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
ref: ${{ github.event.pull_request.head.sha }}
34+
35+
- name: Install
36+
uses: posit-dev/setup-air@v1
37+
38+
- name: Format
39+
run: air format .
40+
41+
- name: Suggest
42+
uses: reviewdog/[email protected]
43+
with:
44+
level: error
45+
fail_level: error
46+
tool_name: air

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"Posit.air-vscode"
4+
]
5+
}

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"[r]": {
3+
"editor.formatOnSave": true,
4+
"editor.defaultFormatter": "Posit.air-vscode"
5+
},
6+
"[quarto]": {
7+
"editor.formatOnSave": true,
8+
"editor.defaultFormatter": "quarto.quarto"
9+
}
10+
}

R/aaa.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
.drive$translate_mime_types <-
55
system.file(
6-
"extdata", "data", "translate_mime_types.csv",
6+
"extdata",
7+
"data",
8+
"translate_mime_types.csv",
79
package = "googledrive",
810
mustWork = TRUE
911
) %>%
@@ -12,7 +14,9 @@
1214

1315
.drive$mime_tbl <-
1416
system.file(
15-
"extdata", "data", "mime_tbl.csv",
17+
"extdata",
18+
"data",
19+
"mime_tbl.csv",
1620
package = "googledrive",
1721
mustWork = TRUE
1822
) %>%
@@ -21,7 +25,9 @@
2125

2226
.drive$files_fields <-
2327
system.file(
24-
"extdata", "data", "files_fields.csv",
28+
"extdata",
29+
"data",
30+
"files_fields.csv",
2531
package = "googledrive",
2632
mustWork = TRUE
2733
) %>%

R/compat-vctrs.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,11 @@ vec_cast.data.frame.dribble <- function(x, to, ..., x_arg = "", to_arg = "") {
9898

9999
stop_incompatible_cast_dribble <- function(x, to, ..., x_arg, to_arg) {
100100
details <- "Can't cast to a <dribble> because the resulting structure is likely invalid."
101-
stop_incompatible_cast(x, to, x_arg = x_arg, to_arg = to_arg, details = details)
101+
stop_incompatible_cast(
102+
x,
103+
to,
104+
x_arg = x_arg,
105+
to_arg = to_arg,
106+
details = details
107+
)
102108
}

R/deprecated.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ drive_auth_config <- function(active, app, path, api_key) {
4848
#' @export
4949
drive_oauth_app <- function() {
5050
lifecycle::deprecate_warn(
51-
"2.1.0", "drive_oauth_app()", "drive_oauth_client()"
51+
"2.1.0",
52+
"drive_oauth_app()",
53+
"drive_oauth_client()"
5254
)
5355
drive_oauth_client()
5456
}

R/dribble.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ id_can_be_drive_id <- function(x) {
135135
has_drive_resource <- function(x) {
136136
kind <- map_chr(x$drive_resource, "kind", .default = NA_character_)
137137
# TODO: remove `drive#teamDrive` here, when possible
138-
all(!is.na(kind) & kind %in% c("drive#file", "drive#drive", "drive#teamDrive"))
138+
all(
139+
!is.na(kind) & kind %in% c("drive#file", "drive#drive", "drive#teamDrive")
140+
)
139141
}
140142

141143
#' Coerce to a `dribble`
@@ -191,9 +193,11 @@ as_dribble <- function(x, ...) UseMethod("as_dribble")
191193

192194
#' @export
193195
as_dribble.default <- function(x, ...) {
194-
drive_abort("
196+
drive_abort(
197+
"
195198
Don't know how to coerce an object of class {.cls {class(x)}} into \\
196-
a {.cls dribble}.")
199+
a {.cls dribble}."
200+
)
197201
}
198202

199203
#' @export
@@ -374,7 +378,8 @@ is_folder_shortcut <- function(d) {
374378
d$drive_resource,
375379
c("shortcutDetails", "targetMimeType"),
376380
.default = ""
377-
) == "application/vnd.google-apps.folder")
381+
) ==
382+
"application/vnd.google-apps.folder")
378383
}
379384

380385
#' @export

R/drive_auth.R

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
## The roxygen comments for these functions are mostly generated from data
88
## in this list and template text maintained in gargle.
99
gargle_lookup_table <- list(
10-
PACKAGE = "googledrive",
11-
YOUR_STUFF = "your Drive files",
12-
PRODUCT = "Google Drive",
13-
API = "Drive API",
14-
PREFIX = "drive"
10+
PACKAGE = "googledrive",
11+
YOUR_STUFF = "your Drive files",
12+
PRODUCT = "Google Drive",
13+
API = "Drive API",
14+
PREFIX = "drive"
1515
)
1616

1717
#' Authorize googledrive
@@ -59,12 +59,15 @@ gargle_lookup_table <- list(
5959
#'
6060
#' # use a service account token
6161
#' drive_auth(path = "foofy-83ee9e7c9c48.json")
62-
drive_auth <- function(email = gargle::gargle_oauth_email(),
63-
path = NULL, subject = NULL,
64-
scopes = "drive",
65-
cache = gargle::gargle_oauth_cache(),
66-
use_oob = gargle::gargle_oob_default(),
67-
token = NULL) {
62+
drive_auth <- function(
63+
email = gargle::gargle_oauth_email(),
64+
path = NULL,
65+
subject = NULL,
66+
scopes = "drive",
67+
cache = gargle::gargle_oauth_cache(),
68+
use_oob = gargle::gargle_oob_default(),
69+
token = NULL
70+
) {
6871
gargle::check_is_service_account(path, hint = "drive_auth_configure")
6972
scopes <- drive_scopes(scopes)
7073
env_unbind(.googledrive, "root_folder")
@@ -205,15 +208,21 @@ drive_auth_configure <- function(client, path, api_key, app = deprecated()) {
205208
}
206209

207210
if (!missing(client) && !missing(path)) {
208-
drive_abort("Must supply exactly one of {.arg client} or {.arg path}, not both")
211+
drive_abort(
212+
"Must supply exactly one of {.arg client} or {.arg path}, not both"
213+
)
209214
}
210215
stopifnot(missing(api_key) || is.null(api_key) || is_string(api_key))
211216

212217
if (!missing(path)) {
213218
stopifnot(is_string(path))
214219
client <- gargle::gargle_oauth_client_from_json(path)
215220
}
216-
stopifnot(missing(client) || is.null(client) || inherits(client, "gargle_oauth_client"))
221+
stopifnot(
222+
missing(client) ||
223+
is.null(client) ||
224+
inherits(client, "gargle_oauth_client")
225+
)
217226

218227
if (!missing(client) || !missing(path)) {
219228
.auth$set_client(client)
@@ -283,8 +292,7 @@ resolve_scopes <- function(user_scopes, package_scopes) {
283292
}
284293

285294
# unexported helpers that are nice for internal use ----
286-
drive_auth_internal <- function(account = c("docs", "testing"),
287-
scopes = NULL) {
295+
drive_auth_internal <- function(account = c("docs", "testing"), scopes = NULL) {
288296
account <- match.arg(account)
289297
can_decrypt <- gargle::secret_has_key("GOOGLEDRIVE_KEY")
290298
online <- !is.null(curl::nslookup("drive.googleapis.com", error = FALSE))
@@ -296,15 +304,20 @@ drive_auth_internal <- function(account = c("docs", "testing"),
296304
c("x" = "Can't decrypt the {.field {account}} service account token.")
297305
},
298306
if (!online) {
299-
c("x" = "We don't appear to be online. Or maybe the Drive API is down?")
307+
c(
308+
"x" = "We don't appear to be online. Or maybe the Drive API is down?"
309+
)
300310
}
301311
),
302312
class = "googledrive_auth_internal_error",
303-
can_decrypt = can_decrypt, online = online
313+
can_decrypt = can_decrypt,
314+
online = online
304315
)
305316
}
306317

307-
if (!is_interactive()) local_drive_quiet()
318+
if (!is_interactive()) {
319+
local_drive_quiet()
320+
}
308321
filename <- glue("googledrive-{account}.json")
309322
# TODO: revisit when I do PKG_scopes()
310323
# https://github.com/r-lib/gargle/issues/103

R/drive_cp.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@
6868
#'
6969
#' # Clean up
7070
#' drive_rm(chicken_sheet)
71-
drive_cp <- function(file,
72-
path = NULL,
73-
name = NULL,
74-
...,
75-
overwrite = NA,
76-
verbose = deprecated()) {
71+
drive_cp <- function(
72+
file,
73+
path = NULL,
74+
name = NULL,
75+
...,
76+
overwrite = NA,
77+
verbose = deprecated()
78+
) {
7779
warn_for_verbose(verbose)
7880

7981
file <- as_dribble(file)

0 commit comments

Comments
 (0)