Skip to content

Commit

Permalink
Adjust package to submit to CRAN.
Browse files Browse the repository at this point in the history
  • Loading branch information
maciekbanas committed Oct 18, 2024
1 parent 901b854 commit f3ee13f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 52 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
^pkgdown$
^project_metadata.yaml
^.lintr
^CRAN-SUBMISSION$
^cran-comments\.md$
^vignettes/get_and_store_data\.Rmd$
^vignettes/get_files\.Rmd$
6 changes: 6 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ With GitStats you can pull git data in a uniform way (table format) from GitHub
## Installation

```r
From CRAN:

install.packages("GitStats")

Or development version:

devtools::install_github("r-world-devs/GitStats")
```

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ GitHub and GitLab. For the time-being you can get data on:
## Installation

``` r
From CRAN:

install.packages("GitStats")

Or development version:

devtools::install_github("r-world-devs/GitStats")
```

Expand Down
5 changes: 5 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.
50 changes: 0 additions & 50 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -1,53 +1,3 @@
if (nchar(Sys.getenv("GITHUB_PAT")) == 0) {
cli::cli_abort(c(
"x" = "You did not set up your GITHUB_PAT environment variable.",
"i" = "If you wish to run tests for GitHub - set up your GITHUB_PAT
enviroment variable (as a GitHub access token on github.com)."
))
}
if (nchar(Sys.getenv("GITHUB_PAT")) > 0) {
tryCatch({
httr2::request("https://api.github.com") %>%
httr2::req_headers("Authorization" = paste0("Bearer ", Sys.getenv("GITHUB_PAT"))) %>%
httr2::req_perform()
},
error = function(e) {
if (grepl("401", e$message)) {
cli::cli_abort(c(
"x" = "Your GITHUB_PAT enviroment variable does not grant access. Please
setup your GITHUB_PAT before running tests.",
"i" = "If you wish to run tests for GitHub - set up your GITHUB_PAT
enviroment variable (as a GitHub access token on github.com)."
))
}
})
}
if (nchar(Sys.getenv("GITLAB_PAT_PUBLIC")) == 0) {
cli::cli_abort(c(
"x" = "You did not set up your GITLAB_PAT_PUBLIC environment variable.",
"i" = "If you wish to run tests for GitLab - set up your GITLAB_PAT_PUBLIC
enviroment variable (as a GitLab access token on gitlab.com)."
))
}
if (nchar(Sys.getenv("GITLAB_PAT_PUBLIC")) > 0) {
tryCatch({
httr2::request("https://gitlab.com/api/v4/projects") %>%
httr2::req_headers("Authorization" = paste0("Bearer ",
Sys.getenv("GITLAB_PAT_PUBLIC"))) %>%
httr2::req_perform()
},
error = function(e) {
if (grepl("401", e$message)) {
cli::cli_abort(c(
"x" = "Your GITLAB_PAT_PUBLIC enviroment variable does not grant access.
Please setup your GITLAB_PAT_PUBLIC before running tests.",
"i" = "If you wish to run tests for GitLab - set up your GITLAB_PAT_PUBLIC
enviroment variable (as a GitLab access token on gitlab.com)."
))
}
})
}

test_mocker <- Mocker$new()

test_gitstats <- create_test_gitstats(hosts = 2)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ test_that("`test_token` works properly", {
})

test_that("`set_default_token` sets default token for GitLab", {
skip_on_cran()
expect_snapshot(
withr::with_envvar(new = c("GITLAB_PAT" = Sys.getenv("GITLAB_PAT_PUBLIC")), {
default_token <- gitlab_testhost_priv$set_default_token(verbose = TRUE)
Expand Down
4 changes: 2 additions & 2 deletions vignettes/set_hosts.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ When setting hosts you need to take into account:

If you connect to public hosts you simply call `set_github_host()` or `set_gitlab_host()` function without specifying `host` parameter.

```{r}
```{r, eval = FALSE}
library(GitStats)
git_stats <- create_gitstats() %>%
set_github_host(
Expand Down Expand Up @@ -72,7 +72,7 @@ When setting hosts you choose what scanning scope of your GitStats will be:

* `organizations/groups` - in this case you need to pass character arguments (names of organizations (in case of GitHub) or groups (in case of GitLab)) to `orgs` parameter.

```{r}
```{r, eval = FALSE}
git_stats <- create_gitstats() %>%
set_github_host(
orgs = c("r-world-devs", "openpharma"),
Expand Down

0 comments on commit f3ee13f

Please sign in to comment.