From: Andy Doan Date: Thu, 25 Feb 2016 20:49:29 +0000 (-0600) Subject: xmlrpc: Add a check_create function X-Git-Tag: v1.1.0~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=602bffd75d123215bb4d1a8643943b739e762c36;p=thirdparty%2Fpatchwork.git xmlrpc: Add a check_create function This changes adds the ability to create Check objects via the XMLRPC interface. It includes a corresponding helper to the pwclient script. The command can be used like: pwclient check_create -c context1 -s success -u http://f.com \ -d "desc of check" PATCH_ID Signed-off-by: Andy Doan Acked-by: Stephen Finucane --- diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient index a271132c..fdd90357 100755 --- a/patchwork/bin/pwclient +++ b/patchwork/bin/pwclient @@ -242,6 +242,13 @@ def action_checks(rpc): print("%d (for '%s')" % (check['id'], check['patch'])) +def action_check_create(rpc, patch_id, context, state, url, description): + try: + rpc.check_create(patch_id, context, state, url, description) + except xmlrpclib.Fault as f: + sys.stderr.write("Error creating check: %s\n" % f.faultString) + + def action_states(rpc): states = rpc.state_list("", 0) print("%-5s %s" % ("ID", "Name")) @@ -366,7 +373,7 @@ def patch_id_from_hash(rpc, project, hash): sys.exit(1) return patch_id -auth_actions = ['update'] +auth_actions = ['check_create', 'update'] def main(): @@ -473,6 +480,18 @@ def main(): help='''Show list of patch checks''' ) checks_parser.set_defaults(subcmd='checks') + check_create_parser = subparsers.add_parser( + 'check-create', parents=[hash_parser], conflict_handler='resolve', + help='Add a check to a patch') + check_create_parser.set_defaults(subcmd='check_create') + check_create_parser.add_argument( + '-c', metavar='CONTEXT') + check_create_parser.add_argument( + '-s', choices=('pending', 'success', 'warning', 'fail')) + check_create_parser.add_argument( + '-u', metavar='TARGET_URL', default="") + check_create_parser.add_argument( + '-d', metavar='DESCRIPTION', default="") states_parser = subparsers.add_parser( 'states', help='''Show list of potential patch states''' @@ -689,7 +708,7 @@ def main(): elif action.startswith('project'): action_projects(rpc) - elif action.startswith('check'): + elif action.startswith('checks'): action_checks(rpc) elif action.startswith('state'): @@ -747,6 +766,11 @@ def main(): archived=archived_str, commit=commit_str ) + elif action == 'check_create': + for patch_id in non_empty(h, patch_ids): + action_check_create( + rpc, patch_id, args['c'], args['s'], args['u'], args['d']) + else: sys.stderr.write("Unknown action '%s'\n" % action) action_parser.print_help() diff --git a/patchwork/views/xmlrpc.py b/patchwork/views/xmlrpc.py index 2881afba..7ad34d80 100644 --- a/patchwork/views/xmlrpc.py +++ b/patchwork/views/xmlrpc.py @@ -959,6 +959,37 @@ def check_get(check_id): return {} +@xmlrpc_method(login_required=True) +def check_create(user, patch_id, context, state, target_url="", + description=""): + """Add a Check to a patch. + + **NOTE:** Authentication is required for this method. + + Args: + patch_id (id): The ID of the patch to create the check against. + context: Type of test or system that generated this check. + state: "pending", "success", "warning", or "fail" + target_url: Link to artifact(s) relating to this check. + description: A brief description of the check. + + Returns: + True, if successful else raise exception. + """ + patch = Patch.objects.get(id=patch_id) + if not patch.is_editable(user): + raise Exception('No permissions to edit this patch') + for state_val, state_str in Check.STATE_CHOICES: + if state == state_str: + state = state_val + break + else: + raise Exception("Invalid check state: %s" % state) + Check.objects.create(patch=patch, context=context, state=state, user=user, + target_url=target_url, description=description) + return True + + @xmlrpc_method() def patch_check_get(patch_id): """Get a patch's combined checks by its ID.