{"action":"created","comment":{"url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/comments/91201121","pull_request_review_id":11711094,"id":91201121,"diff_hunk":"@@ -0,0 +1,515 @@\n+/**\n+ * @license\n+ * Copyright 2016 Google Inc. All Rights Reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *      http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+'use strict';\n+\n+const ReportGenerator = require('../../../lighthouse-core/report/report-generator');\n+// TODO: We only need getFilenamePrefix from asset-saver. Tree shake!\n+const getFilenamePrefix = require('../../../lighthouse-core/lib/asset-saver.js').getFilenamePrefix;\n+\n+const firebase = require('firebase/app');\n+require('firebase/auth');\n+const idb = require('idb-keyval');\n+\n+// Polyfills\n+// TODO: dynamically load this based on feature detection.\n+require('whatwg-fetch');\n+const URLSearchParams = require('url-search-params');\n+\n+const LH_CURRENT_VERSION = require('../../../package.json').version;\n+const APP_URL = `${location.origin}${location.pathname}`;\n+\n+/**\n+ * Logs messages via a UI butter.\n+ * @class\n+ */\n+class Logger {\n+  constructor(selector) {\n+    this.el = document.querySelector(selector);\n+  }\n+\n+  /**\n+   * Shows a butter bar.\n+   * @param {!string} msg The message to show.\n+   * @param {boolean=} autoHide True to hide the message after a duration.\n+   *     Default is true.\n+   */\n+  log(msg, autoHide = true) {\n+    clearTimeout(this._id);\n+\n+    this.el.textContent = msg;\n+    this.el.classList.add('show');\n+    if (autoHide) {\n+      this._id = setTimeout(_ => {\n+        this.el.classList.remove('show');\n+      }, 7000);\n+    }\n+  }\n+\n+  warn(msg) {\n+    console.warn(msg);\n+  }\n+\n+  error(msg) {\n+    console.error(msg);\n+  }\n+\n+  /**\n+   * Explicitly hides the butter bar.\n+   */\n+  hide() {\n+    clearTimeout(this._id);\n+    this.el.classList.remove('show');\n+  }\n+}\n+\n+const logger = new Logger('#log');\n+\n+/**\n+ * Wrapper for Firebase Authentication\n+ * @class\n+ */\n+class FirebaseAuth {\n+  constructor() {\n+    this.accessToken = null;\n+    this.user = null;\n+\n+    this.provider = new firebase.auth.GithubAuthProvider();\n+    this.provider.addScope('gist');\n+\n+    firebase.initializeApp({\n+      apiKey: 'AIzaSyApMz8FHTyJNqqUtA51tik5Mro8j-2qMcM',\n+      authDomain: 'lighthouse-viewer.firebaseapp.com',\n+      databaseURL: 'https://lighthouse-viewer.firebaseio.com',\n+      storageBucket: 'lighthouse-viewer.appspot.com',\n+      messagingSenderId: '962507201498'\n+    });\n+\n+    // Wrap auth state callback in a promise so  other parts of the app that\n+    // require login can hook into the changes.\n+    this.ready = new Promise((resolve, reject) => {\n+      firebase.auth().onAuthStateChanged(user => {\n+        idb.get('accessToken').then(token => {\n+          if (user && token) {\n+            this.accessToken = token;\n+            this.user = user;\n+          }\n+          resolve(user);\n+        });\n+      });\n+    });\n+  }\n+\n+  /**\n+   * Signs in the user to Github using the Firebase API.\n+   * @return {!Promise<object>} The logged in user.\n+   */\n+  signIn() {\n+    return firebase.auth().signInWithPopup(this.provider).then(result => {\n+      this.accessToken = result.credential.accessToken;\n+      this.user = result.user;\n+      // A limitation of firebase auth is that it doesn't return an oauth token\n+      // after a page refresh. We'll get a firebase token, but not an oauth token\n+      // for GH. Since GH's tokens never expire, stash the access token in IDB.\n+      return idb.set('accessToken', this.accessToken).then(_ => {\n+        return this.accessToken;\n+      });\n+    });\n+  }\n+\n+  /**\n+   * Signs the user out.\n+   * @return {!Promise}\n+   */\n+  signOut() {\n+    return firebase.auth().signOut().then(_ => {\n+      this.accessToken = null;\n+      return idb.delete('accessToken');\n+    });\n+  }\n+}\n+\n+/**\n+ * Wrapper around the Github API for reading/writing gists.\n+ * @class\n+ */\n+class GithubAPI {\n+  constructor() {\n+    // this.CLIENT_ID = '48e4c3145c4978268ecb';\n+    this.auth = new FirebaseAuth();\n+  }\n+\n+  static get LH_JSON_EXT() {\n+    return '.lighthouse.report.json';\n+  }\n+\n+  authorize() {\n+    return this.auth.accessToken ? Promise.resolve(this.auth.accessToken) :\n+                                   this.auth.signIn();\n+  }\n+\n+  /**\n+   * Creates a gist under the users account.\n+   * @param {!object} jsonFile The gist file body.","path":"lighthouse-viewer/app/src/main.js","position":166,"original_position":166,"commit_id":"d18809ec10985b2546ba0c908ce361520370fa46","original_commit_id":"d18809ec10985b2546ba0c908ce361520370fa46","user":{"login":"ebidel","id":238208,"avatar_url":"https://avatars.githubusercontent.com/u/238208?v=3","gravatar_id":"","url":"https://api.github.com/users/ebidel","html_url":"https://github.com/ebidel","followers_url":"https://api.github.com/users/ebidel/followers","following_url":"https://api.github.com/users/ebidel/following{/other_user}","gists_url":"https://api.github.com/users/ebidel/gists{/gist_id}","starred_url":"https://api.github.com/users/ebidel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ebidel/subscriptions","organizations_url":"https://api.github.com/users/ebidel/orgs","repos_url":"https://api.github.com/users/ebidel/repos","events_url":"https://api.github.com/users/ebidel/events{/privacy}","received_events_url":"https://api.github.com/users/ebidel/received_events","type":"User","site_admin":false},"body":"fancy 👖 . done","created_at":"2016-12-07T00:02:24Z","updated_at":"2016-12-07T00:02:24Z","html_url":"https://github.com/GoogleChrome/lighthouse/pull/1109#discussion_r91201121","pull_request_url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/1109","_links":{"self":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/comments/91201121"},"html":{"href":"https://github.com/GoogleChrome/lighthouse/pull/1109#discussion_r91201121"},"pull_request":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/1109"}}},"pull_request":{"url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/1109","id":96570885,"html_url":"https://github.com/GoogleChrome/lighthouse/pull/1109","diff_url":"https://github.com/GoogleChrome/lighthouse/pull/1109.diff","patch_url":"https://github.com/GoogleChrome/lighthouse/pull/1109.patch","issue_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/1109","number":1109,"state":"open","locked":false,"title":"Lighthouse Viewer","user":{"login":"ebidel","id":238208,"avatar_url":"https://avatars.githubusercontent.com/u/238208?v=3","gravatar_id":"","url":"https://api.github.com/users/ebidel","html_url":"https://github.com/ebidel","followers_url":"https://api.github.com/users/ebidel/followers","following_url":"https://api.github.com/users/ebidel/following{/other_user}","gists_url":"https://api.github.com/users/ebidel/gists{/gist_id}","starred_url":"https://api.github.com/users/ebidel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ebidel/subscriptions","organizations_url":"https://api.github.com/users/ebidel/orgs","repos_url":"https://api.github.com/users/ebidel/repos","events_url":"https://api.github.com/users/ebidel/events{/privacy}","received_events_url":"https://api.github.com/users/ebidel/received_events","type":"User","site_admin":false},"body":"R: all\r\n\r\nThis adds a online viewer for LH json reports, served from `gh-pages`. It browserifies our current report generating code and adds Firebase for authorization to the Github API. Shared reports are saved as gists to Github and fetched later\r\n\r\nTry it: https://ebidel.github.io/viewer-test/\r\n\r\n<img width=\"1126\" alt=\"screen shot 2016-12-05 at 9 12 38 am\" src=\"https://cloud.githubusercontent.com/assets/238208/20894691/4e74d148-bacb-11e6-8fba-99b7469e93a7.png\">\r\n\r\n**Deploys**\r\n\r\ncan be done during a release using `npm run deploy-viewer` in the repo root. That will build `lighthouse-viewer/dist` and push to `gh-pages`. The `dist` folder of LH viewer will be the only thing in the `gh-pages` branch.\r\n\r\nFuture work is tracked in https://github.com/GoogleChrome/lighthouse/issues/1108","created_at":"2016-12-05T17:15:18Z","updated_at":"2016-12-07T00:02:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"357c2bdf56da2b156779ef2d7beefdbde2602108","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/1109/commits","review_comments_url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/1109/comments","review_comment_url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/1109/comments","statuses_url":"https://api.github.com/repos/GoogleChrome/lighthouse/statuses/d18809ec10985b2546ba0c908ce361520370fa46","head":{"label":"GoogleChrome:viewer","ref":"viewer","sha":"d18809ec10985b2546ba0c908ce361520370fa46","user":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"repo":{"id":53370988,"name":"lighthouse","full_name":"GoogleChrome/lighthouse","owner":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleChrome/lighthouse","description":"Auditing, performance metrics, and best practices for Progressive Web Apps","fork":false,"url":"https://api.github.com/repos/GoogleChrome/lighthouse","forks_url":"https://api.github.com/repos/GoogleChrome/lighthouse/forks","keys_url":"https://api.github.com/repos/GoogleChrome/lighthouse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleChrome/lighthouse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleChrome/lighthouse/teams","hooks_url":"https://api.github.com/repos/GoogleChrome/lighthouse/hooks","issue_events_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleChrome/lighthouse/events","assignees_url":"https://api.github.com/repos/GoogleChrome/lighthouse/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleChrome/lighthouse/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleChrome/lighthouse/tags","blobs_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleChrome/lighthouse/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleChrome/lighthouse/languages","stargazers_url":"https://api.github.com/repos/GoogleChrome/lighthouse/stargazers","contributors_url":"https://api.github.com/repos/GoogleChrome/lighthouse/contributors","subscribers_url":"https://api.github.com/repos/GoogleChrome/lighthouse/subscribers","subscription_url":"https://api.github.com/repos/GoogleChrome/lighthouse/subscription","commits_url":"https://api.github.com/repos/GoogleChrome/lighthouse/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleChrome/lighthouse/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleChrome/lighthouse/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleChrome/lighthouse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleChrome/lighthouse/merges","archive_url":"https://api.github.com/repos/GoogleChrome/lighthouse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleChrome/lighthouse/downloads","issues_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleChrome/lighthouse/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleChrome/lighthouse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleChrome/lighthouse/labels{/name}","releases_url":"https://api.github.com/repos/GoogleChrome/lighthouse/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleChrome/lighthouse/deployments","created_at":"2016-03-08T01:03:11Z","updated_at":"2016-12-06T23:00:44Z","pushed_at":"2016-12-06T23:14:57Z","git_url":"git://github.com/GoogleChrome/lighthouse.git","ssh_url":"git@github.com:GoogleChrome/lighthouse.git","clone_url":"https://github.com/GoogleChrome/lighthouse.git","svn_url":"https://github.com/GoogleChrome/lighthouse","homepage":"","size":10990,"stargazers_count":4858,"watchers_count":4858,"language":"JavaScript","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":178,"mirror_url":null,"open_issues_count":147,"forks":178,"open_issues":147,"watchers":4858,"default_branch":"master"}},"base":{"label":"GoogleChrome:master","ref":"master","sha":"aa6d38b3ea8b87677e3d1b4b7dfc93c78ed19f44","user":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"repo":{"id":53370988,"name":"lighthouse","full_name":"GoogleChrome/lighthouse","owner":{"login":"GoogleChrome","id":1778935,"avatar_url":"https://avatars.githubusercontent.com/u/1778935?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleChrome","html_url":"https://github.com/GoogleChrome","followers_url":"https://api.github.com/users/GoogleChrome/followers","following_url":"https://api.github.com/users/GoogleChrome/following{/other_user}","gists_url":"https://api.github.com/users/GoogleChrome/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleChrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleChrome/subscriptions","organizations_url":"https://api.github.com/users/GoogleChrome/orgs","repos_url":"https://api.github.com/users/GoogleChrome/repos","events_url":"https://api.github.com/users/GoogleChrome/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleChrome/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleChrome/lighthouse","description":"Auditing, performance metrics, and best practices for Progressive Web Apps","fork":false,"url":"https://api.github.com/repos/GoogleChrome/lighthouse","forks_url":"https://api.github.com/repos/GoogleChrome/lighthouse/forks","keys_url":"https://api.github.com/repos/GoogleChrome/lighthouse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleChrome/lighthouse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleChrome/lighthouse/teams","hooks_url":"https://api.github.com/repos/GoogleChrome/lighthouse/hooks","issue_events_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleChrome/lighthouse/events","assignees_url":"https://api.github.com/repos/GoogleChrome/lighthouse/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleChrome/lighthouse/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleChrome/lighthouse/tags","blobs_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleChrome/lighthouse/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleChrome/lighthouse/languages","stargazers_url":"https://api.github.com/repos/GoogleChrome/lighthouse/stargazers","contributors_url":"https://api.github.com/repos/GoogleChrome/lighthouse/contributors","subscribers_url":"https://api.github.com/repos/GoogleChrome/lighthouse/subscribers","subscription_url":"https://api.github.com/repos/GoogleChrome/lighthouse/subscription","commits_url":"https://api.github.com/repos/GoogleChrome/lighthouse/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleChrome/lighthouse/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleChrome/lighthouse/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleChrome/lighthouse/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleChrome/lighthouse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleChrome/lighthouse/merges","archive_url":"https://api.github.com/repos/GoogleChrome/lighthouse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleChrome/lighthouse/downloads","issues_url":"https://api.github.com/repos/GoogleChrome/lighthouse/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleChrome/lighthouse/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleChrome/lighthouse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleChrome/lighthouse/labels{/name}","releases_url":"https://api.github.com/repos/GoogleChrome/lighthouse/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleChrome/lighthouse/deployments","created_at":"2016-03-08T01:03:11Z","updated_at":"2016-12-06T23:00:44Z","pushed_at":"2016-12-06T23:14:57Z","git_url":"git://github.com/GoogleChrome/lighthouse.git","ssh_url":"git@github.com:GoogleChrome/lighthouse.git","clone_url":"https://github.com/GoogleChrome/lighthouse.git","svn_url":"https://github.com/GoogleChrome/lighthouse","homepage":"","size":10990,"stargazers_count":4858,"watchers_count":4858,"language":"JavaScript","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":178,"mirror_url":null,"open_issues_count":147,"forks":178,"open_issues":147,"watchers":4858,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/1109"},"html":{"href":"https://github.com/GoogleChrome/lighthouse/pull/1109"},"issue":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/1109"},"comments":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/issues/1109/comments"},"review_comments":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/1109/comments"},"review_comment":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/pulls/1109/commits"},"statuses":{"href":"https://api.github.com/repos/GoogleChrome/lighthouse/statuses/d18809ec10985b2546ba0c908ce361520370fa46"}}}}
{"actor":{"display_login":"ebidel"}}