示例#1
0
_SLACK_MESSAGE_SUFFIX = '(sent via git-gifi)'


def _configuration(repo=None):
    repo = get_repo(repo)
    return Configuration(repo, 'slack', {
        'access-token': (NOT_SET, 'Slack access token'),
        'notification-channel': (NOT_SET, 'Slack channel to where notification will be send')
    })


def notify(message):
    config = _configuration()
    if config.notification_channel is NOT_SET:
        raise missingConfigurationException('notification-channel')
    if config.access_token is NOT_SET:
        raise missingConfigurationException('access-token')
    client = SlackClient(config.access_token)
    message = '%s %s' % (message, _SLACK_MESSAGE_SUFFIX)
    client.api_call('chat.postMessage', channel='#%s' % config.notification_channel, text=message, as_user=True, parse='full')


def missingConfigurationException(item):
    return CommandException('No slack %s is set, please do configure.' % item)


command = AggregatedCommand('slack', 'Integration with slack.', [
    Command('notify', 'Post a message on given channel.', notify, '<message>'),
    configuration_command(_configuration, 'Configure slack settings.')
])
示例#2
0
        head = current_branch

    pull_request = {
        'title': repo.head.commit.summary,
        'body': repo.head.commit.message,
        'head': head,
        'base': target_branch
    }

    logging.debug('Creating pull request with: %s' % pull_request)
    return _get_github(repo).get_repo(full_repo_name).create_pull(**pull_request)


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.')
])