-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
71 lines (48 loc) · 1.61 KB
/
server.py
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
from flask import Flask, request, jsonify
import git, os, shutil
app = Flask(__name__)
@app.route('/', methods=['GET'])
def testServer():
return "Server is running"
#End point that takes in Git project URL and returns tests results
@app.route('/submit', methods=['GET'])
def register_patron():
args = request.args
remoteURL = args['git']
DIR_NAME = remoteURL.split('github.com/')[-1]
DIR_NAME = DIR_NAME.split('/')[0] + '-' + DIR_NAME.split('/')[1]
if os.path.isdir(DIR_NAME):
shutil.rmtree(DIR_NAME)
os.mkdir(DIR_NAME)
repo = git.Repo.init(DIR_NAME)
origin = repo.create_remote('origin', remoteURL)
origin.fetch()
origin.pull(origin.refs[0].remote_head)
import subprocess
subprocess.call(['sudo', './testProject.sh', DIR_NAME])
a = open(DIR_NAME + "/results.txt", 'rb')
lines = a.readlines()
if lines:
last_line = lines[-1]
last_line = str(last_line)
vals = last_line.split(',')
response = {}
response['Tests'] = vals[0].strip()
response['Assertions'] = vals[1].strip()
response['Errors'] = vals[2].strip()
return jsonify(response)
#Endpoint that takes foldername (Project location on server) and returns test results
@app.route('/runTest', methods=['GET'])
def testAll():
#Run the cron job
args = request.args
DIR_NAME = args['folderName']
import subprocess
subprocess.call(['sudo', './testProject.sh', DIR_NAME])
a = open(DIR_NAME+"/results.txt", 'rb')
lines = a.readlines()
if lines:
last_line = lines[-1]
return last_line
if __name__ == '__main__':
app.run(debug=True)