def gen_token(): project = request.form.get('project') if Project().is_exist(project): new_token = uuid.uuid4().hex Project().update(project, token=new_token) return json_response("token updated.") return json_response("", status='fail', error_msg='project id invalid')
def update_project_pipeline(): new_pipeline = request.form.get('pipeline') new_pipeline = new_pipeline.replace(' ', '').split(',') if new_pipeline else [] id = request.args.get('id', '') project_info = Project().update(id, pipeline=new_pipeline) if not project_info: return json_response("", status='fail', error_msg='id invalid') return json_response("pipeline updated.")
def delete_result(): id = request.args.get('id') if not id: return json_response("", status='fail', error_msg='id required') try: result = Result().delete(id) if result['n'] == 0: return json_response("", status='fail', error_msg='no such id') return json_response(result) except bson.errors.InvalidId: return json_response("", status='fail', error_msg='id invalid')
def get_project_info(): id = request.args.get('id', '') if not id: return json_response("", status='fail', error_msg='id required') project_info = Project().get(id, filter={ 'detail': 1, 'pipeline': 1, 'token': 1 }) if not project_info: return json_response("", status='fail', error_msg='id invalid') return json_response(project_info)
def get_test_result(): project_id = request.args.get('pro_id', "") result_id = request.args.get('id', '') page_index = request.args.get('p', 1, type=int) page_size = request.args.get('ps', 30, type=int) tag = request.args.get('tag', None) if result_id: result_data = Result().get(result_id) elif not project_id: return json_response("", status='fail', error_msg='id required') else: result_data = Result().get_page(project_id, tag, page_index, page_size) result_data = json_util._json_convert(result_data) return json_response(result_data)
def upload_result(): token = request.args.get('token') result = Project().col.find_one({'token': token}) if not token or not result: return json_response("", status='forbidden', error_msg='token error') new_result = request.get_json() # todo: check arguments # [] new_result['project'] = result['_id'] new_result = init_document(new_result) insert_result = Result().insert(new_result) Project().col.update({'_id': result['_id']}, {"$addToSet": { "pipeline": new_result['stage'] }}) return json_response({'inserted_id': str(insert_result.inserted_id)})
def get_latest_version(): result_data = Result().list_detail() result_data = json_util._json_convert(result_data) return json_response(result_data)
def get_version_list(): project_id = request.args.get('project', "", type=str) if not project_id: return json_response("", status='fail', error_msg='project required') result_data = Result().list_version(project_id) return json_response(result_data)