Skip to content

Commit

Permalink
Update the URLs in use_github_actions_badge()
Browse files Browse the repository at this point in the history
Closes #1525
  • Loading branch information
jennybc committed Dec 17, 2021
1 parent eec44c8 commit aa510ec
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 26 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# usethis (development version)

`use_github_actions_badge()` now uses the same URLs as GitHub does via the "Create status badge" helper in the browser (#1525). This changes the signicance of the `name` argument; now it really must be the name of the workflow configuration file.

# usethis 2.1.5

pkgdown-related functions no longer automatically strip a trailing slash from the pkgdown site URL, in order to play more nicely with CRAN's URL checks (#1526).
Expand Down
2 changes: 1 addition & 1 deletion R/badge.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use_badge <- function(badge_name, href, src) {
)

if (changed && path_ext(path) == "Rmd") {
ui_todo("Re-knit {ui_path(path)}")
ui_todo("Re-knit {ui_path(path)} with {ui_code('devtools::build_readme()')}")
}
invisible(changed)
}
Expand Down
36 changes: 23 additions & 13 deletions R/github-actions.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
#' * Provides the markdown to insert a badge into your README
#'
#' @name github_actions

#' @param name For `use_github_action()`: Name of one of the example workflows
#' from <https://github.com/r-lib/actions/tree/v1/examples>, with or without a
#' `.yaml` extension, e.g. "pkgdown" or "test-coverage.yaml".
#' from <https://github.com/r-lib/actions/tree/v1/examples>. Examples:
#' "pkgdown", "check-standard.yaml".
#'
#' For `use_github_actions_badge()`: Name of the workflow's YAML configuration
#' file. Examples: "R-CMD-check", "R-CMD-check.yaml".
#'
#' For `use_github_actions_badge()`: Specifies the workflow whose status the
#' badge will report. Usually, this is the `name` keyword that appears in the
#' workflow `.yaml` file.
#' If `name` has no extension, we assume it's `.yaml`.
#' @eval param_repo_spec()
#' @param url The full URL to a `.yaml` file on GitHub.
#' @param save_as Name of the local workflow file. Defaults to `name` or
Expand All @@ -36,10 +38,12 @@
#' about the workflow. Ignored when `url` is `NULL`.
#' @inheritParams use_template
#'

#' @seealso
#' * [use_github_file()] for more about `url` format and parsing.
#' * [use_tidy_github_actions()] for the standard GitHub Actions used for
#' tidyverse packages.

#' @examples
#' \dontrun{
#' use_github_actions()
Expand Down Expand Up @@ -67,13 +71,17 @@ use_github_actions <- function() {
#' documented here.
#' @export
#' @rdname github_actions
use_github_actions_badge <- function(name = "R-CMD-check", repo_spec = NULL) {
use_github_actions_badge <- function(name = "R-CMD-check.yaml",
repo_spec = NULL) {
if (path_ext(name) == "") {
name <- path_ext_set(name, "yaml")
}
repo_spec <- repo_spec %||% target_repo_spec()
enc_name <- utils::URLencode(name)
img <- glue("https://github.com/{repo_spec}/workflows/{enc_name}/badge.svg")
url <- glue("https://github.com/{repo_spec}/actions")
img <- glue("https://github.com/{repo_spec}/actions/workflows/{enc_name}/badge.svg")
url <- glue("https://github.com/{repo_spec}/actions/workflows/{enc_name}")

use_badge(name, url, img)
use_badge(path_ext_remove(name), url, img)
}

uses_github_actions <- function() {
Expand Down Expand Up @@ -113,7 +121,9 @@ use_github_action <- function(name,
open = FALSE) {
if (is.null(url)) {
check_string(name)
name <- path_ext_set(name, "yaml")
if (path_ext(name) == "") {
name <- path_ext_set(name, "yaml")
}
url <- glue(
"https://raw.githubusercontent.com/r-lib/actions/v1/examples/{name}"
)
Expand Down Expand Up @@ -158,7 +168,7 @@ use_github_action_check_release <- function(save_as = "R-CMD-check.yaml",
ignore = ignore,
open = open
)
use_github_actions_badge("R-CMD-check")
use_github_actions_badge(save_as)
}

#' @section `use_github_action_check_standard()`:
Expand All @@ -178,7 +188,7 @@ use_github_action_check_standard <- function(save_as = "R-CMD-check.yaml",
ignore = ignore,
open = open
)
use_github_actions_badge("R-CMD-check")
use_github_actions_badge(save_as)
}

#' @section `use_github_action_pr_commands()`:
Expand Down Expand Up @@ -229,7 +239,7 @@ use_tidy_github_actions <- function() {
# it who are better served by something less over-the-top
# now we inline it here
full_status <- use_github_action("check-full.yaml", save_as = "R-CMD-check.yaml")
use_github_actions_badge("R-CMD-check", repo_spec = repo_spec)
use_github_actions_badge("R-CMD-check.yaml", repo_spec = repo_spec)

pr_status <- use_github_action_pr_commands()
pkgdown_status <- use_github_action("pkgdown")
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ knitr::opts_chunk$set(
# usethis <img src="man/figures/logo.png" align="right" height="139" />

<!-- badges: start -->
[![R-CMD-check](https://github.com/r-lib/usethis/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/usethis/actions)
[![R-CMD-check](https://github.com/r-lib/usethis/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/usethis/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/r-lib/usethis/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/usethis?branch=main)
[![CRAN status](https://www.r-pkg.org/badges/version/usethis)](https://CRAN.R-project.org/package=usethis)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<!-- badges: start -->

[![R-CMD-check](https://github.com/r-lib/usethis/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/usethis/actions)
[![R-CMD-check](https://github.com/r-lib/usethis/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/usethis/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/r-lib/usethis/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/usethis?branch=main)
[![CRAN
Expand Down Expand Up @@ -60,8 +60,8 @@ library(usethis)
# Create a new package -------------------------------------------------
path <- file.path(tempdir(), "mypkg")
create_package(path)
#> ✓ Creating '/tmp/Rtmp86lEpD/mypkg/'
#> ✓ Setting active project to '/private/tmp/Rtmp86lEpD/mypkg'
#> ✓ Creating '/tmp/RtmpCnD2JV/mypkg/'
#> ✓ Setting active project to '/private/tmp/RtmpCnD2JV/mypkg'
#> ✓ Creating 'R/'
#> ✓ Writing 'DESCRIPTION'
#> Package: mypkg
Expand All @@ -79,8 +79,8 @@ create_package(path)
#> ✓ Setting active project to '<no active project>'
# only needed since this session isn't interactive
proj_activate(path)
#> ✓ Setting active project to '/private/tmp/Rtmp86lEpD/mypkg'
#> ✓ Changing working directory to '/tmp/Rtmp86lEpD/mypkg/'
#> ✓ Setting active project to '/private/tmp/RtmpCnD2JV/mypkg'
#> ✓ Changing working directory to '/tmp/RtmpCnD2JV/mypkg/'

# Modify the description ----------------------------------------------
use_mit_license("My Name")
Expand Down
13 changes: 7 additions & 6 deletions man/github_actions.Rd

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

0 comments on commit aa510ec

Please sign in to comment.