Skip to content

Commit

Permalink
Adding a dry run path. Starting an adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
karlcow committed Jul 11, 2014
1 parent e2a13e3 commit edeb3a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 15 additions & 1 deletion import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

13 changes: 9 additions & 4 deletions importer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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')
Expand All @@ -119,6 +123,7 @@ def validate_json(issue_file, skip_labels=False):
print(e.message)
else:
print(e)
return False


def get_labels():
Expand Down

0 comments on commit edeb3a5

Please sign in to comment.