-
Notifications
You must be signed in to change notification settings - Fork 41
/
githubquery.ado
120 lines (95 loc) · 2.86 KB
/
githubquery.ado
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
*cap prog drop githubquery
program githubquery, rclass
syntax anything
tempfile api tmp
tempname hitch knot
capture qui copy "https://api.github.com/repos/`anything'/releases" `api', replace
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
}
file open `hitch' using "`api'", read
qui file open `knot' using "`tmp'", write replace
file read `hitch' line
//remove the beginning brackets
local line : subinstr local line "[{" ""
local line : subinstr local line "`" "", all
di in text _n " {hline 40}" _n ///
" {bf:Version}" _col(16) "{bf:Release Date}" _col(34) "{bf:Install} " _n ///
" {hline 40}"
while r(eof) == 0 {
tokenize `"`macval(line)'"' , parse(",")
while !missing(`"`macval(1)'"') {
if `"`macval(1)'"' == "," {
macro shift
}
else if `"`macval(1)'"' == "html_url" {
if strlen(`"`macval(2)'"') < strlen(`"https://github.com/`anything'/"') {
macro shift
macro shift
}
else {
file write `knot' `"`macval(1)'"' _n
macro shift
local 1 : di substr(`"`macval(1)'"', 2,.)
file write `knot' `"`macval(1)'"' _n
macro shift
}
}
else if `"`macval(1)'"' == "tag_name" {
file write `knot' `"`macval(1)'"' _n
macro shift
local a strlen(`"`macval(1)'"')
local 1 : di substr(`"`macval(1)'"', 3,`a'-3)
file write `knot' `"`macval(1)'"' _n
macro shift
}
else if `"`macval(1)'"' == "published_at" {
file write `knot' `"`macval(1)'"' _n
macro shift
local 1 : di substr(`"`macval(1)'"', 3,10)
file write `knot' `"`macval(1)'"' _n
macro shift
}
else {
macro shift
}
}
file read `hitch' line
}
file close `hitch'
file close `knot'
file open `hitch' using "`tmp'", read
file read `hitch' line
local latestversion
while r(eof) == 0 {
if `"`macval(line)'"' == "html_url" {
file read `hitch' line
local link `"`macval(line)'"'
file read `hitch' line
if `"`macval(line)'"' == "tag_name" {
file read `hitch' line
local version `"`macval(line)'"'
file read `hitch' line
}
if `"`macval(line)'"' == "published_at" {
file read `hitch' line
local date `"`macval(line)'"'
}
// get the latest version
// -----------------------------------------------------------------------
if missing("`latestversion'") local latestversion "`version'"
if !missing(`"`link'"') & !missing("`version'") & !missing("`date'") {
di `" {browse `link':`version'}"' _skip(8) "`date'" _skip(7) ///
"{stata github install `anything', version(`version') : Install}"
local link
local version
local date
}
}
file read `hitch' line
}
di in text " {hline 40}" _n
return local latestversion `latestversion'
end