diff --git a/harbomaster/hbm.py b/harbomaster/hbm.py index da6229c..7341c39 100644 --- a/harbomaster/hbm.py +++ b/harbomaster/hbm.py @@ -1,88 +1,87 @@ from phabricator import Phabricator from . import export from .results import Results def get_phabricator_instance(ctx=None): _phab = None try: _host = None _username = None _token = None if ctx: _host = ctx.pop('HOST', None) _username = ctx.pop('USERNAME', None) _token = ctx.pop('API_TOKEN', None) _phab = Phabricator(host=_host, username=_username, token=_token) _phab.update_interfaces() # this request is just to make an actual connection _phab.user.whoami() except Exception as e: - _logger.error( - 'Could not connect to phabricator, either give the' + - ' connection with the default configuration of arc' + - ' or in the backend configuration of the configuration' + - ' file:\n' + - ' in/out:\n' + - ' username: mylogin\n' + - ' host: https://c4science.ch/\n' + - ' token: cli-g3amff25kdpnnv2tqvigmr4omnn7\n') + print('Could not connect to phabricator, either give the' + + ' connection with the default configuration of arc' + + ' or in the backend configuration of the configuration' + + ' file:\n' + + ' in/out:\n' + + ' username: mylogin\n' + + ' host: https://c4science.ch/\n' + + ' token: cli-g3amff25kdpnnv2tqvigmr4omnn7\n') raise e return _phab @export class Harbormaster: STATUS = {Results.PASS: 'pass', Results.FAIL: 'fail'} def __init__(self, **kwargs): ctx = kwargs['ctx'] self.__phid = ctx['BUILD_TARGET_PHID'] self.__phab = get_phabricator_instance(**kwargs) def _send_message(self, results): self.__phab.harbormaster.sendmessage(buildTargetPHID=self.__phid, type=self.STATUS[results]) def send_unit_tests(self, tests): _unit_tests = [] _format = tests.test_format for _test in tests: _test_dict = { 'name': _test.name, 'result': self.STATUS[_test.status], 'format': _format } if _test.duration: _test_dict['duration'] = _test.duration if _test.path: _test_dict['path'] = _test.path _unit_tests.append(_test_dict) _msg = {'buildTargetPHID': self.__phid, 'type': 'work', 'unit':_unit_tests} print(_msg) self.__phab.harbormaster.sendmessage(**_msg) def attach_uri(self, key, uri, name): self.__phab.harbormaster.createartifact(buildTargetPHID=self.__phid, artifactType='uri', artifactKey=name, artifactData={ 'uri': uri, 'name': name, 'ui.external': True }) def passed(self): self._send_message(Results.PASS) def failed(self): self._send_message(Results.PASS) diff --git a/hbm b/hbm index a995ceb..c3cf027 100755 --- a/hbm +++ b/hbm @@ -1,47 +1,47 @@ #!/usr/bin/env python3 import click import harbomaster @click.group() -@click.option('-a', '--api-token', default=None) -@click.option('-h', '--host', default=None) -@click.option('-b', '--build-target-phid') +@click.option('-a', '--api-token', default=None, envvar='API_TOKEN') +@click.option('-h', '--host', default=None, envvar='PHABRICATOR_HOST') +@click.option('-b', '--build-target-phid', envvar='BUILD_TARGET_PHID') @click.pass_context def hbm(ctx, api_token, host, build_target_phid): ctx.obj['API_TOKEN'] = api_token ctx.obj['HOST'] = host ctx.obj['BUILD_TARGET_PHID'] = build_target_phid @hbm.command() @click.option('-f', '--filename') @click.pass_context def send_ctest_results(ctx, filename): _hbm = harbomaster.Harbormaster(ctx=ctx.obj) with harbomaster.CTestResults(filename) as tests: _hbm.send_unit_tests(tests) @hbm.command() @click.option('-k', '--key') @click.option('-l', '--label') @click.pass_context def send_uri(ctx, key, label): _hbm = harbomaster.Harbormaster(ctx=ctx.obj) _hbm.send_uri(key, label) @hbm.command() @click.pass_context def passed(ctx): _hbm = harbomaster.Harbormaster(ctx=ctx.obj) _hbm.passed() @hbm.command() @click.pass_context def failed(ctx): _hbm = harbomaster.Harbormaster(ctx=ctx.obj) _hbm.failed() if __name__ == '__main__': hbm(obj={})