diff --git a/import.py b/import.py index ab1674f..b25e7cd 100755 --- a/import.py +++ b/import.py @@ -8,8 +8,8 @@ import argparse import sys -from importer import validate_json, print_labels from importer import validate_json, print_labels, create_issue, get_as_json, format_issue +from termcolor import cprint if __name__ == '__main__': parser = argparse.ArgumentParser() @@ -30,3 +30,17 @@ sys.exit(0) # Let's get the data json_data = get_as_json(args.issue_file) + # Mode without consequences + if args.dry_run: + cprint('Test Mode Run. Nothing is sent to github', 'yellow') + webcompat_issue = format_issue(json_data, args.origin) + # Mode with consequences + else: + # Processing an issue only if it's valid + if validate_json(json_data, args.force): + create_issue(json_data) + cprint('Creating the issue on Github', 'green') + else: + cprint('Invalid JSON data for the issue', 'red') + sys.exit(0) + diff --git a/importer/__init__.py b/importer/__init__.py index 3f2e088..b05d673 100644 --- a/importer/__init__.py +++ b/importer/__init__.py @@ -40,6 +40,11 @@ def get_issue_body(json_data): json_data['body']) +def format_issue(json_data, json_format='moz'): + '''Transform the issue data into something usable by importer''' + pass + + def get_post_body(json_data): '''Create the POST "body" object.''' body = {} @@ -103,14 +108,13 @@ def get_as_json(issue_file): return r -def validate_json(issue_file, skip_labels=False): - '''Validate the structure of `file_name` against our JSON schema.''' - json_data = get_as_json(issue_file) +def validate_json(json_data, skip_labels=False): + '''Validate the structure of `json_data` against our JSON schema.''' if not skip_labels: schema['properties']['labels']['items'].update(enum=get_labels()) try: jsonschema.validate(json_data, schema) - create_issue(json_data) + return True except jsonschema.exceptions.ValidationError as e: cprint('JSON Schema validation failed:', 'white', 'on_red') print('\n') @@ -119,6 +123,7 @@ def validate_json(issue_file, skip_labels=False): print(e.message) else: print(e) + return False def get_labels():