Exemplo n.º 1
0
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({})
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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})