Created
June 15, 2019 19:16
-
-
Save brooke-watson/1516805d537e8da3a134cc6ef7c654dc to your computer and use it in GitHub Desktop.
Weekly release script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Weekly release script (modeled off of https://gist.github.com/alicegoldfuss/d9a4a8cce0b45e3d37060a07aec616dc) | |
library(httr) | |
library(tidyverse) | |
library(twilio) | |
library(emo) | |
HEADERS <- c(Accept = 'application/vnd.github.inertia-preview+json') # named vector for add_headers | |
GH_TOKEN <- "XXX" # Your auth token from https://github.com/settings/tokens | |
Sys.setenv(TWILIO_SID = "XXX") # Your Account SID from twilio.com/console | |
Sys.setenv(TWILIO_TOKEN = "XXX") # Your Auth Token from twilio.com/console | |
DONE <- "XXX" # 7-digit Done column id | |
RELEASE <- "XXX" # 7-digit Release column id | |
TW_PHONE <- "+111111111" # Your Twilio account phone number | |
PHONE <- "+111111111" # Your phone number | |
# get the done cards | |
url <- sprintf("https://api.github.com/projects/columns/%s/cards?access_token=%s", DONE, GH_TOKEN) | |
r <- httr::GET(url, add_headers(HEADERS)) | |
# pull out content from the done card "note" item | |
get_data <- content(r) | |
# sample a random emoji for the title message. you can leave this out | |
# if you want (and remove all instances of the `e` object.) | |
emojis <- c("dance", "dancer", "tada", "check", "cool", "cake", "trophy", "chart_with_upwards_trend", "boom", "crystal", "gem", "mage", "angel", "money_mouth_face", "ghost", "crown", "key", "coaster", "halo", "gymnastics", "information_desk_person", "leaf", "cowboy", "lizard", "up", "mermaid", "technologist", "nerd", "party", "partying", "celebrate", "champagne", "Puck", "rainbow", "salon", "surfer", "trident", "sparkles", "rocket", "weight", "wings", "first") | |
e <- emo::ji(sample(emojis, 1)) | |
# create new Release card using release_string | |
release_string <- str_c(emo::ji("check"), | |
purrr::map_chr(get_data, ~.x$note), | |
collapse = "\n") | |
# add the date in bold as a title for the release card. again, optional. | |
rs <- str_c("**", as.character(Sys.Date()), e, "** \n\n", release_string, collapse = "") | |
# POST content body needs to be a named list. | |
# we're putting this back into "note", the same way we took it out. | |
body <- list(note = rs) | |
# post new Release card to github project using release_string | |
url <- sprintf("https://api.github.com/projects/columns/%s/cards?access_token=%s", RELEASE, GH_TOKEN) | |
POST(url, config = add_headers(HEADERS), body = body, encode = "json") | |
# # send text message with release_string | |
msg <- paste("Your Weekly Release!", e, "\n\n", release_string) | |
tw_send_message(to = PHONE, from = TW_PHONE, body = msg) | |
# archive Done cards | |
purrr::map(get_data, ~{ | |
card <- .x$id | |
url <- sprintf("https://api.github.com/projects/columns/cards/%s?access_token=%s", card, GH_TOKEN) | |
PATCH(url, add_headers(HEADERS), body = list(archived = TRUE), encode = "json") | |
}) | |
# ---------------------------------------------------------------------------- | |
# cron job (do this bit in terminal): | |
# replace `/usr/local/bin/Rscript` with the results of `which Rscript` | |
# env EDITOR=nano crontab -e | |
# 0 17 * * FRI cd /Users/bwatson/Documents/other-projects/weekly-release && /usr/local/bin/Rscript weekly-release.R | |
# crontab -l | |
------------------------------------------------------------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment