-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_GitHub_push.R
36 lines (28 loc) · 1.73 KB
/
_GitHub_push.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# SETUP ENVIRONMENT -------------------------------------------------------
# setup libraries
library("git2r")
# instructions on how to use git2r package here https://rpubs.com/chrimaho/GitHubAutomation
library("keyring")
# you will need to make sure the "GITHUB_USER" keyring is setup
# instructions here https://rdrr.io/cran/keyring/man/backend_wincred.html
# and more on the keyring package here https://www.r-bloggers.com/how-to-hide-a-password-in-r-with-the-keyring-package/
# setup working directory
working_directory <- "U:/COVID19_Analysis"
GitHub_filepath <- paste0(working_directory, "/")
setwd(working_directory)
workdir(working_directory)
# 1. CREATE GITHUB.R FILE -------------------------------------------------
message(paste0(format(Sys.time(), "%Y-%m-%d %H:%M:%S"), ": Creating GitHub.R file"))
FileConnection <- file(GitHub_filepath)
close(FileConnection)
rm(FileConnection)
# 2. STAGE CHANGES --------------------------------------------------------
message(paste0(format(Sys.time(), "%Y-%m-%d %H:%M:%S"), ": Staging changes"))
add(repo = getwd(), path = GitHub_filepath)
# 3. COMMIT CHANGES -------------------------------------------------------
message(paste0(format(Sys.time(), "%Y-%m-%d %H:%M:%S"), ": Comitting changes"))
commit(repo = getwd(), message = "Updating data")
pull(repo = getwd(), credentials = cred_user_pass(username = "buntoss@gmail.com", password = key_get("GITHUB_USER", "buntoss@gmail.com")))
# 4. PUSH CHANGES ---------------------------------------------------------
message(paste0(format(Sys.time(), "%Y-%m-%d %H:%M:%S"), ": Pushing changes"))
push(object = getwd(), credentials = cred_user_pass(username = "buntoss@gmail.com", password = key_get("GITHUB_USER", "buntoss@gmail.com")))