def del_one_comment(git_name, git_repository_blog, id_file=None): args = request.args.get('access_token') if not args: return jsonify({'access_token': args}) git_access = GitAccess(git_name, git_repository_blog, args) del_comment = git_access.del_comment(id_file) return '', del_comment.status_code
def save_comments_to_file(git_name, git_repository_blog): args = request.args.get('access_token') git_access = GitAccess(git_name, git_repository_blog, args) confirmed_comments = request.json added_comments = [] counter = [] data_issues = git_access.data_issue_json() data_issues = data_issues.json() for confirmed_comment in confirmed_comments: id_file = confirmed_comment['post_id'] counter.append(confirmed_comment['counter']) if len(data_issues) > 0: for issue in data_issues: if issue['title'] == id_file: get_id = git_access.get_comments() get_id = [ el for el in get_id[id_file] if el['body'] == confirmed_comment['body'] ] added_comments.append(get_id) break continue edit_file_comments( 'static/comments_%s_%s.json' % (git_name, git_repository_blog), counter) return jsonify(added_comments)
def oauth(git_name, git_repository_blog): args = request.args.get('code') if not args: return jsonify({'access_token': args}) git_access = GitAccess(git_name, git_repository_blog, args) access_token = git_access.get_access_token(args) access_token = access_token.json() return jsonify(access_token)
def delete_file(git_name, git_repository_blog, id_file, sha): args = request.args.get('access_token') if not args: return jsonify({'access_token': args}) git_access = GitAccess(git_name, git_repository_blog, args) path = 'posts/' + str(id_file) res = git_access.del_one_post(sha, path) return '', res.status_code
def edit_one_comment(git_name, git_repository_blog, id_file=None): args = request.args.get('access_token') if not args: return jsonify({'access_token': args}) git_access = GitAccess(git_name, git_repository_blog, args) data_body = request.json edit_comment = git_access.edit_comment(id_file, data_body) return '', edit_comment.status_code
def edit_file(git_name, git_repository_blog, id_file, sha): args = request.args.get('access_token') if not args: return jsonify({'access_token': args}) git_access = GitAccess(git_name, git_repository_blog, args) changes = request.json res = git_access.edit_post(changes, sha, id_file) return '', res.status_code
def get_one_comment(git_name, git_repository_blog, id_file): args = request.args.get('access_token') git_access = GitAccess(git_name, git_repository_blog, args) list_coms = git_access.get_comments() if id_file in list_coms: return jsonify(list_coms[id_file]) else: return jsonify([])
def get(self, git_name, git_repository_blog, id_comment): access_token = auth() if not access_token: return {'access_token': access_token}, 401 git_access = GitAccess(git_name, git_repository_blog, access_token) likes = git_access.get_reaction(id_comment) list_likes = [one_like for one_like in likes.json()] return list_likes
def push_master(git_name, git_repository_blog): args = request.args.get('access_token') if not args: return jsonify({'access_token': args}) git_access = GitAccess(git_name, git_repository_blog, args) changes = request.json ref = False res = git_access.new_post(changes, ref) return '', res.status_code
def repo_master(git_name, git_repository_blog, test_user): args = request.args.get('access_token') if not args: return jsonify({'access_token': args}) git_access = GitAccess(git_name, git_repository_blog, args) test = git_access.test_user_rights(test_user) if test.status_code == 200: return jsonify({'access': True}) else: return jsonify({'access': False})
def del_repo(git_name, git_repository_blog): args = request.args.get('access_token') if not args: return jsonify({'access_token': args}) git_access = GitAccess(git_name, git_repository_blog, args) data = git_access.get_all_posts() users_list = Users(git_name, git_repository_blog) session_git = users_list.open_base() users = session_git.query(Users) query_fav = session_git.query(Favorites).filter( Favorites.user_name == git_name.lower()) for one_fav in query_fav: session_git.delete(one_fav) if data.status_code == 200: for dir_ in data.json(): git_access.del_one_post(dir_['sha'], dir_['path']) for user in users: if user.user_name == git_name.lower( ) and user.user_repo_name == git_repository_blog.lower(): session_git.delete(user) session_git.commit() session_git.close() git_access.del_branch() remove_files(git_name, git_repository_blog) return '', 200 else: for user in users: if user.user_name == git_name.lower( ) and user.user_repo_name == git_repository_blog.lower(): session_git.delete(user) session_git.commit() session_git.close() git_access.del_branch() remove_files(git_name, git_repository_blog) return '', 200
def post(self, git_name, git_repository_blog, id_comment): access_token = auth() if not access_token: return {'access_token': access_token}, 401 git_access = GitAccess(git_name, git_repository_blog, access_token) root_parser = parser.add_argument('content', required=True, type=str, location='json') json_data = root_parser.parse_args(strict=True) create_like = git_access.create_reaction(id_comment, json_data) return '', create_like.status_code
def unlock_comments(git_name, git_repository_blog, id_file=None): args = request.args.get('access_token') if not args: return jsonify({'access_token': args}) git_access = GitAccess(git_name, git_repository_blog, args) data_issues = git_access.data_issue_json() data_issues = data_issues.json() len_data_issue = len_data_issues(data_issues, id_file) if not len_data_issue: return jsonify(add_new_issues(git_access, id_file)) else: lock_issue = git_access.lock_issue( len_data_issues(data_issues, id_file)) if lock_issue.status_code == 204: return jsonify({'status': False}) else: return jsonify({'status': True})
def add_one_comment(git_name, git_repository_blog, id_file=None): args = request.args.get('access_token') if not args: return jsonify({'access_token': args}) git_access = GitAccess(git_name, git_repository_blog, args) data_issues = git_access.data_issue_json() data_issues = data_issues.json() data_body = request.json all_posts = try_file(git_name, git_repository_blog) one_post = [y for y in all_posts if y['id'] == id_file][0] if len(data_issues) > 0: for issue in data_issues: if issue['title'] == id_file: add_new = git_access.add_comment(issue['number'], {'body': data_body['body']}) add_new = add_new.json() return get_file_comments( 'static/comments_%s_%s.json' % (git_name, git_repository_blog), id_file, data_body['body'], one_post['title'], add_new['id']) add_new_issue = git_access.add_new_issue(id_file) if add_new_issue.status_code == 201: issue = add_new_issue.json() add_new = git_access.add_comment(issue['number'], {'body': data_body['body']}) add_new = add_new.json() return get_file_comments( 'static/comments_%s_%s.json' % (git_name, git_repository_blog), id_file, data_body['body'], one_post['title'], add_new['id']) else: return jsonify({})
def delete_comments_from_file(git_name, git_repository_blog): args = request.args.get('access_token') if not args: return jsonify({'access_token': args}) git_access = GitAccess(git_name, git_repository_blog, args) confirmed_comments = request.json counter = [] for confirmed_comment in confirmed_comments: counter.append(confirmed_comment['counter']) edit_file_comments_2( 'static/comments_%s_%s.json' % (git_name, git_repository_blog), counter, git_access) return jsonify({'message': '%s comments deleted' % counter})
def new_file(git_name, git_repository_blog, id_file=None, sha=None): args = request.args.get('access_token') if not args: return jsonify({'access_token': args}) git_access = GitAccess(git_name, git_repository_blog, args) changes = request.json res = git_access.new_post(changes) if res.status_code == 404 and res.json( )['message'] == 'Branch post_branch not found': sha = (git_access.get_one_branch('master')).json()['object']['sha'] git_access.create_branch(sha) res = git_access.new_post(changes) return '', res.status_code
def lock_status(git_name, git_repository_blog, id_file=None): args = request.args.get('access_token') git_access = GitAccess(git_name, git_repository_blog, args) return jsonify({'status': git_access.lock_status_comment(id_file)})
def get_dict_all_comments(git_name, git_repository_blog): args = request.args.get('access_token') git_access = GitAccess(git_name, git_repository_blog, args) list_coms = git_access.get_comments() return jsonify(list_coms)