コード例 #1
0
    def default(self,*args, **kwargs):

        if cherrypy.request.method == "POST":
            path = "".join(args)
            payload = json.loads(kwargs["payload"])

            dispatch = Dispatch(path.lower(), payload, CONFIG_FILE)

            script = "{0}{1}/{2}".format(dispatch.dispatch_path,
                                         dispatch.repository,
                                         dispatch.script_name)

            cherrypy.log('DISPATCH Executing: {0}'.format(script))
            result = dispatch.run()

            if result['status_code'] == 0:
                message = result['message']
                cherrypy.log('DISPATCH Successful Execution: {0}'.format(script))
            elif result['status_code'] == -1:
                message = result['error']
                cherrypy.log('DISPATCH {0}: {1}'.format(message, script))
            else:
                message = result['error']
                cherrypy.log('DISPATCH Error: {0} - {1}'.format(result['status_code'],
                                                                message))

            if len(dispatch.mails) > 0:
                message = 'Repository: {0}\nBranch: {1}\nScript: {2}\n\n{3}' \
                    .format(dispatch.repository,
                            dispatch.branch, script, message)
                cherrypy.log('DISPATCH Send mails')
                dispatch.send_mails(message)

            return "Received: repository {0} of the branch {1}".\
                format(dispatch.repository, dispatch.branch)
コード例 #2
0
ファイル: test_dispatch.py プロジェクト: johnmontero/o-jigi
    def test_script_not_exist(self):
        payload = {
            "commits": [{"branch": "master"}],
            "repository": {
                "name": "foo"
            }
        }

        dispatch = Dispatch('bitbucket', payload, CONFIG_FILE)
        assert dispatch.run() == {'status_code': -1,
                                  'error': 'File does not exist'}
コード例 #3
0
ファイル: test_dispatch.py プロジェクト: johnmontero/o-jigi
    def test_run(self):
        payload = {
            "commits": [{"branch": "testing"}],
            "repository": {
                "name": "foo"
            }
        }

        dispatch = Dispatch('bitbucket', payload, CONFIG_FILE)
        r = dispatch.run()
        assert r['status_code'] == 0
        assert r['error'] == ''
        assert r['message'] == '=== sync foo ===\n=== finished ===\n'
    def test_script_not_exist(self):
        payload = {
            "commits": [{
                "branch": "master"
            }],
            "repository": {
                "name": "foo"
            }
        }

        dispatch = Dispatch('bitbucket', payload, CONFIG_FILE)
        assert dispatch.run() == {
            'status_code': -1,
            'error': 'File does not exist'
        }
    def test_run(self):
        payload = {
            "commits": [{
                "branch": "testing"
            }],
            "repository": {
                "name": "foo"
            }
        }

        dispatch = Dispatch('bitbucket', payload, CONFIG_FILE)
        r = dispatch.run()
        assert r['status_code'] == 0
        assert r['error'] == ''
        assert r['message'] == '=== sync foo ===\n=== finished ===\n'
    def test_ojigi(self):
        payload = {}

        dispatch = Dispatch('ojigi', payload, CONFIG_FILE)

        assert dispatch.repository == ''
        assert dispatch.branch == ''
    def test_mails(self):
        payload = {
            "commits": [{
                "branch": "testing"
            }],
            "repository": {
                "name": "foo"
            }
        }

        dispatch = Dispatch('bitbucket', payload, CONFIG_FILE)
        assert dispatch.mails == ['*****@*****.**', '*****@*****.**']
    def test_script_name(self):
        payload = {
            "commits": [{
                "branch": "testing"
            }],
            "repository": {
                "name": "foo"
            }
        }

        dispatch = Dispatch('bitbucket', payload, CONFIG_FILE)
        assert dispatch.script_name == 'testing.sh'
    def test_dispatch_path(self):
        payload = {
            "commits": [{
                "branch": "testing"
            }],
            "repository": {
                "name": "foo"
            }
        }

        dispatch = Dispatch('bitbucket', payload, CONFIG_FILE)
        assert dispatch.dispatch_path == './'
    def test_config_file_repo(self):
        payload = {
            "commits": [{
                "branch": "testing"
            }],
            "repository": {
                "name": "foo"
            }
        }

        dispatch = Dispatch('bitbucket', payload, CONFIG_FILE)
        assert dispatch.config_file_repo == './foo/config.ini'
    def test_github(self):
        payload = {"ref": "refs/heads/testing", "repository": {"name": "foo"}}

        dispatch = Dispatch('github', payload, CONFIG_FILE)
        assert dispatch.repository == 'foo'
        assert dispatch.branch == 'testing'