{"action":"created","comment":{"url":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls/comments/45043630","id":45043630,"diff_hunk":"@@ -140,60 +139,211 @@ var uploadFailedImage = function(obj) {\n     gitRepoName: gitRepoName\n   };\n \n-  var uploadResponse = '';\n-\n   Promise.props(gitData)\n     .then(function(gitData) {\n-      var req = request.post(options);\n-      req\n-        .on('error', function (err) {\n-          throw new Error(err);\n-        })\n-        .on('data', function(chunk) {\n-          uploadResponse += chunk;\n+\n+      // Get the repository ID.\n+      var repoOptions = {\n+        url: options.backendUrl + '/api/repositories?filter[label]=' + gitData.gitRepoName + '&fields=id',\n+        headers: {\n+          'access-token': options.accessToken\n+        }\n+      };\n+\n+      request.get(repoOptions)\n+        .then(function(data) {\n+          if (!JSON.parse(data).count) {\n+            // Repository doesn't exist.\n+            return false;\n+          }\n+          // Get the UI Build ID.\n+          return getBuildId(JSON.parse(data).data[0]['id'], options);\n         })\n-        .on('end', function() {\n-          var data = JSON.parse(uploadResponse).data[0];\n-          // Populate the build ID.\n-          buildId = buildId || data.build;\n-\n-          if (getConfig('debug')) {\n-            // Show response.\n-            console.log(data);\n+        .then(function(data) {\n+          if (!JSON.parse(data).count) {\n+            // UI Build doesn't exist.\n+            return false;\n           }\n+          // Check Same screenshots don't exist yet.\n+          var files = [obj.baselinePath, obj.regressionPath, obj.diffPath];\n+          buildId = JSON.parse(data).data[0]['id'];\n+          return getScreenshotByHash(files, buildId, options);\n         })\n-        .on('response', function(response) {\n-          if (response.statusCode >= 500) {\n-            throw new Error('Backend error');\n+        .then(function(data) {\n+          if (JSON.parse(data).count) {\n+            console.log('Screenshots already exist.');\n+            showRegressionLink(buildId);\n           }\n-          else if (response.statusCode !== 200) {\n-            throw new Error('Access token is incorrect or no longer valid, visit your account page');\n+          else {\n+            // This is new regression. Files should be uploaded.\n+            uploadFiles(gitData, obj, options);\n+            console.log('Upload done.');","path":"index.js","position":85,"original_position":85,"commit_id":"57feac9d9d8d216d5a89ad1c9a95971068f0c573","original_commit_id":"57feac9d9d8d216d5a89ad1c9a95971068f0c573","user":{"login":"amitaibu","id":125707,"avatar_url":"https://avatars.githubusercontent.com/u/125707?v=3","gravatar_id":"","url":"https://api.github.com/users/amitaibu","html_url":"https://github.com/amitaibu","followers_url":"https://api.github.com/users/amitaibu/followers","following_url":"https://api.github.com/users/amitaibu/following{/other_user}","gists_url":"https://api.github.com/users/amitaibu/gists{/gist_id}","starred_url":"https://api.github.com/users/amitaibu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitaibu/subscriptions","organizations_url":"https://api.github.com/users/amitaibu/orgs","repos_url":"https://api.github.com/users/amitaibu/repos","events_url":"https://api.github.com/users/amitaibu/events{/privacy}","received_events_url":"https://api.github.com/users/amitaibu/received_events","type":"User","site_admin":false},"body":"this message is wrong, since uploadFiles() wasn't `then`ed yet.","created_at":"2015-11-17T10:33:04Z","updated_at":"2015-11-17T10:33:04Z","html_url":"https://github.com/shoov/shoov-webdrivercss/pull/20#discussion_r45043630","pull_request_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls/20","_links":{"self":{"href":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls/comments/45043630"},"html":{"href":"https://github.com/shoov/shoov-webdrivercss/pull/20#discussion_r45043630"},"pull_request":{"href":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls/20"}}},"pull_request":{"url":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls/20","id":50905732,"html_url":"https://github.com/shoov/shoov-webdrivercss/pull/20","diff_url":"https://github.com/shoov/shoov-webdrivercss/pull/20.diff","patch_url":"https://github.com/shoov/shoov-webdrivercss/pull/20.patch","issue_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/issues/20","number":20,"state":"open","locked":false,"title":"Do not upload images if the same screenshot node already exists.","user":{"login":"HelenaEksler","id":8306902,"avatar_url":"https://avatars.githubusercontent.com/u/8306902?v=3","gravatar_id":"","url":"https://api.github.com/users/HelenaEksler","html_url":"https://github.com/HelenaEksler","followers_url":"https://api.github.com/users/HelenaEksler/followers","following_url":"https://api.github.com/users/HelenaEksler/following{/other_user}","gists_url":"https://api.github.com/users/HelenaEksler/gists{/gist_id}","starred_url":"https://api.github.com/users/HelenaEksler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HelenaEksler/subscriptions","organizations_url":"https://api.github.com/users/HelenaEksler/orgs","repos_url":"https://api.github.com/users/HelenaEksler/repos","events_url":"https://api.github.com/users/HelenaEksler/events{/privacy}","received_events_url":"https://api.github.com/users/HelenaEksler/received_events","type":"User","site_admin":false},"body":"https://github.com/shoov/shoov/issues/267","created_at":"2015-11-17T05:22:47Z","updated_at":"2015-11-17T10:33:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3a444c15629d9ea7d2fd05235d1ec6361ffa5726","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls/20/commits","review_comments_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls/20/comments","review_comment_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls/comments{/number}","comments_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/issues/20/comments","statuses_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/statuses/57feac9d9d8d216d5a89ad1c9a95971068f0c573","head":{"label":"shoov:check-screenshot-exists","ref":"check-screenshot-exists","sha":"57feac9d9d8d216d5a89ad1c9a95971068f0c573","user":{"login":"shoov","id":11602528,"avatar_url":"https://avatars.githubusercontent.com/u/11602528?v=3","gravatar_id":"","url":"https://api.github.com/users/shoov","html_url":"https://github.com/shoov","followers_url":"https://api.github.com/users/shoov/followers","following_url":"https://api.github.com/users/shoov/following{/other_user}","gists_url":"https://api.github.com/users/shoov/gists{/gist_id}","starred_url":"https://api.github.com/users/shoov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shoov/subscriptions","organizations_url":"https://api.github.com/users/shoov/orgs","repos_url":"https://api.github.com/users/shoov/repos","events_url":"https://api.github.com/users/shoov/events{/privacy}","received_events_url":"https://api.github.com/users/shoov/received_events","type":"Organization","site_admin":false},"repo":{"id":33170466,"name":"shoov-webdrivercss","full_name":"shoov/shoov-webdrivercss","owner":{"login":"shoov","id":11602528,"avatar_url":"https://avatars.githubusercontent.com/u/11602528?v=3","gravatar_id":"","url":"https://api.github.com/users/shoov","html_url":"https://github.com/shoov","followers_url":"https://api.github.com/users/shoov/followers","following_url":"https://api.github.com/users/shoov/following{/other_user}","gists_url":"https://api.github.com/users/shoov/gists{/gist_id}","starred_url":"https://api.github.com/users/shoov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shoov/subscriptions","organizations_url":"https://api.github.com/users/shoov/orgs","repos_url":"https://api.github.com/users/shoov/repos","events_url":"https://api.github.com/users/shoov/events{/privacy}","received_events_url":"https://api.github.com/users/shoov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/shoov/shoov-webdrivercss","description":"npm module to allow easy integration between Shoov.io and  WebDriverCss","fork":false,"url":"https://api.github.com/repos/shoov/shoov-webdrivercss","forks_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/forks","keys_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/teams","hooks_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/hooks","issue_events_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/issues/events{/number}","events_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/events","assignees_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/assignees{/user}","branches_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/branches{/branch}","tags_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/tags","blobs_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/git/refs{/sha}","trees_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/statuses/{sha}","languages_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/languages","stargazers_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/stargazers","contributors_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/contributors","subscribers_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/subscribers","subscription_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/subscription","commits_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/commits{/sha}","git_commits_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/git/commits{/sha}","comments_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/comments{/number}","issue_comment_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/issues/comments{/number}","contents_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/contents/{+path}","compare_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/merges","archive_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/downloads","issues_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/issues{/number}","pulls_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls{/number}","milestones_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/milestones{/number}","notifications_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/labels{/name}","releases_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/releases{/id}","created_at":"2015-03-31T07:10:10Z","updated_at":"2015-05-29T22:42:56Z","pushed_at":"2015-11-17T05:22:48Z","git_url":"git://github.com/shoov/shoov-webdrivercss.git","ssh_url":"git@github.com:shoov/shoov-webdrivercss.git","clone_url":"https://github.com/shoov/shoov-webdrivercss.git","svn_url":"https://github.com/shoov/shoov-webdrivercss","homepage":null,"size":29,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"master"}},"base":{"label":"shoov:master","ref":"master","sha":"238b62f77fc6a2c2c29955e0c86ce2cf9da40c53","user":{"login":"shoov","id":11602528,"avatar_url":"https://avatars.githubusercontent.com/u/11602528?v=3","gravatar_id":"","url":"https://api.github.com/users/shoov","html_url":"https://github.com/shoov","followers_url":"https://api.github.com/users/shoov/followers","following_url":"https://api.github.com/users/shoov/following{/other_user}","gists_url":"https://api.github.com/users/shoov/gists{/gist_id}","starred_url":"https://api.github.com/users/shoov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shoov/subscriptions","organizations_url":"https://api.github.com/users/shoov/orgs","repos_url":"https://api.github.com/users/shoov/repos","events_url":"https://api.github.com/users/shoov/events{/privacy}","received_events_url":"https://api.github.com/users/shoov/received_events","type":"Organization","site_admin":false},"repo":{"id":33170466,"name":"shoov-webdrivercss","full_name":"shoov/shoov-webdrivercss","owner":{"login":"shoov","id":11602528,"avatar_url":"https://avatars.githubusercontent.com/u/11602528?v=3","gravatar_id":"","url":"https://api.github.com/users/shoov","html_url":"https://github.com/shoov","followers_url":"https://api.github.com/users/shoov/followers","following_url":"https://api.github.com/users/shoov/following{/other_user}","gists_url":"https://api.github.com/users/shoov/gists{/gist_id}","starred_url":"https://api.github.com/users/shoov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shoov/subscriptions","organizations_url":"https://api.github.com/users/shoov/orgs","repos_url":"https://api.github.com/users/shoov/repos","events_url":"https://api.github.com/users/shoov/events{/privacy}","received_events_url":"https://api.github.com/users/shoov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/shoov/shoov-webdrivercss","description":"npm module to allow easy integration between Shoov.io and  WebDriverCss","fork":false,"url":"https://api.github.com/repos/shoov/shoov-webdrivercss","forks_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/forks","keys_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/teams","hooks_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/hooks","issue_events_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/issues/events{/number}","events_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/events","assignees_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/assignees{/user}","branches_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/branches{/branch}","tags_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/tags","blobs_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/git/refs{/sha}","trees_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/statuses/{sha}","languages_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/languages","stargazers_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/stargazers","contributors_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/contributors","subscribers_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/subscribers","subscription_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/subscription","commits_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/commits{/sha}","git_commits_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/git/commits{/sha}","comments_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/comments{/number}","issue_comment_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/issues/comments{/number}","contents_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/contents/{+path}","compare_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/merges","archive_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/downloads","issues_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/issues{/number}","pulls_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls{/number}","milestones_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/milestones{/number}","notifications_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/labels{/name}","releases_url":"https://api.github.com/repos/shoov/shoov-webdrivercss/releases{/id}","created_at":"2015-03-31T07:10:10Z","updated_at":"2015-05-29T22:42:56Z","pushed_at":"2015-11-17T05:22:48Z","git_url":"git://github.com/shoov/shoov-webdrivercss.git","ssh_url":"git@github.com:shoov/shoov-webdrivercss.git","clone_url":"https://github.com/shoov/shoov-webdrivercss.git","svn_url":"https://github.com/shoov/shoov-webdrivercss","homepage":null,"size":29,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls/20"},"html":{"href":"https://github.com/shoov/shoov-webdrivercss/pull/20"},"issue":{"href":"https://api.github.com/repos/shoov/shoov-webdrivercss/issues/20"},"comments":{"href":"https://api.github.com/repos/shoov/shoov-webdrivercss/issues/20/comments"},"review_comments":{"href":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls/20/comments"},"review_comment":{"href":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/shoov/shoov-webdrivercss/pulls/20/commits"},"statuses":{"href":"https://api.github.com/repos/shoov/shoov-webdrivercss/statuses/57feac9d9d8d216d5a89ad1c9a95971068f0c573"}}}}