1
1
const dotenv = require ( 'dotenv' ) ;
2
2
const express = require ( 'express' ) ;
3
- const rp = require ( 'request-promise' ) ;
4
- const convert = require ( 'xml-js' ) ;
5
3
const app = express ( ) ;
6
- //app.disable('query parser');
7
4
dotenv . config ( ) ;
8
- const parse = require ( 'parse-link-header' ) ;
5
+ const github = require ( './server/routes/api/github' ) ;
6
+ const buildbot = require ( './server/routes/api/buildbot' ) ;
7
+ const testman = require ( './server/routes/api/testman' ) ;
9
8
const PORT = process . env . PORT || 5000 ;
10
9
const path = require ( 'path' ) ;
11
10
const dev = app . get ( 'env' ) !== 'production' ;
12
- const key = process . env . SECRET ;
13
11
14
12
//settings for production Environment
15
13
if ( ! dev ) {
@@ -18,248 +16,14 @@ if (!dev) {
18
16
app . use ( express . static ( path . join ( __dirname , 'client/build' ) ) ) ;
19
17
}
20
18
21
- //------- COMMITS END-POINT -------
19
+ //API calls to GitHub API
20
+ app . use ( '/api/github' , github ) ;
22
21
23
- function commitReq ( sha , page ) {
24
- const commits = {
25
- uri : 'https://api.github.com/repos/reactos/reactos/commits' ,
26
- resolveWithFullResponse : true ,
27
- qs : {
28
- access_token : key ,
29
- sha : sha ,
30
- per_page : 10 ,
31
- page : page
32
- } ,
33
- headers : {
34
- 'User-Agent' : 'Request-Promise'
35
- } ,
36
- json : true
37
- } ;
22
+ //API calls to BuildBot Endpoints
23
+ app . use ( '/api/buildbot' , buildbot ) ;
38
24
39
- return commits ;
40
- }
41
-
42
- app . get ( '/api/commits' , ( req , res ) => {
43
- rp ( commitReq ( req . query . sha , req . query . page ) )
44
- . then ( body => {
45
- let link = body . headers . link ;
46
- let parsed = parse ( link ) ;
47
- let dataAndPage = {
48
- page : {
49
- ...parsed
50
- } ,
51
- commits : body
52
- } ;
53
-
54
- res . json ( dataAndPage ) ;
55
- } )
56
- . catch ( function ( err ) {
57
- res . json ( { error : 'oops...something went wrong' , err : err } ) ;
58
- } ) ;
59
- } ) ;
60
-
61
- //------- BRANCHES END-POINT -------
62
-
63
- function branchReq ( ) {
64
- const branches = {
65
- uri : 'https://api.github.com/repos/reactos/reactos/branches' ,
66
- resolveWithFullResponse : false ,
67
- qs : {
68
- access_token : key ,
69
- per_page : 100
70
- } ,
71
- headers : {
72
- 'User-Agent' : 'Request-Promise'
73
- } ,
74
- json : true
75
- } ;
76
-
77
- return branches ;
78
- }
79
-
80
- app . get ( '/api/branches' , ( req , res ) => {
81
- rp ( branchReq ( ) )
82
- . then ( body => {
83
- res . json ( body ) ;
84
- } )
85
- . catch ( function ( err ) {
86
- res . json ( { error : 'oops...something went wrong' + err } ) ;
87
- } ) ;
88
- } ) ;
89
-
90
- //------- PR'S END-POINT -------
91
-
92
- function pullReq ( state , page ) {
93
- const pulls = {
94
- uri : 'https://api.github.com/repos/reactos/reactos/pulls' ,
95
- resolveWithFullResponse : true ,
96
- qs : {
97
- access_token : key ,
98
- state : state ,
99
- per_page : 10 ,
100
- page : page
101
- } ,
102
- headers : {
103
- 'User-Agent' : 'Request-Promise'
104
- } ,
105
- json : true
106
- } ;
107
-
108
- return pulls ;
109
- }
110
-
111
- app . get ( '/api/pulls' , ( req , res ) => {
112
- rp ( pullReq ( req . query . state , req . query . page ) )
113
- . then ( body => {
114
- let link = body . headers . link ;
115
- let parsed = parse ( link ) ;
116
- let dataAndPage = {
117
- page : {
118
- ...parsed
119
- } ,
120
- pulls : body
121
- } ;
122
-
123
- res . json ( dataAndPage ) ;
124
- } )
125
- . catch ( function ( err ) {
126
- res . json ( { error : 'oops...something went wrong' + err } ) ;
127
- } ) ;
128
- } ) ;
129
-
130
- //------- BUILD-SET END-POINT -------
131
-
132
- function buildSetReq ( str ) {
133
- //https://build.reactos.org/api/v2/buildsets?field=bsid&field=sourcestamps&order=-bsid&offset=0&limit=200
134
- const buildSets = {
135
- uri : `https://build.reactos.org/api/v2/buildsets?field=bsid&field=sourcestamps&field=submitted_at&order=-bsid${ str } ` ,
136
- headers : {
137
- 'User-Agent' : 'Request-Promise'
138
- } ,
139
- json : true
140
- } ;
141
-
142
- return buildSets ;
143
- }
144
-
145
- app . get ( '/api/buildsets' , ( req , res ) => {
146
- let q =
147
- '&submitted_at__le=' +
148
- req . query . submitted_at__le +
149
- '&submitted_at__ge=' +
150
- req . query . submitted_at__ge ;
151
- rp ( buildSetReq ( q ) )
152
- . then ( body => {
153
- res . json ( body ) ;
154
- } )
155
- . catch ( function ( err ) {
156
- res . json ( { error : 'oops...something went wrong' + err } ) ;
157
- } ) ;
158
- } ) ;
159
-
160
- //------- BUILD-REQUEST END-POINT -------
161
-
162
- function buildReq ( str ) {
163
- const buildReq = {
164
- uri : `https://build.reactos.org/api/v2/buildrequests?${ str } &field=buildsetid&field=buildrequestid&order=-buildsetid` ,
165
- headers : {
166
- 'User-Agent' : 'Request-Promise'
167
- } ,
168
- json : true
169
- } ;
170
-
171
- return buildReq ;
172
- }
173
-
174
- app . get ( '/api/buildreq' , ( req , res ) => {
175
- let f = req . query . buildsetid__contains ;
176
- let queryStr = f . join ( '&buildsetid__contains=' ) ;
177
- queryStr = 'buildsetid__contains=' + queryStr ;
178
- rp ( buildReq ( queryStr ) )
179
- . then ( body => {
180
- res . json ( body ) ;
181
- } )
182
- . catch ( function ( err ) {
183
- res . json ( { error : 'oops...something went wrong' + err } ) ;
184
- } ) ;
185
- } ) ;
186
-
187
- //------- BUILDS END-POINT -------
188
-
189
- function builds ( str ) {
190
- const builds = {
191
- uri : `https://build.reactos.org/api/v2/builds?${ str } &order=-buildrequestid` ,
192
- headers : {
193
- 'User-Agent' : 'Request-Promise'
194
- } ,
195
- json : true
196
- } ;
197
-
198
- return builds ;
199
- }
200
-
201
- app . get ( '/api/builds' , ( req , res ) => {
202
- let f = req . query . buildrequestid__contains ;
203
- let queryStr = f . join ( '&buildrequestid__contains=' ) ;
204
- queryStr = 'buildrequestid__contains=' + queryStr ;
205
- rp ( builds ( queryStr ) )
206
- . then ( body => {
207
- res . json ( body ) ;
208
- } )
209
- . catch ( function ( err ) {
210
- res . json ( { error : 'oops...something went wrong' + err } ) ;
211
- } ) ;
212
- } ) ;
213
-
214
- //------- BUILDERS END-POINT -------
215
-
216
- function builderReq ( ) {
217
- const builders = {
218
- uri : 'https://build.reactos.org/api/v2/builders' ,
219
- resolveWithFullResponse : false ,
220
- headers : {
221
- 'User-Agent' : 'Request-Promise'
222
- } ,
223
- json : true
224
- } ;
225
-
226
- return builders ;
227
- }
228
-
229
- app . get ( '/api/builders' , ( req , res ) => {
230
- rp ( builderReq ( ) )
231
- . then ( body => {
232
- res . json ( body ) ;
233
- } )
234
- . catch ( function ( err ) {
235
- res . json ( { error : 'oops...something went wrong' + err } ) ;
236
- } ) ;
237
- } ) ;
238
-
239
- //------- TESTMAN END-POINT -------
240
-
241
- function testReq ( startrev , endrev , page ) {
242
- const tests = {
243
- uri : `https://reactos.org/testman/ajax-search.php?startrev=${ startrev } &endrev=${ endrev } &page=${ page } &resultlist=0&requesttype=2` ,
244
- resolveWithFullResponse : false ,
245
- headers : {
246
- 'User-Agent' : 'Request-Promise'
247
- }
248
- } ;
249
-
250
- return tests ;
251
- }
252
-
253
- app . get ( '/api/testman' , ( req , res ) => {
254
- rp ( testReq ( req . query . startrev , req . query . endrev , req . query . page ) )
255
- . then ( body => {
256
- const result = convert . xml2json ( body , { compact : true , spaces : 2 } ) ;
257
- res . send ( result ) ;
258
- } )
259
- . catch ( function ( err ) {
260
- res . json ( { error : 'oops...something went wrong' + err } ) ;
261
- } ) ;
262
- } ) ;
25
+ //API calls to Testman Endpoints
26
+ app . use ( '/api/testman' , testman ) ;
263
27
264
28
if ( ! dev ) {
265
29
app . get ( '*' , ( req , res ) => {
0 commit comments