-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_update.R
executable file
·46 lines (37 loc) · 1.79 KB
/
git_update.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
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/Rscript
# Sorry this isn't elegant but necessary for the cron tab to work
setwd("~/Projects/Graphics/2022-log-scales-prolific/")
# Set up authentication via ssh
cred <- git2r::cred_ssh_key("~/.ssh/id_rsa.pub", "~/.ssh/id_rsa")
repo <- git2r::repository()
git2r::config(repo = repo, global = F, "Susan-auto", "[email protected]")
# Log job start
httr::POST("https://hc-ping.com/00fb59c2-a334-44ad-899a-1927e3d18023/start")
# Check repo status
status <- git2r::status()
tmp <- status$unstaged
modified <- names(tmp) == "modified"
modified <- unlist(tmp[modified])
# If db has been modified
if ("perception-of-statistical-graphics/databases/00_demographics_db.db" %in% modified |
"perception-of-statistical-graphics/databases/01_lineups_db.db" %in% modified |
"perception-of-statistical-graphics/databases/02_you_draw_it_db.db" %in% modified |
"perception-of-statistical-graphics/databases/03_estimation_db.db" %in% modified) {
# Add changed db to commit and commit
git2r::add(repo = '.', list.files("perception-of-statistical-graphics/databases/", "*.db$", full.names = T))
try(git2r::commit(message = "Update data", all = T))
# Update
git2r::pull(repo = repo, credentials = cred)
git2r::push(getwd(), credentials = cred)
if (length(git2r::status()$unstaged$conflicted) > 0) {
# Log merge conflict, signal failure (Susan gets an email)
httr::POST("https://hc-ping.com/00fb59c2-a334-44ad-899a-1927e3d18023/fail", body = "Merge conflict")
} else {
# Log success
httr::POST("https://hc-ping.com/00fb59c2-a334-44ad-899a-1927e3d18023", body = "Changes pushed")
}
} else {
# Log no changes
httr::POST("https://hc-ping.com/00fb59c2-a334-44ad-899a-1927e3d18023", body = "No changes")
}
git2r::config(repo = repo, global = F, "Susan Vanderplas", "[email protected]")