Exemple #1
0
def test_run_aggregated_command_with_args():
    callable1, command1 = _test_callable('test1')
    callable2, command2 = _test_callable('test2')
    command = AggregatedCommand('aggregated', 'description of aggregated command', [command1, command2])
    assert callable1.called == False
    assert callable2.called == False
    command('test1', 'some', 'arg')
    assert callable1.called == True
    assert callable1.args == ('some', 'arg')
    assert callable2.called == False
    assert len(command.nested_commands()) == 2
Exemple #2
0
def test_run_aggregated_command_with_args():
    callable1, command1 = _test_callable('test1')
    callable2, command2 = _test_callable('test2')
    command = AggregatedCommand('aggregated',
                                'description of aggregated command',
                                [command1, command2])
    assert callable1.called == False
    assert callable2.called == False
    command('test1', 'some', 'arg')
    assert callable1.called == True
    assert callable1.args == ('some', 'arg')
    assert callable2.called == False
    assert len(command.nested_commands()) == 2
Exemple #3
0
def test_run_aggregated_command_with_no_args():
    _, command1 = _test_callable('test1')
    _, command2 = _test_callable('test2')
    command = AggregatedCommand('aggregated',
                                'description of aggregated command',
                                [command1, command2])
    command()
Exemple #4
0
        'finish-with-rebase-interactive': (False, 'Should do a rebase interactive during feature finishing'),
        'publish-with-pull-request': (False, 'Should create a pull request during feature publishing'),
        'working-remote': ('origin', 'On which remote you are working at')
    })


def is_on_feature_branch(repo):
    current_branch = git_utils.get_current_branch(repo)
    return current_branch.count('/') > 1


def _current_feature_branch(repo):
    current_branch = git_utils.get_current_branch(repo)
    if not current_branch.count('/') > 1:
        raise CommandException('Please checkout to a feature branch.')
    return current_branch


def current(repo):
    return Feature.parse(_current_feature_branch(repo))


command = AggregatedCommand('feature', 'Manages a feature branches.', [
    Command('start', 'Creates a new feature branch.', _start, '<feature name>'),
    Command('publish', 'Publishes a feature branch to review.', _publish),
    Command('finish', 'Closes and pushes a feature to a feature epic branch.', _finish),
    Command('discard', 'Closes a feature branch without a push.', _discard),
    Command('rebase', 'Rebases current feature on recent epic.', _rebase),
    configuration_command(configuration, 'Configure feature behaviour.')
])
Exemple #5
0
def _list():
    repo = get_repo()
    return repo.git.stash('list')


def _escape_new_lines(commit_message):
    """

    :type commit_message: str
    """
    return commit_message.replace('\n', '$$')


def _unescape_new_lines(commit_message):
    """

    :type commit_message: str
    """
    return commit_message.replace('$$', '\n')


command = AggregatedCommand('queue', 'Stash based commit queue.', [
    Command('pop', 'Pops a commit from the queue.', _pop),
    Command(
        'pop-finish',
        "In case of conflict during 'pop', use this command once conflict is solved.",
        _pop_finish),
    Command('push', 'Pushes a commit on the queue.', _push),
    Command('list', 'List commits in the queue.', _list)
])
Exemple #6
0
    config.set('all', ','.join(epics))


def _print_current():
    print('/'.join(current()))


def current():
    repo = get_repo()
    if gifi.feature.is_on_feature_branch(repo):
        f = gifi.feature.current(repo)
        return (f.target_remote, f.target_branch)
    else:
        return ('origin', 'master')


def configuration(repo=None):
    repo = get_repo(repo)
    return Configuration(repo, 'epic', {
        'all':
        ('origin/master', 'A list of coma separated epic remote/branch`es')
    })


command = AggregatedCommand('epic', 'Manages a epic branches.', [
    Command('list', 'List all epic branches.', _print_list),
    Command('rm', 'Remove epic branch.', _rm),
    Command('current', 'Print current epic branch.', _print_current),
    Command('add', 'Add new epic branch.', _add, '<remote/branch>')
])
Exemple #7
0
        'base': f.target_branch
    }

    logging.debug('Creating pull request with: %s' % pull_request_parameters)
    pull_request = github.create_pull(**pull_request_parameters)
    print('Pull request URL: ', pull_request.html_url)


def _missing_configuration_exception(item):
    return CommandException(
        'No github %s is set, please do configure or authorize github first.' %
        item)


def _configuration(repo=None):
    repo = get_repo(repo)
    return Configuration(
        repo, 'github', {
            'login': (NOT_SET, 'Github login'),
            'access-token': (NOT_SET, 'Github access token')
        })


command = AggregatedCommand('github', 'Integration with github.', [
    Command('authorize',
            'Create authorization and retrieve github access token.',
            _authorize),
    Command('request', 'Creates a pull request from current branch.', request),
    configuration_command(_configuration, 'Configure github settings.')
])
Exemple #8
0
import sys
import logging

from gifi.utils import git_utils
from gifi.command import Command, AggregatedCommand, UnknownCommandException, CommandException
import gifi.epic
import gifi.feature
import pkg_resources
import gifi.queue
import gifi.git_hub

logging.basicConfig(filename='/tmp/gifi.log', level=logging.DEBUG)

command = AggregatedCommand('gifi', 'Git and github enhancements to git.', [
    gifi.epic.command, gifi.feature.command, gifi.queue.command,
    gifi.git_hub.command,
    Command('version', 'Show version number.',
            lambda: pkg_resources.require("git-gifi")[0].version)
])


class HelpGenerator(object):
    def __init__(self, main):
        self.main = main

    def __call__(self):
        help = str(self.main)
        help += '\nUsage:\n\t%s command [command arguments]\n\nCommands:\n' % self.main.name

        # it does not have to be recursive as there are only two levels
        for command in self.main.nested_commands():
            help += str(command)