{"action":"created","comment":{"url":"https://api.github.com/repos/studentinsights/studentinsights/pulls/comments/194483354","pull_request_review_id":127664684,"id":194483354,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NDQ4MzM1NA==","diff_hunk":"@@ -1,38 +1,45 @@\n class ImportTask\n-  def initialize(options:)\n-    @options = options\n+  # If passed invalid arguments, validete and fail in the constructor\n+  def initialize(options = {})\n+    @options = options.symbolize_keys\n \n-    # options[\"school\"] is an optional filter; imports all schools if nil\n-    @school = @options.fetch(\"school\", nil)\n+    # which schools to include\n+    @school_local_ids = validate_school_local_ids!(@options[:school_local_ids])\n \n-    # options[\"source\"] describes which external data sources to import from\n-    @source = @options.fetch(\"source\", [\"x2\", \"star\"])\n+    # which importers to run\n+    @importer_descriptions = validate_importer_keys!(@options[:importer_keys])\n \n-    # options[\"only_recent_attendance\"]\n-    @only_recent_attendance = @options.fetch(\"only_recent_attendance\", false)\n+    # only recent attendance data, or all of it\n+    raise 'missing only_recent_attendance' unless @options.has_key?(:only_recent_attendance)\n+    @only_recent_attendance = @options[:only_recent_attendance]\n \n-    @log = Rails.env.test? ? LogHelper::Redirect.instance.file : STDOUT\n+    # log differently based on env\n+    @log = pick_log_based_on_env(options)\n   end\n \n   def connect_transform_import\n     begin\n+      log('Setting up logging...')\n       @record = create_import_record\n+      log('Done logging.')\n+\n+      log('Running inital report...')\n       @report = create_report\n-      log('Starting validation...')\n-      validate_district_option\n-      seed_schools_if_needed\n-      validate_school_options","path":"app/importers/import_task.rb","position":40,"original_position":40,"commit_id":"86ed327067b0ac67143fa2d6f57dda0f13669c17","original_commit_id":"86ed327067b0ac67143fa2d6f57dda0f13669c17","user":{"login":"kevinrobinson","id":1056957,"node_id":"MDQ6VXNlcjEwNTY5NTc=","avatar_url":"https://avatars3.githubusercontent.com/u/1056957?v=4","gravatar_id":"","url":"https://api.github.com/users/kevinrobinson","html_url":"https://github.com/kevinrobinson","followers_url":"https://api.github.com/users/kevinrobinson/followers","following_url":"https://api.github.com/users/kevinrobinson/following{/other_user}","gists_url":"https://api.github.com/users/kevinrobinson/gists{/gist_id}","starred_url":"https://api.github.com/users/kevinrobinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevinrobinson/subscriptions","organizations_url":"https://api.github.com/users/kevinrobinson/orgs","repos_url":"https://api.github.com/users/kevinrobinson/repos","events_url":"https://api.github.com/users/kevinrobinson/events{/privacy}","received_events_url":"https://api.github.com/users/kevinrobinson/received_events","type":"User","site_admin":false},"body":"Validation is moved up to the constructor so invalid args fail before any work can be done, and seeding is removed here.","created_at":"2018-06-11T17:28:17Z","updated_at":"2018-06-11T17:28:17Z","html_url":"https://github.com/studentinsights/studentinsights/pull/1785#discussion_r194483354","pull_request_url":"https://api.github.com/repos/studentinsights/studentinsights/pulls/1785","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/studentinsights/studentinsights/pulls/comments/194483354"},"html":{"href":"https://github.com/studentinsights/studentinsights/pull/1785#discussion_r194483354"},"pull_request":{"href":"https://api.github.com/repos/studentinsights/studentinsights/pulls/1785"}}},"pull_request":{"url":"https://api.github.com/repos/studentinsights/studentinsights/pulls/1785","id":194049381,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk0MDQ5Mzgx","html_url":"https://github.com/studentinsights/studentinsights/pull/1785","diff_url":"https://github.com/studentinsights/studentinsights/pull/1785.diff","patch_url":"https://github.com/studentinsights/studentinsights/pull/1785.patch","issue_url":"https://api.github.com/repos/studentinsights/studentinsights/issues/1785","number":1785,"state":"open","locked":false,"title":"Allow running single importer jobs, remove Thor and add initial importer specs","user":{"login":"kevinrobinson","id":1056957,"node_id":"MDQ6VXNlcjEwNTY5NTc=","avatar_url":"https://avatars3.githubusercontent.com/u/1056957?v=4","gravatar_id":"","url":"https://api.github.com/users/kevinrobinson","html_url":"https://github.com/kevinrobinson","followers_url":"https://api.github.com/users/kevinrobinson/followers","following_url":"https://api.github.com/users/kevinrobinson/following{/other_user}","gists_url":"https://api.github.com/users/kevinrobinson/gists{/gist_id}","starred_url":"https://api.github.com/users/kevinrobinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevinrobinson/subscriptions","organizations_url":"https://api.github.com/users/kevinrobinson/orgs","repos_url":"https://api.github.com/users/kevinrobinson/repos","events_url":"https://api.github.com/users/kevinrobinson/events{/privacy}","received_events_url":"https://api.github.com/users/kevinrobinson/received_events","type":"User","site_admin":false},"body":"# Who is this PR for?\r\ndevelopers\r\nFor https://github.com/studentinsights/studentinsights/issues/1657, I want to be able to run a single importer.  I want to be able to do this for https://github.com/studentinsights/studentinsights/issues/1626 as well, and to have some more spec coverage if we make any changes around logging or handling failures.\r\n\r\n# What problem does this PR fix?\r\nRight now we can't run a single importer.  Making changes to the thor defaults requires using the DSL (eg, factoring a constant out to a method didn't just work) and without being able to write tests changes there are more dangerous.  There are multiple files describing the importer classes, and it's hard to see how they relate.  Running the import task seeds the database with schools in a way that is unexpected for an import task.\r\n\r\n# What does this PR do?\r\n- allow running a single importer on the command line\r\n- replace Thor with a Rake task using builtin `OptionParser`, and add specs for command line parsing\r\n- move code describing the importers into `FileImporterOptions` and make order explicit\r\n- removing seeding schools from the import job\r\n- add some tests for these changes\r\n- adds changes to the set of importers or their priority to mentionbot\r\n\r\n# Screenshot (if adding a client-side feature)\r\nThis is the rake task:\r\n```\r\n$ bundle exec rake import:run -- --help\r\nUsage: bundle exec rake import:run -- [options]\r\n        --background                 Add job into DelayedJob queue.\r\n        --only-recent-attendance     Only import attendance rows from the past 90 days for faster attendance import.\r\n        --school-local-ids x,y,z     Scope import to only these school local_ids (not Insights school.id).\r\n        --importer-keys x,y,z        Import data from one of EducatorsImporter, CoursesSectionsImporter, EducatorSectionAssignmentsImporter, StudentsImporter, StudentSectionAssignmentsImporter, BehaviorImporter, AttendanceImporter, StudentSectionGradesImporter, X2AssessmentImporter, StarMathImporter, StarReadingImporter.\r\n```\r\n\r\n# Checklists\r\n+ [x] Author improved specs for code in need of better test coverage\r\n+ [x] Author included specs for new code\r\n","created_at":"2018-06-11T17:25:07Z","updated_at":"2018-06-11T17:28:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ca16dc055d0ef28596adfe913030d36a5c383540","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/studentinsights/studentinsights/pulls/1785/commits","review_comments_url":"https://api.github.com/repos/studentinsights/studentinsights/pulls/1785/comments","review_comment_url":"https://api.github.com/repos/studentinsights/studentinsights/pulls/comments{/number}","comments_url":"https://api.github.com/repos/studentinsights/studentinsights/issues/1785/comments","statuses_url":"https://api.github.com/repos/studentinsights/studentinsights/statuses/86ed327067b0ac67143fa2d6f57dda0f13669c17","head":{"label":"studentinsights:patch/more-explicit-import-options","ref":"patch/more-explicit-import-options","sha":"86ed327067b0ac67143fa2d6f57dda0f13669c17","user":{"login":"studentinsights","id":17129837,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE3MTI5ODM3","avatar_url":"https://avatars2.githubusercontent.com/u/17129837?v=4","gravatar_id":"","url":"https://api.github.com/users/studentinsights","html_url":"https://github.com/studentinsights","followers_url":"https://api.github.com/users/studentinsights/followers","following_url":"https://api.github.com/users/studentinsights/following{/other_user}","gists_url":"https://api.github.com/users/studentinsights/gists{/gist_id}","starred_url":"https://api.github.com/users/studentinsights/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/studentinsights/subscriptions","organizations_url":"https://api.github.com/users/studentinsights/orgs","repos_url":"https://api.github.com/users/studentinsights/repos","events_url":"https://api.github.com/users/studentinsights/events{/privacy}","received_events_url":"https://api.github.com/users/studentinsights/received_events","type":"Organization","site_admin":false},"repo":{"id":51324046,"node_id":"MDEwOlJlcG9zaXRvcnk1MTMyNDA0Ng==","name":"studentinsights","full_name":"studentinsights/studentinsights","owner":{"login":"studentinsights","id":17129837,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE3MTI5ODM3","avatar_url":"https://avatars2.githubusercontent.com/u/17129837?v=4","gravatar_id":"","url":"https://api.github.com/users/studentinsights","html_url":"https://github.com/studentinsights","followers_url":"https://api.github.com/users/studentinsights/followers","following_url":"https://api.github.com/users/studentinsights/following{/other_user}","gists_url":"https://api.github.com/users/studentinsights/gists{/gist_id}","starred_url":"https://api.github.com/users/studentinsights/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/studentinsights/subscriptions","organizations_url":"https://api.github.com/users/studentinsights/orgs","repos_url":"https://api.github.com/users/studentinsights/repos","events_url":"https://api.github.com/users/studentinsights/events{/privacy}","received_events_url":"https://api.github.com/users/studentinsights/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/studentinsights/studentinsights","description":"Student Insights for Somerville and New Bedford educators","fork":false,"url":"https://api.github.com/repos/studentinsights/studentinsights","forks_url":"https://api.github.com/repos/studentinsights/studentinsights/forks","keys_url":"https://api.github.com/repos/studentinsights/studentinsights/keys{/key_id}","collaborators_url":"https://api.github.com/repos/studentinsights/studentinsights/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/studentinsights/studentinsights/teams","hooks_url":"https://api.github.com/repos/studentinsights/studentinsights/hooks","issue_events_url":"https://api.github.com/repos/studentinsights/studentinsights/issues/events{/number}","events_url":"https://api.github.com/repos/studentinsights/studentinsights/events","assignees_url":"https://api.github.com/repos/studentinsights/studentinsights/assignees{/user}","branches_url":"https://api.github.com/repos/studentinsights/studentinsights/branches{/branch}","tags_url":"https://api.github.com/repos/studentinsights/studentinsights/tags","blobs_url":"https://api.github.com/repos/studentinsights/studentinsights/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/studentinsights/studentinsights/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/studentinsights/studentinsights/git/refs{/sha}","trees_url":"https://api.github.com/repos/studentinsights/studentinsights/git/trees{/sha}","statuses_url":"https://api.github.com/repos/studentinsights/studentinsights/statuses/{sha}","languages_url":"https://api.github.com/repos/studentinsights/studentinsights/languages","stargazers_url":"https://api.github.com/repos/studentinsights/studentinsights/stargazers","contributors_url":"https://api.github.com/repos/studentinsights/studentinsights/contributors","subscribers_url":"https://api.github.com/repos/studentinsights/studentinsights/subscribers","subscription_url":"https://api.github.com/repos/studentinsights/studentinsights/subscription","commits_url":"https://api.github.com/repos/studentinsights/studentinsights/commits{/sha}","git_commits_url":"https://api.github.com/repos/studentinsights/studentinsights/git/commits{/sha}","comments_url":"https://api.github.com/repos/studentinsights/studentinsights/comments{/number}","issue_comment_url":"https://api.github.com/repos/studentinsights/studentinsights/issues/comments{/number}","contents_url":"https://api.github.com/repos/studentinsights/studentinsights/contents/{+path}","compare_url":"https://api.github.com/repos/studentinsights/studentinsights/compare/{base}...{head}","merges_url":"https://api.github.com/repos/studentinsights/studentinsights/merges","archive_url":"https://api.github.com/repos/studentinsights/studentinsights/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/studentinsights/studentinsights/downloads","issues_url":"https://api.github.com/repos/studentinsights/studentinsights/issues{/number}","pulls_url":"https://api.github.com/repos/studentinsights/studentinsights/pulls{/number}","milestones_url":"https://api.github.com/repos/studentinsights/studentinsights/milestones{/number}","notifications_url":"https://api.github.com/repos/studentinsights/studentinsights/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/studentinsights/studentinsights/labels{/name}","releases_url":"https://api.github.com/repos/studentinsights/studentinsights/releases{/id}","deployments_url":"https://api.github.com/repos/studentinsights/studentinsights/deployments","created_at":"2016-02-08T20:15:35Z","updated_at":"2018-06-11T17:19:11Z","pushed_at":"2018-06-11T17:25:56Z","git_url":"git://github.com/studentinsights/studentinsights.git","ssh_url":"git@github.com:studentinsights/studentinsights.git","clone_url":"https://github.com/studentinsights/studentinsights.git","svn_url":"https://github.com/studentinsights/studentinsights","homepage":"https://somerville-teacher-tool-demo.herokuapp.com/","size":18459,"stargazers_count":89,"watchers_count":89,"language":"JavaScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":45,"mirror_url":null,"archived":false,"open_issues_count":102,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":45,"open_issues":102,"watchers":89,"default_branch":"master"}},"base":{"label":"studentinsights:master","ref":"master","sha":"450d7f3af224e1efe2b0b70546b1f7b202e0d26c","user":{"login":"studentinsights","id":17129837,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE3MTI5ODM3","avatar_url":"https://avatars2.githubusercontent.com/u/17129837?v=4","gravatar_id":"","url":"https://api.github.com/users/studentinsights","html_url":"https://github.com/studentinsights","followers_url":"https://api.github.com/users/studentinsights/followers","following_url":"https://api.github.com/users/studentinsights/following{/other_user}","gists_url":"https://api.github.com/users/studentinsights/gists{/gist_id}","starred_url":"https://api.github.com/users/studentinsights/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/studentinsights/subscriptions","organizations_url":"https://api.github.com/users/studentinsights/orgs","repos_url":"https://api.github.com/users/studentinsights/repos","events_url":"https://api.github.com/users/studentinsights/events{/privacy}","received_events_url":"https://api.github.com/users/studentinsights/received_events","type":"Organization","site_admin":false},"repo":{"id":51324046,"node_id":"MDEwOlJlcG9zaXRvcnk1MTMyNDA0Ng==","name":"studentinsights","full_name":"studentinsights/studentinsights","owner":{"login":"studentinsights","id":17129837,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE3MTI5ODM3","avatar_url":"https://avatars2.githubusercontent.com/u/17129837?v=4","gravatar_id":"","url":"https://api.github.com/users/studentinsights","html_url":"https://github.com/studentinsights","followers_url":"https://api.github.com/users/studentinsights/followers","following_url":"https://api.github.com/users/studentinsights/following{/other_user}","gists_url":"https://api.github.com/users/studentinsights/gists{/gist_id}","starred_url":"https://api.github.com/users/studentinsights/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/studentinsights/subscriptions","organizations_url":"https://api.github.com/users/studentinsights/orgs","repos_url":"https://api.github.com/users/studentinsights/repos","events_url":"https://api.github.com/users/studentinsights/events{/privacy}","received_events_url":"https://api.github.com/users/studentinsights/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/studentinsights/studentinsights","description":"Student Insights for Somerville and New Bedford educators","fork":false,"url":"https://api.github.com/repos/studentinsights/studentinsights","forks_url":"https://api.github.com/repos/studentinsights/studentinsights/forks","keys_url":"https://api.github.com/repos/studentinsights/studentinsights/keys{/key_id}","collaborators_url":"https://api.github.com/repos/studentinsights/studentinsights/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/studentinsights/studentinsights/teams","hooks_url":"https://api.github.com/repos/studentinsights/studentinsights/hooks","issue_events_url":"https://api.github.com/repos/studentinsights/studentinsights/issues/events{/number}","events_url":"https://api.github.com/repos/studentinsights/studentinsights/events","assignees_url":"https://api.github.com/repos/studentinsights/studentinsights/assignees{/user}","branches_url":"https://api.github.com/repos/studentinsights/studentinsights/branches{/branch}","tags_url":"https://api.github.com/repos/studentinsights/studentinsights/tags","blobs_url":"https://api.github.com/repos/studentinsights/studentinsights/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/studentinsights/studentinsights/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/studentinsights/studentinsights/git/refs{/sha}","trees_url":"https://api.github.com/repos/studentinsights/studentinsights/git/trees{/sha}","statuses_url":"https://api.github.com/repos/studentinsights/studentinsights/statuses/{sha}","languages_url":"https://api.github.com/repos/studentinsights/studentinsights/languages","stargazers_url":"https://api.github.com/repos/studentinsights/studentinsights/stargazers","contributors_url":"https://api.github.com/repos/studentinsights/studentinsights/contributors","subscribers_url":"https://api.github.com/repos/studentinsights/studentinsights/subscribers","subscription_url":"https://api.github.com/repos/studentinsights/studentinsights/subscription","commits_url":"https://api.github.com/repos/studentinsights/studentinsights/commits{/sha}","git_commits_url":"https://api.github.com/repos/studentinsights/studentinsights/git/commits{/sha}","comments_url":"https://api.github.com/repos/studentinsights/studentinsights/comments{/number}","issue_comment_url":"https://api.github.com/repos/studentinsights/studentinsights/issues/comments{/number}","contents_url":"https://api.github.com/repos/studentinsights/studentinsights/contents/{+path}","compare_url":"https://api.github.com/repos/studentinsights/studentinsights/compare/{base}...{head}","merges_url":"https://api.github.com/repos/studentinsights/studentinsights/merges","archive_url":"https://api.github.com/repos/studentinsights/studentinsights/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/studentinsights/studentinsights/downloads","issues_url":"https://api.github.com/repos/studentinsights/studentinsights/issues{/number}","pulls_url":"https://api.github.com/repos/studentinsights/studentinsights/pulls{/number}","milestones_url":"https://api.github.com/repos/studentinsights/studentinsights/milestones{/number}","notifications_url":"https://api.github.com/repos/studentinsights/studentinsights/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/studentinsights/studentinsights/labels{/name}","releases_url":"https://api.github.com/repos/studentinsights/studentinsights/releases{/id}","deployments_url":"https://api.github.com/repos/studentinsights/studentinsights/deployments","created_at":"2016-02-08T20:15:35Z","updated_at":"2018-06-11T17:19:11Z","pushed_at":"2018-06-11T17:25:56Z","git_url":"git://github.com/studentinsights/studentinsights.git","ssh_url":"git@github.com:studentinsights/studentinsights.git","clone_url":"https://github.com/studentinsights/studentinsights.git","svn_url":"https://github.com/studentinsights/studentinsights","homepage":"https://somerville-teacher-tool-demo.herokuapp.com/","size":18459,"stargazers_count":89,"watchers_count":89,"language":"JavaScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":45,"mirror_url":null,"archived":false,"open_issues_count":102,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":45,"open_issues":102,"watchers":89,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/studentinsights/studentinsights/pulls/1785"},"html":{"href":"https://github.com/studentinsights/studentinsights/pull/1785"},"issue":{"href":"https://api.github.com/repos/studentinsights/studentinsights/issues/1785"},"comments":{"href":"https://api.github.com/repos/studentinsights/studentinsights/issues/1785/comments"},"review_comments":{"href":"https://api.github.com/repos/studentinsights/studentinsights/pulls/1785/comments"},"review_comment":{"href":"https://api.github.com/repos/studentinsights/studentinsights/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/studentinsights/studentinsights/pulls/1785/commits"},"statuses":{"href":"https://api.github.com/repos/studentinsights/studentinsights/statuses/86ed327067b0ac67143fa2d6f57dda0f13669c17"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"kevinrobinson"}}