-
Notifications
You must be signed in to change notification settings - Fork 40
/
githubcheck.ado
90 lines (70 loc) · 2.29 KB
/
githubcheck.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
program githubcheck, rclass
syntax anything [, gettoc getpkg]
if missing("`gettoc'") & missing("`getpkg'") {
local gettoc gettoc
local getpkg getpkg
}
tempfile confirm
tempfile api
tempname hitch
if !missing("`gettoc'") {
capture quietly copy "https://api.github.com/search/code?q=in:path+filename:stata.toc+repo:`anything'" `api', replace
while _rc != 0 {
di as txt "{p}the GitHub API is not responsive right now. Try again in 10 or 20 seconds." ///
" this can happen if you search GitHub very frequent..." _n
sleep 5000
capture quietly copy "https://api.github.com/search/code?q=in:path+filename:stata.toc+repo:`anything'" `api', replace
}
file open `hitch' using "`api'", read
file read `hitch' line
// check the number of results
// --------------------------------
tokenize `"`macval(line)'"' , parse(",")
local 1 : display substr(`"`macval(1)'"',16,.)
local toc `1'
if `1' > 0 {
return local toc 1
di as txt "{bf:toc} file was found"
}
else {
return local toc 0
di as error "{bf:toc} file was NOT found"
}
file close `hitch'
}
sleep 10000
capture quietly copy "https://api.github.com/search/code?q=extension:pkg+repo:`anything'" `api', replace
while _rc != 0 {
di as txt "{p}the GitHub API is not responsive right now. Try again in 10 or 20 seconds." ///
" this can happen if you search GitHub very frequent..." _n
sleep 5000
capture quietly copy "https://api.github.com/search/code?q=extension:pkg+repo:`anything'" `api', replace
}
file open `hitch' using "`api'", read
file read `hitch' line
// check the number of results
// --------------------------------
tokenize `"`macval(line)'"' , parse(",")
local 1 : display substr(`"`macval(1)'"',16,.)
local pkg `1'
if `1' > 0 {
return local pkg 1
di as txt "`pkg' {bf:pkg} file was found"
}
else {
return local pkg 0
di as error "{bf:pkg} file was NOT found"
}
file close `hitch'
// return the results
if !missing("`gettoc'") & !missing("`getpkg'") {
if `toc' > 0 & `pkg' > 0 {
return local installable 1
di as txt "(the repository is installable)"
}
else {
return local installable 0
di as err "(the repository is NOT installable)"
}
}
end