Exemplo n.º 1
0
def finish(project, branch):
    # will be deprecated
    merging = get_merging(project.name, branch.name)
    if not merging:
        flash(_('You are not merging'), 'error')
        return redirect(
            url_for('branches.view',
                    project=project.name,
                    branch=branch.name,
                    filename='index.html'))
    if len(merging['modified']):
        flash(_('You still have unreviewed files'), 'error')
        return redirect(
            url_for('branches.merge',
                    project=project.name,
                    branch=branch.name,
                    other=merging['branch']))
    ####################
    git_api = branch.get_git()
    git_api.commit('-m', 'Merge ' + merging['branch'])
    merge_file_path = join('repos', project.name, branch.name, 'merging.json')
    os.remove(merge_file_path)
    if branch != branch.origin:
        git_api.push('origin', branch.name)
        flash(_('Page submitted to _%s') % branch.origin.name, 'info')
    update_subtree(project, branch)
    flash(_('You have finished merging _%s') % merging['branch'], 'info')
    return redirect(
        url_for('branches.view',
                project=project.name,
                branch=branch.name,
                filename='index'))
Exemplo n.º 2
0
def accept(project, branch, filename):
    # will be deprecated
    merging = get_merging(project.name, branch.name)
    if not merging:
        flash(_('You are not merging'), 'error')
        return redirect(
            url_for('branches.view',
                    project=project.name,
                    branch=branch.name,
                    filename='index.html'))
    if not filename in merging['modified']:
        flash(_('File %s is not being reviewed') % filename, 'error')
        return redirect(
            url_for('branches.view',
                    project=project.name,
                    branch=branch.name,
                    filename='index.html'))
    ####################
    merging['modified'].remove(filename)
    merging['reviewed'].append(filename)
    merge_file_path = join('repos', project.name, branch.name, 'merging.json')
    write_file(merge_file_path, json.dumps(merging))
    return redirect(
        url_for('branches.merge',
                project=project.name,
                branch=branch.name,
                other=merging['branch']))
Exemplo n.º 3
0
def merge(project, branch, other):
    merging = get_merging(project.name, branch.name)
    if not merging:
        if branch.is_dirty():
            flash(_('Commit your changes before reviewing requests'), 'error')
            return redirect(
                url_for('branches.commit',
                        project=project.name,
                        branch=branch.name))
        # Check if other has something to merge
        git_api = branch.get_git()
        branches = string.split(git_api.branch())
        merged = string.split(git_api.branch('--merged'))
        if other in merged:
            flash(_('Branch _%s has no requests now') % other, 'error')
            return redirect(
                url_for('branches.view',
                        project=project.name,
                        branch=branch.name,
                        filename='index.html'))
        git_api.merge('--no-commit', '--no-ff', '-s', 'recursive', '-Xtheirs',
                      other)
        modified = string.split(git_api.diff('HEAD', '--name-only'))
        merging = {'branch': other, 'modified': modified, 'reviewed': []}
        write_file(join('repos', project.name, branch.name, 'merging.json'),
                   json.dumps(merging))
    g.menu = {
        'right': [{
            'name':
            branch.name,
            'url':
            url_for('branches.merge',
                    project=project.name,
                    branch=branch.name,
                    other=other)
        }]
    }
    # Logic for diff rendering
    repo = dulwich.repo.Repo(branch.get_source_path())
    try:
        old_commit = repo['refs/heads/' + branch.name.encode('utf8')]
        new_commit = repo['refs/heads/' + merging['branch'].encode('utf8')]
    except KeyError:
        raise
    return render_template('merge.html',
                           modified=merging['modified'],
                           repo=repo,
                           old_commit=old_commit,
                           new_commit=new_commit,
                           reviewed=merging['reviewed'],
                           other=other)
Exemplo n.º 4
0
def review(project, branch, filename):
    merging = get_merging(project.name, branch.name)
    if not merging:
        flash(_('You are not merging'), 'error')
        return redirect(
            url_for('branches.view',
                    project=project.name,
                    branch=branch.name,
                    filename='index.html'))
    update_branch(project, branch)
    filename, file_extension = os.path.splitext(filename)
    branch_source_path = join(branch.get_source_path(), filename + '.rst')
    branch_html_path = join(branch.get_html_path(), filename + '.html')
    if request.method == 'POST':
        write_file(branch_source_path, request.form['code'])
        repo = branch.get_repo()
        repo.index.add([filename + '.rst'])
        return redirect(
            url_for('branches.accept',
                    project=project.name,
                    branch=branch.name,
                    filename=filename + file_extension))
    new = load_file(branch_source_path)
    git_api = branch.get_git()
    if (git_api.ls_tree('-r', '--name-only', branch.name,
                        filename + file_extension) != ''):
        old = git_api.show(branch.name + ':' + filename + file_extension)
    else:
        old = ''
    g.menu = {
        'right': [{
            'name':
            branch.name,
            'url':
            url_for('branches.edit',
                    project=project.name,
                    branch=branch.name,
                    filename=filename)
        }]
    }
    return render_template('review.html',
                           new=new,
                           old=old,
                           filename=filename + file_extension,
                           other=merging['branch'])
Exemplo n.º 5
0
def commit(project, branch):
    if (current_user != branch.owner
            and current_user != project.get_master().owner):
        flash(_('You are not the owner of this or the master branch'), 'error')
        return redirect(
            url_for('branches.view',
                    project=project.name,
                    branch=branch.name,
                    filename='index.html'))
    # will be deprecated
    merging = get_merging(project.name, branch.name)
    if merging:
        flash(_('You need to finish merging'), 'error')
        return redirect(
            url_for('branches.merge',
                    project=project.name,
                    branch=branch.name,
                    other=merging['branch']))
    ####################
    user_repo_path = join('repos', project.name, branch.name)
    repo = git.Repo(join(user_repo_path, 'source'))
    form = CommitForm(request.form)
    if request.method == 'POST' and form.validate():
        author = git.Actor(current_user.username, current_user.email)
        if len(form.message.data):
            message = form.message.data
        else:
            message = _('Some changes')
        repo.index.commit(message, author=author)
        origin = branch.origin
        if branch != origin:
            git_api = repo.git
            git_api.push('origin', branch.name)
            flash(_('Page submitted to _%s') % origin.name, 'info')
        update_subtree(project, branch)
        flash(_('Change commited'), 'info')
        return redirect(
            url_for('branches.view',
                    project=project.name,
                    branch=branch.name,
                    filename='index'))
    diff = repo.git.diff('--cached')
    return render_template('commit.html', form=form, diff=diff)