コード例 #1
0
ファイル: tasks.py プロジェクト: sangjeedondrub/git-webhook
def do_webhook_shell(webhook_id, histroy_id, data):
    webhook = WebHook.query.get(webhook_id)
    history = History.query.get(histroy_id)
    # server information
    ip = webhook.server.ip
    port = webhook.server.port
    account = webhook.server.account
    pkey = webhook.server.pkey
    
    # do what
    shell = webhook.shell
    
    # start to process, add history into database
    status = '2'
    history.push_user = '******' % (HookDataParse.get_push_name(data), HookDataParse.get_push_email(data))
    history.updateStatus(status)
    webhook.updateStatus(status)
    try:
        success, log = SshUtil.do_ssh_cmd(ip, port, account, pkey, shell, JsonUtil.object_2_json(data))
        status = '3'  # error
        if success:
            status = '4'  # success
    except Exception, e:
        success, log = False, 'Server SSH error: ' + str(e)
        status = '5'  # except
コード例 #2
0
ファイル: api.py プロジェクト: zhihaowen/git-webhook
def api_for_webhook(key):
    '''git hook data
    '''
    #     try:
    data = RequestUtil.get_parameter('hook', None)
    if data is None:
        data = request.data

#     for test
#     data = WebhookData.github
#     data = WebhookData.gitlab
#     data = WebhookData.gitosc
    try:
        data = json.loads(data)
        webhook = WebHook.query.filter_by(key=key).first()
        if webhook:
            repo = webhook.repo
            branch = webhook.branch

            # then repo and branch is match the config. then do the shell
            if HookDataParse.get_repo_name(
                    data) == repo and HookDataParse.get_repo_branch(
                        data) == branch:
                # start to process, add history into database
                # waiting to done
                history = History(status='1',
                                  webhook_id=webhook.id,
                                  data=JsonUtil.object_2_json(data))
                history.save()
                # status is waiting
                webhook.updateStatus('1')
                # do the async task
                tasks.do_webhook_shell.delay(webhook.id, history.id, data)
                return "Work put into Queue."

            return "Not match the Repo and Branch."
        else:
            return "The webhook is not exist."
    except Exception, e:
        return "Request is not valid Git webhook: " + str(e)
コード例 #3
0
ファイル: tasks.py プロジェクト: ldjhust/git-webhook
def do_webhook_shell(webhook_id, history_id, data):
    webhook = WebHook.query.get(webhook_id)
    history = History.query.get(history_id)
    # server information
    ip = webhook.server.ip
    port = webhook.server.port
    account = webhook.server.account
    pkey = webhook.server.pkey

    # do what
    shell = webhook.shell

    # start to process, add history into database
    status = '2'
    history.push_user = '******' % (
        HookDataParse.get_push_name(data)
        or 'WebHook', HookDataParse.get_push_email(data) or 'Web GUI')
    history.updateStatus(status)
    webhook.updateStatus(status)
    try:
        success, log = SshUtil.do_ssh_cmd(ip, port, account, pkey, shell,
                                          JsonUtil.object_2_json(data))
        status = '3'  # error
        if success:
            status = '4'  # success
    except Exception as e:
        success, log = False, 'Server SSH error: ' + str(e)
        status = '5'  # except

    # ProgrammingError: You must not use 8-bit bytestrings unless you use a
    # text_factory
    log = unicode(log)  # noqa

    history.status = status
    history.update_time = datetime.datetime.now()
    history.shell_log = log
    history.save()

    webhook.updateStatus(status)
コード例 #4
0
    # server information
    ip = webhook.server.ip
    port = webhook.server.port
    account = webhook.server.account
    pkey = webhook.server.pkey

    # do what
    shell = webhook.shell

    # start to process, add history into database
    status = '2'
    history.updateStatus(status)
    webhook.updateStatus(status)
    try:
        success, log = SshUtil.do_ssh_cmd(ip, port, account, pkey, shell,
                                          JsonUtil.object_2_json(data))
        status = '3'  # error
        if success:
            status = '4'  # success
    except Exception, e:
        success, log = False, 'Server SSH error: ' + str(e)
        status = '5'  # except

    history.status = status
    history.push_user = '******' % (HookDataParse.get_push_name(data),
                                     HookDataParse.get_push_email(data))
    history.shell_log = log
    history.save()

    webhook.updateStatus(status)