def load_config(config_file, endpoint): CommandChain.load_from_config(config_file) if endpoint != "": config.route = endpoint print("ENDPOINT : " + config.route) from pydeploy.webhook import app app.run(host="0.0.0.0", port=9999)
def setUp(self): data = { 'post_script': [], 'pre_script': [], 'remote': 'origin', 'branch': 'master' } with open("test.json", 'w') as f: json.dump(data, f) CommandChain.load_from_config("test.json") os.remove("test.json")
def test_all(self): data = { 'post_script': [ "echo " + self.first_out, "echo " + self.second_out, ], 'pre_script': [ "echo " + self.first_out, "echo " + self.second_out, ], 'remote': 'origin', 'branch': 'master' } with open(self.filename, 'w') as f: json.dump(data, f) chain = CommandChain.load_from_config(self.filename) chain.commands[0].execute() chain.commands[1].execute() chain.commands[3].execute() chain.commands[4].execute() self.assertEqual(len(chain.commands), 5) self.assertEqual(chain.commands[2].cmd, 'git pull origin master') self.assertIn(self.first_out, chain.commands[0].out) self.assertIn(self.second_out, chain.commands[1].out) self.assertIn(self.first_out, chain.commands[3].out) self.assertIn(self.second_out, chain.commands[4].out)
def deploy(): chain = CommandChain.load_from_config("") for cmd in chain.commands: cmd.kill() data = request.json ref = data['ref'] pusher_name, pusher_email = data['pusher']['name'], data['pusher']['email'] print("Push Received : ") print("Ref : {}".format(ref)) response.content_type = 'text/text; charset=UTF8' chain = CommandChain.load_from_config("") t = Thread(target=chain.execute) t.start() running_threads.append(t) return u"{} {} {}".format(ref, pusher_name, pusher_email)
def test_empty(self): data = { 'pre_script': [], 'post_script': [], 'remote': 'origin', 'branch': 'master' } with open(self.filename, 'w') as f: json.dump(data, f) chain = CommandChain.load_from_config(self.filename) self.assertEqual(len(chain.commands), 1) self.assertEqual(chain.commands[0].cmd, 'git pull origin master')
def test_notifier_loaded(self): data = { 'pre_script': [], 'post_script': [], 'remote': 'origin', 'branch': 'master', 'notifier': { 'type': 'discord', 'receiver': 'something' } } with open(self.filename, 'w') as f: json.dump(data, f) chain = CommandChain.load_from_config(self.filename) self.assertIsNotNone(chain.notifier)