-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathversion_lookup.R
138 lines (120 loc) · 4.04 KB
/
version_lookup.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# remotes::install_github("lorenzwalthert/gitsum")
if (system("whoami",intern=TRUE) == "tim"){
library(gitsum)
library(tidyverse)
library(readr)
library(lubridate)
get_versions <- function(hash){
D <- readLines(paste0("https://raw.githubusercontent.com/timriffe/DemoTools/",hash,"/DESCRIPTION") )
D[grepl(D,pattern = "Version: ")] %>%
gsub(pattern = "Version: ", replacement = "")
}
update_lookup <- function(){
DESC_changes <-
parse_log_detailed() %>%
unnest_log() %>%
dplyr::filter(changed_file == "DESCRIPTION") %>%
group_by(lubridate::as_date(date)) %>%
slice(n()) %>%
ungroup() %>%
mutate(date = as_date(date))
#date = paste(year(date),month(date),day(date),sep="-"))
# DESC_changes %>%
# mutate(get_versions(hash))
vers <- list()
for (i in 1:nrow(DESC_changes)){
# Sys.sleep(1)
vers[[i]] <- try(get_versions(DESC_changes$hash[i]))
}
closeAllConnections()
errors <- lapply(vers,class) %>% unlist()
errors <- errors == "try-error"
vers[errors]<-NA
DESC_changes <- cbind(DESC_changes,version=tibble(version=unlist(vers)))
version_lookup <-
DESC_changes %>%
filter(!is.na(version)) %>%
select(date,version, hash)
write_csv(version_lookup,"version_lookup.csv")
}
}
get_DemoTools_versions <- function(){
readr::read_csv("https://raw.githubusercontent.com/timriffe/DemoTools/master/version_lookup.csv")
}
install_DemoTools_version <- function(version = NULL, date = NULL, hash = NULL){
if (is.null(version) & is.null(date) & is.null(hash)){
cat("version identifiers include (one of):
1. Version entries in the DESCRIPTION file
2. Date (yyyy-mm-dd)
3. the hash key of the commit\n\n")
cat("no identifier given, you can view options with
get_DemoTools_version()\n\n")
cat("to install the current head, try:
remotes::install_github('timriffe/DemoTools'")
}
versions <- get_DemoTools_versions() %>%
mutate(date = lubridate::as_date(date))
out <- NULL
if (!is.null(hash)){
if (hash %in% version$hash){
remotes::install_github("timriffe/DemoTools", ref = hash)
} else {
stop("hash not found, try using one from the (incomplete) list returned by:\n get_DemoTools_versions()")
}
out <- 1
}
# try date
if (is.null(out)){
if (!is.null(date)){
if (is.character(date)){
date = lubridate::ymd(date)
}
if (is.na(date)){
cat("date didn't parse. It should be yyyy-mm-dd format if given as character\n")
stop()
}
dateK <- date
dateL <-
versions %>%
mutate(dist = abs(dateK - date)) %>%
dplyr::filter(dist == min(dist)) %>%
dplyr::pull(date) %>%
'['(1)
hash <-
versions %>%
dplyr::filter(date == dateL) %>%
dplyr::pull(hash)
remotes::install_github("timriffe/DemoTools", ref = hash)
out <- 1
if (date != dateL){
cat("date not in the (incomplete) set returned by get_DemoTools_versions()
using the closest date in that subset instead:", as.character(dateL),"\n")
}
}
}
# try version
if (is.null(out)){
if (!is.null(version)){
.version <- version
hash <-
versions %>%
dplyr::filter(version == .version) %>%
dplyr::pull(hash)
if (length(hash) == 1){
remotes::install_github("timriffe/DemoTools", ref = hash)
out <- 1
} else {
cat("version not in the set returned by get_DemoTools_versions()
we didn't try approximating. Have a look at the version snapshots available
in the lookup table.\n")
}
}
}
# catch-all
if (is.null(out)){
cat("Looks like no installation attempted. For the most recent version try:
remotes::install_github('timriffe/DemoTools')
otherwise easiest thing to roll back is to pick something
out from the lookup table.")
}
}