diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..14159b7 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,50 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..21b8a93 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,50 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: test-coverage + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr + needs: coverage + + - name: Test coverage + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") + ) + shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/DESCRIPTION b/DESCRIPTION index ff06d69..60491fc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,6 +12,9 @@ Description: Tools and utilities for package development currently not preferences during the development process. They assist in making routine and repetitive tasks easily implementable. License: GPL (>= 3) +Imports: + stringr Encoding: UTF-8 LazyData: true RoxygenNote: 7.3.1 + diff --git a/NAMESPACE b/NAMESPACE index 6ae9268..6b909df 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,2 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(add_badge_codefactor) +export(add_badge_status) +importFrom(stringr,str_detect) +importFrom(stringr,str_replace_all) diff --git a/R/add_badge.R b/R/add_badge.R new file mode 100644 index 0000000..57f1093 --- /dev/null +++ b/R/add_badge.R @@ -0,0 +1,168 @@ +#' +#' Add repostatus badge +#' +#' @param status A character value for status to be assigned to project. This +#' can be either *"concept"*, *"wip"*, *"suspended"*, *"abandoned"*, +#' *"active"*, *"inactive"*, *"unsupported"*, or *"moved"*. +#' @param path Path to file to add repostatus badge to. Set to NULL by default +#' which would indicate that a README file in the root directory of the +#' project is the target file. +#' @param .url If `status` is "moved", the URL to which the repository has moved +#' to. Otherwise NULL. +#' +#' @returns An entry to the badge section of the README of the repository. +#' Otherwise, a print of the markdown text for the status badge. +#' +#' @examples +#' add_badge_status( +#' "wip", +#' path = system.file("examples", "README.Rmd", package = "pakete") +#' ) +#' +#' @export +#' + +add_badge_status <- function(status = c("concept", "wip", "suspended", + "abandoned", "active", "inactive", + "unsupported", "moved"), + path = NULL, + .url = NULL) { + ## Determine status ---- + status <- match.arg(status) + + ## Determine which file to append badge to ---- + if (is.null(path)) { + if (file.exists("README.Rmd")) + path <- "README.Rmd" + else + path <- "README.md" + } + + ## Determine what text to use based on status ---- + status_text_url <- paste0( + "https://www.repostatus.org/badges/latest/", status, "_md.txt" + ) + + ## Read the badge text ---- + badge_text <- readLines(con = status_text_url) + + ## Replace http://example.com with .url ---- + if (!is.null(.url)) { + badge_text <- stringr::str_replace_all( + string = badge_text, pattern = "http://example.com", replacement = .url + ) + } + + ## Read file in path ---- + readme_lines <- readLines(path, encoding = "UTF-8") + + if (all(badge_text %in% readme_lines)) + return(FALSE) + + ## Get start and end line of badges ---- + badges_start_line <- stringr::str_detect( + readme_lines, pattern = "badges: start" + ) |> + (\(x) seq_len(length(x))[x])() + + badges_end_line <- stringr::str_detect( + readme_lines, pattern = "badges: end" + ) |> + (\(x) seq_len(length(x))[x])() + + ## Create replacement text ---- + readme_lines <- c( + readme_lines[seq_len(badges_end_line - 1)], + badge_text, + readme_lines[seq(from = badges_end_line, to = length(readme_lines))] + ) + + ## Append replacement text ---- + writeLines( + text = readme_lines, + con = "README.Rmd" + ) + + TRUE +} + + +#' +#' Add CodeFactor badget +#' +#' Assumes that repository is already activated in CodeFactor. +#' +#' @param repo Short remote git repository name. If NULL, is determined based +#' on current git settings. +#' @param path Path to file to add repostatus badge to. Set to NULL by default +#' which would indicate that a README file in the root directory of the +#' project is the target file. +#' +#' @returns An entry to the badge section of the README of the repository. +#' Otherwise, a print of the markdown text for the status badge. +#' +#' @examples +#' if (FALSE) {add_badge_codefactor(repo = "katilingban/pakete")} +#' +#' @export +#' + +add_badge_codefactor <- function(repo = NULL, + path = NULL) { + ## Determine repo ---- + if (is.null(repo)) + stop("Remote git repository required. Try again") + + ## Set CodeFactor defaults ---- + badge <- paste0("https://www.codefactor.io/repository/github/", repo, "/badge") + link <- paste0("https://www.codefactor.io/repository/github/", repo) + + ## Determine which file to append badge to ---- + if (is.null(path)) { + if (file.exists("README.Rmd")) + path <- "README.Rmd" + else + path <- "README.md" + } + + ## Create badge_text ---- + badge_text <- paste0( + "[![CodeFactor](", + badge, + ")](", + link, + ")" + ) + + ## Read file in path ---- + readme_lines <- readLines(path, encoding = "UTF-8") + + if (all(badge_text %in% readme_lines)) + return(FALSE) + + ## Get start and end line of badges ---- + badges_start_line <- stringr::str_detect( + readme_lines, pattern = "badges: start" + ) |> + (\(x) seq_len(length(x))[x])() + + badges_end_line <- stringr::str_detect( + readme_lines, pattern = "badges: end" + ) |> + (\(x) seq_len(length(x))[x])() + + ## Create replacement text ---- + readme_lines <- c( + readme_lines[seq_len(badges_end_line - 1)], + badge_text, + readme_lines[seq(from = badges_end_line, to = length(readme_lines))] + ) + + ## Append replacement text ---- + writeLines( + text = readme_lines, + con = "README.Rmd" + ) + + TRUE +} diff --git a/R/pakete-package.R b/R/pakete-package.R index bbb493c..b84383a 100644 --- a/R/pakete-package.R +++ b/R/pakete-package.R @@ -7,5 +7,6 @@ #' @docType package #' @keywords internal #' @name pakete +#' @importFrom stringr str_detect str_replace_all #' "_PACKAGE" diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 0000000..8a3c585 --- /dev/null +++ b/R/utils.R @@ -0,0 +1,31 @@ +# +# Get current remote repository +# + +get_remote_repository <- function(full = FALSE) { + git_repo <- system("git remote -v", intern = TRUE) |> + (\(x) x[stringr::str_detect(string = x, pattern = "push")])() |> + stringr::str_remove_all(pattern = "origin\t| \\(push\\)") + + if (!full) { + if (stringr::str_detect(string = git_repo, pattern = "@")) { + git_repo <- stringr::str_extract_all( + string = git_repo, pattern = "[^:]*$", simplify = TRUE + ) |> + stringr::str_remove_all(pattern = "[^.]*$|\\.") |> + (\(x) x[1])() + } else { + git_repo <- stringr::str_extract_all( + string = git_repo, pattern = "[^com]*$", simplify = TRUE + ) |> + stringr::str_remove_all(pattern = "[^.]*$|\\.") |> + stringr::str_remove(pattern = "/") |> + (\(x) x[1])() + } + } + + ## Return git_repo + git_repo +} + + diff --git a/README.Rmd b/README.Rmd index 177ef77..268eb09 100644 --- a/README.Rmd +++ b/README.Rmd @@ -16,6 +16,10 @@ knitr::opts_chunk$set( # pakete: Utilities for Package Development +[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip) +[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) +[![R-CMD-check](https://github.com/katilingban/pakete/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/katilingban/pakete/actions/workflows/R-CMD-check.yaml) +[![CodeFactor](https://www.codefactor.io/repository/github/katilingban/pakete/badge)](https://www.codefactor.io/repository/github/katilingban/pakete) Tools and utilities for package development currently not available from usual development tools. These are mostly linked to personal preferences during the development process. They assist in making routine and repetitive tasks easily implementable. @@ -30,7 +34,11 @@ Currently, `pakete` includes functions for: 3. creating line snippets for `DESCRIPTION` file; -## Installation +4. creating `CONTRIBUTING.md` file; + +5. adding `repostatus` badge; + +## Installation· You can install `pakete` via the [Katilingban R-universe](https://katilingban.r-universe.dev) as follows: diff --git a/README.md b/README.md index 724a199..ac4a35f 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,14 @@ # pakete: Utilities for Package Development + +[![Project Status: WIP – Initial development is in progress, but there +has not yet been a stable, usable release suitable for the +public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip) +[![Lifecycle: +experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) +[![R-CMD-check](https://github.com/katilingban/pakete/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/katilingban/pakete/actions/workflows/R-CMD-check.yaml) +[![CodeFactor](https://www.codefactor.io/repository/github/katilingban/pakete/badge)](https://www.codefactor.io/repository/github/katilingban/pakete) Tools and utilities for package development currently not available from @@ -22,7 +30,11 @@ Currently, `pakete` includes functions for: 3. creating line snippets for `DESCRIPTION` file; -## Installation +4. creating `CONTRIBUTING.md` file; + +5. adding `repostatus` badge; + +## Installation· You can install `pakete` via the [Katilingban R-universe](https://katilingban.r-universe.dev) as follows: diff --git a/inst/examples/README.Rmd b/inst/examples/README.Rmd new file mode 100644 index 0000000..5da2ec3 --- /dev/null +++ b/inst/examples/README.Rmd @@ -0,0 +1,59 @@ +--- +output: github_document +--- + + + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "man/figures/README-", + out.width = "100%" +) +``` + +# pakete: Utilities for Package Development + + +[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip) +[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) + + +Tools and utilities for package development currently not available from usual development tools. These are mostly linked to personal preferences during the development process. They assist in making routine and repetitive tasks easily implementable. + +## What does `pakete` do? + +Currently, `pakete` includes functions for: + +1. creating GitHub checklists for tasks in the package submission process; + +2. creating `_pkgdown.yml` templates for projects that I work on; + +3. creating line snippets for `DESCRIPTION` file; + +4. creating `CONTRIBUTING.md` file; + +5. adding `repostatus` badge; + +## Installation + +You can install `pakete` via the [Katilingban R-universe](https://katilingban.r-universe.dev) as follows: + +```{r install-r-universe, eval = FALSE} +install.packages( + "pakete", + repos = c('https://katilingban.r-universe.dev', 'https://cloud.r-project.org') +) +``` + +## Usage + +## Citation + +## Community guidelines + +Feedback, bug reports and feature requests are welcome; file issues or seek support [here](https://github.com/katilingban/pakete/issues). If you would like to contribute to the package, please see our [contributing guidelines](https://katilingban.io/pakete/CONTRIBUTING.html). + +Please note that the `paketa` project is released with a [Contributor Code of Conduct](https://katilingban.io/pakete/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. + diff --git a/inst/examples/README.md b/inst/examples/README.md new file mode 100644 index 0000000..724a199 --- /dev/null +++ b/inst/examples/README.md @@ -0,0 +1,51 @@ + + + +# pakete: Utilities for Package Development + + + + +Tools and utilities for package development currently not available from +usual development tools. These are mostly linked to personal preferences +during the development process. They assist in making routine and +repetitive tasks easily implementable. + +## What does `pakete` do? + +Currently, `pakete` includes functions for: + +1. creating GitHub checklists for tasks in the package submission + process; + +2. creating `_pkgdown.yml` templates for projects that I work on; + +3. creating line snippets for `DESCRIPTION` file; + +## Installation + +You can install `pakete` via the [Katilingban +R-universe](https://katilingban.r-universe.dev) as follows: + +``` r +install.packages( + "pakete", + repos = c('https://katilingban.r-universe.dev', 'https://cloud.r-project.org') +) +``` + +## Usage + +## Citation + +## Community guidelines + +Feedback, bug reports and feature requests are welcome; file issues or +seek support [here](https://github.com/katilingban/pakete/issues). If +you would like to contribute to the package, please see our +[contributing +guidelines](https://katilingban.io/pakete/CONTRIBUTING.html). + +Please note that the `paketa` project is released with a [Contributor +Code of Conduct](https://katilingban.io/pakete/CODE_OF_CONDUCT.html). By +contributing to this project, you agree to abide by its terms. diff --git a/man/add_badge_codefactor.Rd b/man/add_badge_codefactor.Rd new file mode 100644 index 0000000..4f9dbfd --- /dev/null +++ b/man/add_badge_codefactor.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/add_badge.R +\name{add_badge_codefactor} +\alias{add_badge_codefactor} +\title{Add CodeFactor badget} +\usage{ +add_badge_codefactor(repo = NULL, path = NULL) +} +\arguments{ +\item{repo}{Short remote git repository name. If NULL, is determined based +on current git settings.} + +\item{path}{Path to file to add repostatus badge to. Set to NULL by default +which would indicate that a README file in the root directory of the +project is the target file.} +} +\value{ +An entry to the badge section of the README of the repository. + Otherwise, a print of the markdown text for the status badge. +} +\description{ +Assumes that repository is already activated in CodeFactor. +} +\examples{ +if (FALSE) {add_badge_codefactor(repo = "katilingban/pakete")} + +} diff --git a/man/add_badge_status.Rd b/man/add_badge_status.Rd new file mode 100644 index 0000000..4d3dbcc --- /dev/null +++ b/man/add_badge_status.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/add_badge.R +\name{add_badge_status} +\alias{add_badge_status} +\title{Add repostatus badge} +\usage{ +add_badge_status( + status = c("concept", "wip", "suspended", "abandoned", "active", "inactive", + "unsupported", "moved"), + path = NULL, + .url = NULL +) +} +\arguments{ +\item{status}{A character value for status to be assigned to project. This +can be either *"concept"*, *"wip"*, *"suspended"*, *"abandoned"*, +*"active"*, *"inactive"*, *"unsupported"*, or *"moved"*.} + +\item{path}{Path to file to add repostatus badge to. Set to NULL by default +which would indicate that a README file in the root directory of the +project is the target file.} + +\item{.url}{If `status` is "moved", the URL to which the repository has moved +to. Otherwise NULL.} +} +\value{ +An entry to the badge section of the README of the repository. + Otherwise, a print of the markdown text for the status badge. +} +\description{ +Add repostatus badge +} +\examples{ +add_badge_status( + "wip", + path = system.file("examples", "README.Rmd", package = "pakete") +) + +}