Skip to content

Commit

Permalink
fix create_release()
Browse files Browse the repository at this point in the history
  • Loading branch information
ThierryO committed Jan 13, 2021
1 parent 9dbe1a9 commit 473431c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
38 changes: 20 additions & 18 deletions R/set_tag.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#' Otherwise it will only return a message.
#' @export
#' @inheritParams read_checklist
#' @param token The GitHub access token
#' @importFrom assertthat assert_that
#' @importFrom git2r config is_detached repository tag tags
#' @family package
set_tag <- function(x = ".") {
set_tag <- function(x = ".", token) {
if (
!as.logical(Sys.getenv("GITHUB_ACTIONS", "false")) ||
Sys.getenv("GITHUB_REF") != "refs/heads/master" ||
Expand Down Expand Up @@ -57,48 +58,49 @@ set_tag <- function(x = ".") {
user.name = "Checklist bot",
user.email = "[email protected]"
)
tag(
repo,
name = paste0("v", version),
message = paste(news[seq(start[current], end[current])], collapse = "\n")
tag_message <- paste(news[seq(start[current], end[current])], collapse = "\n")
tag(repo, name = paste0("v", version), message = tag_message)
cmd <- sprintf(
"cd %s; git push origin; git push origin v%s", repo$path, version
)
cmd <- sprintf("cd %s; git push origin v%s", repo$path, version)
message(cmd)
system(cmd)

create_release(repo = repo, version = version, message = message)
create_release(
repo = repo, version = version, tag_message = tag_message, token = token
)
return(invisible(NULL))
}

#' @importFrom httr add_headers POST
#' @importFrom git2r remote_url
create_release <- function(repo, version, message) {
create_release <- function(repo, version, tag_message, token) {
url <- remote_url(repo, "origin")
if (!grepl("github.com", url)) {
warning("no `origin` or `origin` not on GitHub.")
return(invisible(NULL))
}
owner <- gsub(".*github.com:(.*?)/(.*?)\\.git", "\\1", url)
repo <- gsub(".*github.com:(.*?)/(.*?)\\.git", "\\1", url)
owner <- tolower(gsub(".*github.com:(.*?)/(.*?)\\.git", "\\1", url))
repo <- gsub(".*github.com:(.*?)/(.*?)\\.git", "\\2", url)
url <- sprintf("https://api.github.com/repos/%s/%s/releases", owner, repo)
body <- c(
tag_name = paste0("v", version),
name = paste("Version", version),
body = message,
tag_name = paste0("\"v", version, "\""),
name = paste("\"Version", version, "\""),
body = paste0("\"", tag_message, "\""),
draft = "false",
release = "false"
prerelease = "false"
)
body <- sprintf(
"{\n%s\n}",
paste(
sprintf(" \"%s\" : \"%s\"", names(body), body),
collapse = "\n"
sprintf(" \"%s\" : %s", names(body), body),
collapse = ",\n"
)
)
POST(
url = url,
config = add_headers(
"User-Agent" = "inbo/checklist package",
# "User-Agent" = "inbo/checklist package",
Authorization = paste("Bearer", token),
accept = "application/vnd.github.v3+json"
),
body = body,
Expand Down
2 changes: 1 addition & 1 deletion entrypoint_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ elif [ "$GITHUB_REF" != "refs/heads/master" ]; then
else
git checkout master
echo '\nUpdating tag...\n';
Rscript --no-save --no-restore -e 'checklist::set_tag()';
Rscript --no-save --no-restore -e 'checklist::set_tag(token = "$2")';

echo '\nPush pkgdown website...\n'
cp -R docs ../docs
Expand Down
4 changes: 3 additions & 1 deletion man/set_tag.Rd

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

0 comments on commit 473431c

Please sign in to comment.