-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
95 lines (74 loc) · 3.1 KB
/
server.py
File metadata and controls
95 lines (74 loc) · 3.1 KB
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
import os
from flask import Flask
from flask import request
from flask import jsonify
from git import Repo
import returncodes as status
import stats as stats
def create_app(test_config=None):
app = init(test_config)
@app.route('/')
def home():
return "This is a server. Why are you here?"
@app.route('/set-repo')
def set_repo():
repo_url = request.args.get('url')
if repo_url is None:
return jsonify(status=status.bad_request, message="URL not requested", payload=[])
repo = stats.set_repo_impl(repo_url)
if repo.bare:
return jsonify(status=status.clone_failed, message="Clone Failed", payload=[])
return jsonify(status=status.clone_success, message='OK', payload=[])
@app.route('/delete-repo')
def delete_repo():
repo = request.args.get('url')
delete_repo_impl(stats.set_repo_impl(repo))
return jsonify(status=status.request_success, message='OK', payload=[])
@app.route('/contributions/daily')
def contributions_daily():
repo = request.args.get('url')
return jsonify(status=status.request_success, message='OK', payload=stats.contributions_daily_impl(stats.set_repo_impl(repo)))
@app.route('/contributions/authors')
def contributions_authors():
repo = request.args.get('url')
return jsonify(status=status.request_success, message='OK', payload=stats.contributions_authors_impl(stats.set_repo_impl(repo)))
@app.route('/commit/lengths')
def commit_lengths():
repo = request.args.get('url')
return jsonify(status=status.request_success, message='OK', payload=stats.commit_lengths_impl(stats.set_repo_impl(repo)))
@app.route('/messages/words')
def messages_words():
repo = request.args.get('url')
return jsonify(status=status.request_success, message='OK', payload=stats.messages_words_impl(stats.set_repo_impl(repo)))
@app.route('/commit/times')
def commit_times():
repo = request.args.get('url')
return jsonify(status=status.request_success, message='OK', payload=stats.commit_times_impl(stats.set_repo_impl(repo)))
@app.route('/messages/emotions')
def messages_emotions():
repo = request.args.get('url')
return jsonify(status=status.request_success, message='OK', payload=stats.messages_emotions_impl(stats.set_repo_impl(repo)))
@app.after_request
def after_request(response):
header = response.headers
header['Access-Control-Allow-Origin'] = '*'
return response
return app
def init(test_config=None):
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
SECRET_KEY='dev',
)
if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile('config.py', silent=True)
else:
# load the test config if passed in
app.config.from_mapping(test_config)
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
return app