-
Notifications
You must be signed in to change notification settings - Fork 12
/
github-tools.red
156 lines (141 loc) · 2.94 KB
/
github-tools.red
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
Red[]
#include %apis/github-v3.red
;#include %github-options.red
#include %qobom.red
#include %packers/zip.red
#include %../castr/http-scheme.red
; --- support
numbers: charset "0123456789"
; --- loading functions
init: does [
issues: get-issues
commits: get-commits
; Cache downloaded data
save %issues.red issues
save %commits.red commits
]
get-issues: func [
/local page issues repo
] [
issues: copy []
repo: 'red/red
; get last 30 issues
page: github/get-issues/repo/with repo [state: 'all]
; get total page count
print ["Downloading" page/1/number "issues."]
pages: page/1/number / 30
append issues page
repeat page pages [
print ["Issues - page" page #"/" pages]
append issues github/get-issues/repo/page/with repo page + 1 [state: 'all]
]
issues
]
get-commits: func [
/local page commits repo
][
commits: copy []
page: 1
repo: 'red/red
until [
data: github/get-commits/page repo page
print ["Commits - page" page]
append commits data
page: page + 1
empty? data
]
commits
]
; --- functions working on downloaded data
get-column: func [
data
column
/local line result value
][
result: copy []
foreach line data [
value: pick line column
unless find result value [append result value]
]
result
]
get-authors: func [
issues
/local
][
authors: make map! []
foreach issue issues [
author: issue/user/login
either authors/:author [authors/:author: authors/:author + 1][authors/:author: 1]
]
authors
]
get-fixes: func [
"Return commits that are fixes to issues (message contains #XXXX)"
commits
/local fixes
][
fixes: copy []
foreach commit commits [
issue: none
parse commit/commit/message [thru #"#" copy issue some numbers]
if issue [repend fixes [issue commit]]
]
fixes
]
qget-fixes: func [
"Return commits that are fixes to issues (message contains #XXXX)"
commits
][
qobom commits ['commit/message matches [thru #"#" some numbers to end]]
]
get-issue-by-number: func [
issues
number
][
foreach issue issues [
if equal? issue/number number [return issue]
]
none
]
get-aoiltf: func [
"get authors of issues leading to fixes"
commits
issues
][
authors: make map! []
fixes: get-fixes commits
foreach [id commit] fixes [
id: to integer! id
if issue: get-issue-by-number issues id [
; NOTE: some messages may point to non-existent issue (because they point to something different, see commit "bc6d27c1d0ae89237ce9cbddb7fe593924d482e8")
author: issue/user/login
either authors/:author [
append authors/:author id ;TODO: or issue directly, let's see
][
authors/:author: reduce [id]
]
]
]
authors
]
clone: func [
repo [path!]
/branch
name
/local data file content
] [
name: any [name "master"]
; download ZIP archive
repo: rejoin [https://codeload.github.com/ repo %/zip/refs/heads/ name]
data: load-zip read/binary repo
; save files
foreach [file content] data [
append out file
either dir? file [
make-dir/deep file
][
write/binary file content
]
]
]