Skip to content

Commit

Permalink
add json file of timestamp for shields.io
Browse files Browse the repository at this point in the history
  • Loading branch information
tanho63 committed Mar 6, 2022
1 parent b116065 commit ba55967
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: nflversedata
Title: nflverse data storage functions
Version: 0.0.1
Version: 0.0.2
Authors@R:
person("Tan", "Ho", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-8388-5155"))
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# nflversedata 0.0.2

* Added a `NEWS.md` file to track changes to the package.
* Added timestamp.json to experiment with shields.io badges

# nflversedata 0.0.1

* Added data upload wrapper function (`nflverse_upload()`) including timestamp updates.
25 changes: 15 additions & 10 deletions R/upload.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@ nflverse_upload <- function(files, tag, ...){
update_release_timestamp <- function(tag){
x <- tempdir(check = TRUE)
on.exit(file.remove(file.path(x,"timestamp.txt")), add = TRUE)
update_time <- Sys.time()
writeLines(as.character(update_time), file.path(x,"timestamp.txt"))
piggyback::pb_upload(file.path(x,"timestamp.txt"), repo = "nflverse/nflverse-data", tag = tag, overwrite = TRUE)

current_release <- httr::GET(glue::glue("https://api.github.com/repos/nflverse/nflverse-data/releases/tags/{tag}")) |>
httr::content()
update_time <- format(Sys.time(),tz = "America/Toronto",usetz = TRUE)
writeLines(update_time, file.path(x,"timestamp.txt"))

current_body <- current_release$body
list(last_updated = update_time) |> jsonlite::toJSON(auto_unbox = TRUE) |> writeLines(file.path(x,"timestamp.json"))

new_body <- gsub("Last Updated: .*$", "",x = current_body) |> paste0("Last Updated: ",update_time)
piggyback::pb_upload(file.path(x,"timestamp.txt"), repo = "nflverse/nflverse-data", tag = tag, overwrite = TRUE)
piggyback::pb_upload(file.path(x,"timestamp.json"), repo = "nflverse/nflverse-data", tag = tag, overwrite = TRUE)

update_result <- httr::PATCH(glue::glue("https://api.github.com/repos/nflverse/nflverse-data/releases/{current_release$id}"),
httr::add_headers(Authorization = paste("token",gh::gh_token())),
body = jsonlite::toJSON(list(body = new_body),auto_unbox = TRUE))
# current_release <- httr::GET(glue::glue("https://api.github.com/repos/nflverse/nflverse-data/releases/tags/{tag}")) |>
# httr::content()
#
# current_body <- current_release$body
#
# new_body <- gsub("Last Updated: .*$", "",x = current_body) |> paste0("Last Updated: ",update_time)
#
# update_result <- httr::PATCH(glue::glue("https://api.github.com/repos/nflverse/nflverse-data/releases/{current_release$id}"),
# httr::add_headers(Authorization = paste("token",gh::gh_token())),
# body = jsonlite::toJSON(list(body = new_body),auto_unbox = TRUE))

invisible(NULL)
}

0 comments on commit ba55967

Please sign in to comment.