{"action":"created","comment":{"url":"https://api.github.com/repos/tessel/t2-cli/pulls/comments/59145120","id":59145120,"diff_hunk":"@@ -0,0 +1,136 @@\n+var logs = require('./logs');\n+var os = require('os');\n+var packageJson = require('../package.json');\n+var preferences = require('./preferences');\n+var request = require('request');\n+\n+// the value of the crash reporter preference\n+// the value has to be one of 'on' or 'off'\n+var CRASH_REPORTER_PREFERENCE = 'crash.reporter.preference';\n+var SUBMIT_CRASH_URL = 'http://tessel-error-reporter.appspot.com/crashes/submit';\n+\n+// override for testing\n+if (process.env.DEV_MODE === 'true') {\n+  SUBMIT_CRASH_URL = 'http://localhost:9080/crashes/submit';\n+}\n+\n+// the only instance of the crash reporter\n+var crashReporter = null;\n+\n+var CrashReporter = function() {\n+  this.preferences = new preferences.Preferences();\n+};\n+\n+CrashReporter.getInstance = function() {\n+  if (crashReporter) {\n+    return crashReporter;\n+  } else {\n+    crashReporter = new CrashReporter();\n+    return crashReporter;\n+  }\n+};\n+\n+CrashReporter.prototype.turnOff = function() {\n+  return this.preferences\n+    .write(CRASH_REPORTER_PREFERENCE, 'off')\n+    .catch(function(error) {\n+      // do nothing\n+      // do not crash the crash reporter :)\n+      logs.err('Error turning off crash reporter preferences', error);\n+    });\n+};\n+\n+CrashReporter.prototype.turnOn = function() {\n+  return this.preferences\n+    .write(CRASH_REPORTER_PREFERENCE, 'on')\n+    .catch(function(error) {\n+      // do nothing\n+      // do not crash the crash reporter :)\n+      logs.err('Error turning on crash reporter preferences', error);\n+    });\n+};\n+\n+CrashReporter.prototype.submit = function(report) {\n+  var that = this;\n+  that.preferences.read(CRASH_REPORTER_PREFERENCE, 'on')\n+    .then(function(value) {\n+      if (value === 'on') {\n+        var labels = [\n+          // tessel cli labels\n+          packageJson.name,\n+          `CLI version: ${packageJson.version}`,\n+          // node version\n+          `Node version: ${process.version}`,\n+          // os version\n+          `OS platform: ${os.platform()}`,\n+          `OS release: ${os.release()}`\n+        ];\n+\n+        that.submitReport(labels.join(','), report)\n+          .then(function() {\n+            logs.info('Done !');\n+          })\n+          .catch(function(error) {\n+            logs.err('Error submitting crash report', error);\n+          });\n+      }\n+    })\n+    .catch(function(error) {\n+      // do nothing\n+      // do not crash the crash reporter :)\n+      logs.err('Error submitting crash report', error);\n+    });\n+};\n+\n+CrashReporter.prototype.submitReport = function(labels, report) {\n+  return new Promise(function(resolve, reject) {\n+    request.post({\n+      'url': SUBMIT_CRASH_URL,\n+      'form': {\n+        'crash': report,\n+        'labels': labels,\n+        'f': 'json'","path":"lib/crash_reporter.js","position":92,"original_position":92,"commit_id":"f6aaa095fed4ec75bc548c2b08a8c2f97431b5af","original_commit_id":"f6aaa095fed4ec75bc548c2b08a8c2f97431b5af","user":{"login":"tikurahul","id":624211,"avatar_url":"https://avatars.githubusercontent.com/u/624211?v=3","gravatar_id":"","url":"https://api.github.com/users/tikurahul","html_url":"https://github.com/tikurahul","followers_url":"https://api.github.com/users/tikurahul/followers","following_url":"https://api.github.com/users/tikurahul/following{/other_user}","gists_url":"https://api.github.com/users/tikurahul/gists{/gist_id}","starred_url":"https://api.github.com/users/tikurahul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tikurahul/subscriptions","organizations_url":"https://api.github.com/users/tikurahul/orgs","repos_url":"https://api.github.com/users/tikurahul/repos","events_url":"https://api.github.com/users/tikurahul/events{/privacy}","received_events_url":"https://api.github.com/users/tikurahul/received_events","type":"User","site_admin":false},"body":"Done","created_at":"2016-04-11T00:35:30Z","updated_at":"2016-04-11T00:35:30Z","html_url":"https://github.com/tessel/t2-cli/pull/629#discussion_r59145120","pull_request_url":"https://api.github.com/repos/tessel/t2-cli/pulls/629","_links":{"self":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/comments/59145120"},"html":{"href":"https://github.com/tessel/t2-cli/pull/629#discussion_r59145120"},"pull_request":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/629"}}},"pull_request":{"url":"https://api.github.com/repos/tessel/t2-cli/pulls/629","id":64289281,"html_url":"https://github.com/tessel/t2-cli/pull/629","diff_url":"https://github.com/tessel/t2-cli/pull/629.diff","patch_url":"https://github.com/tessel/t2-cli/pull/629.patch","issue_url":"https://api.github.com/repos/tessel/t2-cli/issues/629","number":629,"state":"open","locked":false,"title":"Add a crash reporter to diagnose CLI crashes.","user":{"login":"tikurahul","id":624211,"avatar_url":"https://avatars.githubusercontent.com/u/624211?v=3","gravatar_id":"","url":"https://api.github.com/users/tikurahul","html_url":"https://github.com/tikurahul","followers_url":"https://api.github.com/users/tikurahul/followers","following_url":"https://api.github.com/users/tikurahul/following{/other_user}","gists_url":"https://api.github.com/users/tikurahul/gists{/gist_id}","starred_url":"https://api.github.com/users/tikurahul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tikurahul/subscriptions","organizations_url":"https://api.github.com/users/tikurahul/orgs","repos_url":"https://api.github.com/users/tikurahul/repos","events_url":"https://api.github.com/users/tikurahul/events{/privacy}","received_events_url":"https://api.github.com/users/tikurahul/received_events","type":"User","site_admin":false},"body":"All crashes get submitted by default. The user can turn off crash reporting if he wants to.","created_at":"2016-03-28T04:55:06Z","updated_at":"2016-04-11T00:35:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3aa9ba97c65ad1b5acc13a347c4dba39e6ec71a7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/tessel/t2-cli/pulls/629/commits","review_comments_url":"https://api.github.com/repos/tessel/t2-cli/pulls/629/comments","review_comment_url":"https://api.github.com/repos/tessel/t2-cli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tessel/t2-cli/issues/629/comments","statuses_url":"https://api.github.com/repos/tessel/t2-cli/statuses/f6aaa095fed4ec75bc548c2b08a8c2f97431b5af","head":{"label":"tikurahul:master","ref":"master","sha":"f6aaa095fed4ec75bc548c2b08a8c2f97431b5af","user":{"login":"tikurahul","id":624211,"avatar_url":"https://avatars.githubusercontent.com/u/624211?v=3","gravatar_id":"","url":"https://api.github.com/users/tikurahul","html_url":"https://github.com/tikurahul","followers_url":"https://api.github.com/users/tikurahul/followers","following_url":"https://api.github.com/users/tikurahul/following{/other_user}","gists_url":"https://api.github.com/users/tikurahul/gists{/gist_id}","starred_url":"https://api.github.com/users/tikurahul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tikurahul/subscriptions","organizations_url":"https://api.github.com/users/tikurahul/orgs","repos_url":"https://api.github.com/users/tikurahul/repos","events_url":"https://api.github.com/users/tikurahul/events{/privacy}","received_events_url":"https://api.github.com/users/tikurahul/received_events","type":"User","site_admin":false},"repo":{"id":54866229,"name":"t2-cli","full_name":"tikurahul/t2-cli","owner":{"login":"tikurahul","id":624211,"avatar_url":"https://avatars.githubusercontent.com/u/624211?v=3","gravatar_id":"","url":"https://api.github.com/users/tikurahul","html_url":"https://github.com/tikurahul","followers_url":"https://api.github.com/users/tikurahul/followers","following_url":"https://api.github.com/users/tikurahul/following{/other_user}","gists_url":"https://api.github.com/users/tikurahul/gists{/gist_id}","starred_url":"https://api.github.com/users/tikurahul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tikurahul/subscriptions","organizations_url":"https://api.github.com/users/tikurahul/orgs","repos_url":"https://api.github.com/users/tikurahul/repos","events_url":"https://api.github.com/users/tikurahul/events{/privacy}","received_events_url":"https://api.github.com/users/tikurahul/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tikurahul/t2-cli","description":"Command line interface to Tessel 2.","fork":true,"url":"https://api.github.com/repos/tikurahul/t2-cli","forks_url":"https://api.github.com/repos/tikurahul/t2-cli/forks","keys_url":"https://api.github.com/repos/tikurahul/t2-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tikurahul/t2-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tikurahul/t2-cli/teams","hooks_url":"https://api.github.com/repos/tikurahul/t2-cli/hooks","issue_events_url":"https://api.github.com/repos/tikurahul/t2-cli/issues/events{/number}","events_url":"https://api.github.com/repos/tikurahul/t2-cli/events","assignees_url":"https://api.github.com/repos/tikurahul/t2-cli/assignees{/user}","branches_url":"https://api.github.com/repos/tikurahul/t2-cli/branches{/branch}","tags_url":"https://api.github.com/repos/tikurahul/t2-cli/tags","blobs_url":"https://api.github.com/repos/tikurahul/t2-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tikurahul/t2-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tikurahul/t2-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/tikurahul/t2-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tikurahul/t2-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/tikurahul/t2-cli/languages","stargazers_url":"https://api.github.com/repos/tikurahul/t2-cli/stargazers","contributors_url":"https://api.github.com/repos/tikurahul/t2-cli/contributors","subscribers_url":"https://api.github.com/repos/tikurahul/t2-cli/subscribers","subscription_url":"https://api.github.com/repos/tikurahul/t2-cli/subscription","commits_url":"https://api.github.com/repos/tikurahul/t2-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/tikurahul/t2-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/tikurahul/t2-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/tikurahul/t2-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/tikurahul/t2-cli/contents/{+path}","compare_url":"https://api.github.com/repos/tikurahul/t2-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tikurahul/t2-cli/merges","archive_url":"https://api.github.com/repos/tikurahul/t2-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tikurahul/t2-cli/downloads","issues_url":"https://api.github.com/repos/tikurahul/t2-cli/issues{/number}","pulls_url":"https://api.github.com/repos/tikurahul/t2-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/tikurahul/t2-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/tikurahul/t2-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tikurahul/t2-cli/labels{/name}","releases_url":"https://api.github.com/repos/tikurahul/t2-cli/releases{/id}","deployments_url":"https://api.github.com/repos/tikurahul/t2-cli/deployments","created_at":"2016-03-28T04:50:30Z","updated_at":"2016-03-28T04:50:32Z","pushed_at":"2016-04-10T19:56:06Z","git_url":"git://github.com/tikurahul/t2-cli.git","ssh_url":"git@github.com:tikurahul/t2-cli.git","clone_url":"https://github.com/tikurahul/t2-cli.git","svn_url":"https://github.com/tikurahul/t2-cli","homepage":"","size":1099,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"tessel:master","ref":"master","sha":"fc24618b98fbd583ad1e0fd63742b059e11d1580","user":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"repo":{"id":30388450,"name":"t2-cli","full_name":"tessel/t2-cli","owner":{"login":"tessel","id":5573563,"avatar_url":"https://avatars.githubusercontent.com/u/5573563?v=3","gravatar_id":"","url":"https://api.github.com/users/tessel","html_url":"https://github.com/tessel","followers_url":"https://api.github.com/users/tessel/followers","following_url":"https://api.github.com/users/tessel/following{/other_user}","gists_url":"https://api.github.com/users/tessel/gists{/gist_id}","starred_url":"https://api.github.com/users/tessel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tessel/subscriptions","organizations_url":"https://api.github.com/users/tessel/orgs","repos_url":"https://api.github.com/users/tessel/repos","events_url":"https://api.github.com/users/tessel/events{/privacy}","received_events_url":"https://api.github.com/users/tessel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tessel/t2-cli","description":"Command line interface to Tessel 2.","fork":false,"url":"https://api.github.com/repos/tessel/t2-cli","forks_url":"https://api.github.com/repos/tessel/t2-cli/forks","keys_url":"https://api.github.com/repos/tessel/t2-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tessel/t2-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tessel/t2-cli/teams","hooks_url":"https://api.github.com/repos/tessel/t2-cli/hooks","issue_events_url":"https://api.github.com/repos/tessel/t2-cli/issues/events{/number}","events_url":"https://api.github.com/repos/tessel/t2-cli/events","assignees_url":"https://api.github.com/repos/tessel/t2-cli/assignees{/user}","branches_url":"https://api.github.com/repos/tessel/t2-cli/branches{/branch}","tags_url":"https://api.github.com/repos/tessel/t2-cli/tags","blobs_url":"https://api.github.com/repos/tessel/t2-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tessel/t2-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tessel/t2-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/tessel/t2-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tessel/t2-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/tessel/t2-cli/languages","stargazers_url":"https://api.github.com/repos/tessel/t2-cli/stargazers","contributors_url":"https://api.github.com/repos/tessel/t2-cli/contributors","subscribers_url":"https://api.github.com/repos/tessel/t2-cli/subscribers","subscription_url":"https://api.github.com/repos/tessel/t2-cli/subscription","commits_url":"https://api.github.com/repos/tessel/t2-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/tessel/t2-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/tessel/t2-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/tessel/t2-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/tessel/t2-cli/contents/{+path}","compare_url":"https://api.github.com/repos/tessel/t2-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tessel/t2-cli/merges","archive_url":"https://api.github.com/repos/tessel/t2-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tessel/t2-cli/downloads","issues_url":"https://api.github.com/repos/tessel/t2-cli/issues{/number}","pulls_url":"https://api.github.com/repos/tessel/t2-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/tessel/t2-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/tessel/t2-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tessel/t2-cli/labels{/name}","releases_url":"https://api.github.com/repos/tessel/t2-cli/releases{/id}","deployments_url":"https://api.github.com/repos/tessel/t2-cli/deployments","created_at":"2015-02-06T01:27:53Z","updated_at":"2016-04-09T19:35:48Z","pushed_at":"2016-04-10T22:41:01Z","git_url":"git://github.com/tessel/t2-cli.git","ssh_url":"git@github.com:tessel/t2-cli.git","clone_url":"https://github.com/tessel/t2-cli.git","svn_url":"https://github.com/tessel/t2-cli","homepage":"","size":1401,"stargazers_count":44,"watchers_count":44,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":69,"forks":21,"open_issues":69,"watchers":44,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/629"},"html":{"href":"https://github.com/tessel/t2-cli/pull/629"},"issue":{"href":"https://api.github.com/repos/tessel/t2-cli/issues/629"},"comments":{"href":"https://api.github.com/repos/tessel/t2-cli/issues/629/comments"},"review_comments":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/629/comments"},"review_comment":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tessel/t2-cli/pulls/629/commits"},"statuses":{"href":"https://api.github.com/repos/tessel/t2-cli/statuses/f6aaa095fed4ec75bc548c2b08a8c2f97431b5af"}}}}