-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathgithubquery.ado
More file actions
95 lines (68 loc) · 1.87 KB
/
githubquery.ado
File metadata and controls
95 lines (68 loc) · 1.87 KB
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
*cap prog drop githubquery
program githubquery, rclass
version 14
syntax anything
qui {
preserve
drop _all
cap scalar page = fileread("https://api.github.com/repos/`anything'/releases")
if _rc {
// Identify the errors with useful information
if _rc == 679 display as err "GitHub API rate limit exceeded... try again after some time"
error _rc
}
// load data and transform to dataframe
mata {
lines = st_strscalar("page")
lines = ustrsplit(lines, ",")'
lines = strtrim(lines)
lines = stritrim(lines)
lines = subinstr(lines, `"":""', "->")
lines = subinstr(lines, `"""', "")
}
getmata lines, replace
split lines, parse ("->")
rename lines? (code url)
// get date
tempname ghpb
frame copy `c(frame)' `ghpb'
frame `ghpb' {
keep if regexm(code, "published_at")
gen n = _n
rename url date
}
// merge date and tags frames
keep if regexm(url, "releases/tag")
gen n = _n
gen tag = regexs(2) if regexm(url, "(releases/tag/)(.*)")
frlink 1:1 n, frame(`ghpb')
frget date, from(`ghpb')
// display
noi di in text _n " {hline 40}" _n ///
" {bf:Version}" _col(16) "{bf:Release Date}" _col(34) "{bf:Install} " _n ///
" {hline 40}"
local N = _N
local bskip = 8 // basic skip
local vlnth = 5 // version length
forvalues i = 1/`N' {
local link = url[`i']
local version = tag[`i']
local date = date[`i']
if regexm("`date'", "([0-9]+\-[0-9]+\-[0-9]+)(.*)") {
local date = regexs(1)
}
if (length("`version'") <= `vlnth') {
local skip = 8
}
else {
local skip = `vlnth'+`bskip' - length("`version'")
}
noi di `" {browse "`link'":`version'}"' _skip(`skip') "`date'" _skip(7) ///
"{stata github install `anything', version(`version') : Install}"
}
noi di in text " {hline 40}" _n
local latestversion = tag[1]
} // end of qui
return local latestversion `latestversion'
end
exit