{"action":"created","comment":{"url":"https://api.github.com/repos/feedhenry/fh-fhc/pulls/comments/62037413","id":62037413,"diff_hunk":"@@ -0,0 +1,145 @@\n+module.exports = appdata;\n+\n+appdata.desc = \"Export FeedHenry MBaaS Apps\";\n+appdata.usage = \"fhc appdata [cmd]\"\n+    + \"\\nfhc appdata export --app=<app> --env=<environment>\"\n+    + \"\\nfhc appdata list\"\n+    + \"\\nfhc appdata download --job=<job-id>\"\n+    + \"\\nwhere <job-id> is the auto generated job id\"\n+    + \"\\nwhere <app> is the app id\"\n+    + \"\\nwhere <environment> is the environment id\";\n+\n+var common = require(\"../../common\");\n+var fhreq = require(\"../../utils/request\");\n+var fhc = require(\"../../fhc\");\n+var ini = require('../../utils/ini');\n+var _ = require('underscore');\n+var templates = require('../common/templates.js');\n+var readline = require('readline');\n+\n+var cmdRef = {\n+  'list': listAppData,\n+  'export': exportAppData,\n+  'download': downloadAppData,\n+  'unknown': unknown\n+};\n+\n+function appdata(argv, cb) {\n+  var args = argv._;\n+  if (args.length === 0) {\n+    return unknown(\"\", cb);\n+  }\n+\n+  var action = args[0];\n+  var fn = cmdRef[action];\n+\n+  if (!fn) {\n+    return unknown(\"Invalid service action \" + action, cb);\n+  }\n+\n+  return fn(argv, cb);\n+}\n+\n+function listAppData(args, cb) {\n+  var app = args.app;\n+  var env = args.env;\n+  var path = 'api/v2/appdata/' + env + '/' + app + '/data/export';\n+  common.doGetApiCall(fhreq.getFeedHenryUrl(), path, 'Error exporting data: ', onDone);\n+\n+  function onDone(err, data) {\n+    if (err) {\n+      return cb(err);\n+    }\n+\n+    if (ini.get('table') === true) {\n+      appdata.table = common.createTableForAppData(data);\n+    }\n+\n+    if (ini.get('bare') !== false) {\n+      var props = ['guid'];\n+      if (typeof ini.get('bare') === 'string') {\n+        props = ini.get('bare').split(\" \");\n+      }\n+      appdata.bare = '';\n+      _.each(data, function(proj) {\n+        if (appdata.bare !== '') {\n+          appdata.bare = appdata.bare + '\\n';\n+        }\n+\n+        for (var i=0; i < data.length; i++) {\n+          appdata.bare = appdata.bare + data[props[i]] + \" \";\n+        }\n+      });\n+    }\n+\n+    return cb(null, data);\n+  }\n+}\n+\n+function exportAppData(args, cb) {\n+  var app = args.app;\n+  var env = args.env;\n+  var path = 'api/v2/appdata/' + env + '/' + app + '/data/export';\n+\n+  var rl = readline.createInterface({\n+    input: process.stdin,\n+    output: process.stdout\n+  });\n+\n+  var question = [\n+    'Do you want to stop the application first?',\n+    'The application data might be outdated if you choose not to. (Y/N):'\n+  ].join(''); \n+\n+  rl.question(question, function(answer) {\n+    var apiData = {\n+      stopApp: shouldStopApp(answer)\n+    };\n+\n+    common.doApiCall(fhreq.getFeedHenryUrl(), path, apiData, 'Error exporting data: ', onDone);\n+\n+    rl.close();\n+  });\n+\n+  function onDone (err, result) {\n+    if (err) {\n+      return cb(err);\n+    }\n+\n+    return cb(null, 'Job ID: ' + result);\n+  }\n+}\n+\n+function downloadAppData(args, cb) {\n+  var app = args.app;\n+  var env = args.env;\n+  var job = args.job;\n+  var path = 'api/v2/appdata/' + env + '/' + app + '/export/data/' + job;\n+  common.doApiCall(fhreq.getFeedHenryUrl(), path, {}, 'Error exporting data: ', onDone);\n+\n+  function onDone(err, res) {\n+    if (err) {\n+      return cb(err);\n+    }\n+\n+    return cb(null, 'Download URL: ' + res.url);\n+  }\n+}\n+\n+function unknown(message, cb) {\n+  return cb(message + \"\\n\" + \"Usage: \\n\" + appdata.usage);\n+}\n+\n+function shouldStopApp(text) {\n+  if (!text) {\n+    return true;\n+  }\n+\n+  var _text = text.toLowerCase();\n+\n+  if (_text == 'y' || _text == 'yes') {","path":"lib/cmd/fh3/appdata.js","position":140,"original_position":140,"commit_id":"24f582acbc5dacb8f54360438b9aababe9aaeca9","original_commit_id":"24f582acbc5dacb8f54360438b9aababe9aaeca9","user":{"login":"fh-qube","id":16801364,"avatar_url":"https://avatars.githubusercontent.com/u/16801364?v=3","gravatar_id":"","url":"https://api.github.com/users/fh-qube","html_url":"https://github.com/fh-qube","followers_url":"https://api.github.com/users/fh-qube/followers","following_url":"https://api.github.com/users/fh-qube/following{/other_user}","gists_url":"https://api.github.com/users/fh-qube/gists{/gist_id}","starred_url":"https://api.github.com/users/fh-qube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fh-qube/subscriptions","organizations_url":"https://api.github.com/users/fh-qube/orgs","repos_url":"https://api.github.com/users/fh-qube/repos","events_url":"https://api.github.com/users/fh-qube/events{/privacy}","received_events_url":"https://api.github.com/users/fh-qube/received_events","type":"User","site_admin":false},"body":"![BLOCKER](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/severity-blocker.png) Replace \"==\" with \"===\". [![rule](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/rule.png)](https://metrics.skunkhenry.com/coding_rules#rule_key=javascript%3AEqEqEq)\n![BLOCKER](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/severity-blocker.png) Replace \"==\" with \"===\". [![rule](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/rule.png)](https://metrics.skunkhenry.com/coding_rules#rule_key=javascript%3AEqEqEq)\n","created_at":"2016-05-04T13:25:04Z","updated_at":"2016-05-04T13:25:04Z","html_url":"https://github.com/feedhenry/fh-fhc/pull/211#discussion_r62037413","pull_request_url":"https://api.github.com/repos/feedhenry/fh-fhc/pulls/211","_links":{"self":{"href":"https://api.github.com/repos/feedhenry/fh-fhc/pulls/comments/62037413"},"html":{"href":"https://github.com/feedhenry/fh-fhc/pull/211#discussion_r62037413"},"pull_request":{"href":"https://api.github.com/repos/feedhenry/fh-fhc/pulls/211"}}},"pull_request":{"url":"https://api.github.com/repos/feedhenry/fh-fhc/pulls/211","id":68856746,"html_url":"https://github.com/feedhenry/fh-fhc/pull/211","diff_url":"https://github.com/feedhenry/fh-fhc/pull/211.diff","patch_url":"https://github.com/feedhenry/fh-fhc/pull/211.patch","issue_url":"https://api.github.com/repos/feedhenry/fh-fhc/issues/211","number":211,"state":"open","locked":false,"title":"RHMAP 6004","user":{"login":"odra","id":2183506,"avatar_url":"https://avatars.githubusercontent.com/u/2183506?v=3","gravatar_id":"","url":"https://api.github.com/users/odra","html_url":"https://github.com/odra","followers_url":"https://api.github.com/users/odra/followers","following_url":"https://api.github.com/users/odra/following{/other_user}","gists_url":"https://api.github.com/users/odra/gists{/gist_id}","starred_url":"https://api.github.com/users/odra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odra/subscriptions","organizations_url":"https://api.github.com/users/odra/orgs","repos_url":"https://api.github.com/users/odra/repos","events_url":"https://api.github.com/users/odra/events{/privacy}","received_events_url":"https://api.github.com/users/odra/received_events","type":"User","site_admin":false},"body":"# Motivation\r\n\r\nCreate new  FHC commands to export, list and download app data.\r\n\r\nThis is not 100% ready yet since it needs the fh-supercore APIs (using dummy data  right now).\r\n\r\n## Command list\r\n\r\n**Export data for a given app**\r\n`fhc appdata export --env=<env> --app=<appid>`\r\n\r\n**List export history**\r\n`fhc appdata list`\r\n\r\n**Download a previous export data**\r\n`fhc appdata download --job=<jobid>`","created_at":"2016-05-04T12:53:20Z","updated_at":"2016-05-04T13:25:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d439aec01cbe47e7a459195152c32b5d7abae982","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/feedhenry/fh-fhc/pulls/211/commits","review_comments_url":"https://api.github.com/repos/feedhenry/fh-fhc/pulls/211/comments","review_comment_url":"https://api.github.com/repos/feedhenry/fh-fhc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/feedhenry/fh-fhc/issues/211/comments","statuses_url":"https://api.github.com/repos/feedhenry/fh-fhc/statuses/24f582acbc5dacb8f54360438b9aababe9aaeca9","head":{"label":"odra:RHMAP-6004","ref":"RHMAP-6004","sha":"24f582acbc5dacb8f54360438b9aababe9aaeca9","user":{"login":"odra","id":2183506,"avatar_url":"https://avatars.githubusercontent.com/u/2183506?v=3","gravatar_id":"","url":"https://api.github.com/users/odra","html_url":"https://github.com/odra","followers_url":"https://api.github.com/users/odra/followers","following_url":"https://api.github.com/users/odra/following{/other_user}","gists_url":"https://api.github.com/users/odra/gists{/gist_id}","starred_url":"https://api.github.com/users/odra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odra/subscriptions","organizations_url":"https://api.github.com/users/odra/orgs","repos_url":"https://api.github.com/users/odra/repos","events_url":"https://api.github.com/users/odra/events{/privacy}","received_events_url":"https://api.github.com/users/odra/received_events","type":"User","site_admin":false},"repo":{"id":57895516,"name":"fh-fhc","full_name":"odra/fh-fhc","owner":{"login":"odra","id":2183506,"avatar_url":"https://avatars.githubusercontent.com/u/2183506?v=3","gravatar_id":"","url":"https://api.github.com/users/odra","html_url":"https://github.com/odra","followers_url":"https://api.github.com/users/odra/followers","following_url":"https://api.github.com/users/odra/following{/other_user}","gists_url":"https://api.github.com/users/odra/gists{/gist_id}","starred_url":"https://api.github.com/users/odra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odra/subscriptions","organizations_url":"https://api.github.com/users/odra/orgs","repos_url":"https://api.github.com/users/odra/repos","events_url":"https://api.github.com/users/odra/events{/privacy}","received_events_url":"https://api.github.com/users/odra/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/odra/fh-fhc","description":"FeedHenry CLI, the Command Line Interface to FeedHenry","fork":true,"url":"https://api.github.com/repos/odra/fh-fhc","forks_url":"https://api.github.com/repos/odra/fh-fhc/forks","keys_url":"https://api.github.com/repos/odra/fh-fhc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odra/fh-fhc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odra/fh-fhc/teams","hooks_url":"https://api.github.com/repos/odra/fh-fhc/hooks","issue_events_url":"https://api.github.com/repos/odra/fh-fhc/issues/events{/number}","events_url":"https://api.github.com/repos/odra/fh-fhc/events","assignees_url":"https://api.github.com/repos/odra/fh-fhc/assignees{/user}","branches_url":"https://api.github.com/repos/odra/fh-fhc/branches{/branch}","tags_url":"https://api.github.com/repos/odra/fh-fhc/tags","blobs_url":"https://api.github.com/repos/odra/fh-fhc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odra/fh-fhc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odra/fh-fhc/git/refs{/sha}","trees_url":"https://api.github.com/repos/odra/fh-fhc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odra/fh-fhc/statuses/{sha}","languages_url":"https://api.github.com/repos/odra/fh-fhc/languages","stargazers_url":"https://api.github.com/repos/odra/fh-fhc/stargazers","contributors_url":"https://api.github.com/repos/odra/fh-fhc/contributors","subscribers_url":"https://api.github.com/repos/odra/fh-fhc/subscribers","subscription_url":"https://api.github.com/repos/odra/fh-fhc/subscription","commits_url":"https://api.github.com/repos/odra/fh-fhc/commits{/sha}","git_commits_url":"https://api.github.com/repos/odra/fh-fhc/git/commits{/sha}","comments_url":"https://api.github.com/repos/odra/fh-fhc/comments{/number}","issue_comment_url":"https://api.github.com/repos/odra/fh-fhc/issues/comments{/number}","contents_url":"https://api.github.com/repos/odra/fh-fhc/contents/{+path}","compare_url":"https://api.github.com/repos/odra/fh-fhc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odra/fh-fhc/merges","archive_url":"https://api.github.com/repos/odra/fh-fhc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odra/fh-fhc/downloads","issues_url":"https://api.github.com/repos/odra/fh-fhc/issues{/number}","pulls_url":"https://api.github.com/repos/odra/fh-fhc/pulls{/number}","milestones_url":"https://api.github.com/repos/odra/fh-fhc/milestones{/number}","notifications_url":"https://api.github.com/repos/odra/fh-fhc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odra/fh-fhc/labels{/name}","releases_url":"https://api.github.com/repos/odra/fh-fhc/releases{/id}","deployments_url":"https://api.github.com/repos/odra/fh-fhc/deployments","created_at":"2016-05-02T14:21:06Z","updated_at":"2016-05-02T14:21:07Z","pushed_at":"2016-05-04T13:24:33Z","git_url":"git://github.com/odra/fh-fhc.git","ssh_url":"git@github.com:odra/fh-fhc.git","clone_url":"https://github.com/odra/fh-fhc.git","svn_url":"https://github.com/odra/fh-fhc","homepage":"","size":2255,"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":"feedhenry:RHMAP_6003_appdata_export","ref":"RHMAP_6003_appdata_export","sha":"d82ed0751f225cd0e01d2de697cf495cea0b5dad","user":{"login":"feedhenry","id":772226,"avatar_url":"https://avatars.githubusercontent.com/u/772226?v=3","gravatar_id":"","url":"https://api.github.com/users/feedhenry","html_url":"https://github.com/feedhenry","followers_url":"https://api.github.com/users/feedhenry/followers","following_url":"https://api.github.com/users/feedhenry/following{/other_user}","gists_url":"https://api.github.com/users/feedhenry/gists{/gist_id}","starred_url":"https://api.github.com/users/feedhenry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feedhenry/subscriptions","organizations_url":"https://api.github.com/users/feedhenry/orgs","repos_url":"https://api.github.com/users/feedhenry/repos","events_url":"https://api.github.com/users/feedhenry/events{/privacy}","received_events_url":"https://api.github.com/users/feedhenry/received_events","type":"Organization","site_admin":false},"repo":{"id":2850815,"name":"fh-fhc","full_name":"feedhenry/fh-fhc","owner":{"login":"feedhenry","id":772226,"avatar_url":"https://avatars.githubusercontent.com/u/772226?v=3","gravatar_id":"","url":"https://api.github.com/users/feedhenry","html_url":"https://github.com/feedhenry","followers_url":"https://api.github.com/users/feedhenry/followers","following_url":"https://api.github.com/users/feedhenry/following{/other_user}","gists_url":"https://api.github.com/users/feedhenry/gists{/gist_id}","starred_url":"https://api.github.com/users/feedhenry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feedhenry/subscriptions","organizations_url":"https://api.github.com/users/feedhenry/orgs","repos_url":"https://api.github.com/users/feedhenry/repos","events_url":"https://api.github.com/users/feedhenry/events{/privacy}","received_events_url":"https://api.github.com/users/feedhenry/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/feedhenry/fh-fhc","description":"FeedHenry CLI, the Command Line Interface to FeedHenry","fork":false,"url":"https://api.github.com/repos/feedhenry/fh-fhc","forks_url":"https://api.github.com/repos/feedhenry/fh-fhc/forks","keys_url":"https://api.github.com/repos/feedhenry/fh-fhc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/feedhenry/fh-fhc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/feedhenry/fh-fhc/teams","hooks_url":"https://api.github.com/repos/feedhenry/fh-fhc/hooks","issue_events_url":"https://api.github.com/repos/feedhenry/fh-fhc/issues/events{/number}","events_url":"https://api.github.com/repos/feedhenry/fh-fhc/events","assignees_url":"https://api.github.com/repos/feedhenry/fh-fhc/assignees{/user}","branches_url":"https://api.github.com/repos/feedhenry/fh-fhc/branches{/branch}","tags_url":"https://api.github.com/repos/feedhenry/fh-fhc/tags","blobs_url":"https://api.github.com/repos/feedhenry/fh-fhc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/feedhenry/fh-fhc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/feedhenry/fh-fhc/git/refs{/sha}","trees_url":"https://api.github.com/repos/feedhenry/fh-fhc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/feedhenry/fh-fhc/statuses/{sha}","languages_url":"https://api.github.com/repos/feedhenry/fh-fhc/languages","stargazers_url":"https://api.github.com/repos/feedhenry/fh-fhc/stargazers","contributors_url":"https://api.github.com/repos/feedhenry/fh-fhc/contributors","subscribers_url":"https://api.github.com/repos/feedhenry/fh-fhc/subscribers","subscription_url":"https://api.github.com/repos/feedhenry/fh-fhc/subscription","commits_url":"https://api.github.com/repos/feedhenry/fh-fhc/commits{/sha}","git_commits_url":"https://api.github.com/repos/feedhenry/fh-fhc/git/commits{/sha}","comments_url":"https://api.github.com/repos/feedhenry/fh-fhc/comments{/number}","issue_comment_url":"https://api.github.com/repos/feedhenry/fh-fhc/issues/comments{/number}","contents_url":"https://api.github.com/repos/feedhenry/fh-fhc/contents/{+path}","compare_url":"https://api.github.com/repos/feedhenry/fh-fhc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/feedhenry/fh-fhc/merges","archive_url":"https://api.github.com/repos/feedhenry/fh-fhc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/feedhenry/fh-fhc/downloads","issues_url":"https://api.github.com/repos/feedhenry/fh-fhc/issues{/number}","pulls_url":"https://api.github.com/repos/feedhenry/fh-fhc/pulls{/number}","milestones_url":"https://api.github.com/repos/feedhenry/fh-fhc/milestones{/number}","notifications_url":"https://api.github.com/repos/feedhenry/fh-fhc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/feedhenry/fh-fhc/labels{/name}","releases_url":"https://api.github.com/repos/feedhenry/fh-fhc/releases{/id}","deployments_url":"https://api.github.com/repos/feedhenry/fh-fhc/deployments","created_at":"2011-11-25T16:34:58Z","updated_at":"2016-04-21T07:54:59Z","pushed_at":"2016-05-04T13:24:34Z","git_url":"git://github.com/feedhenry/fh-fhc.git","ssh_url":"git@github.com:feedhenry/fh-fhc.git","clone_url":"https://github.com/feedhenry/fh-fhc.git","svn_url":"https://github.com/feedhenry/fh-fhc","homepage":"","size":2413,"stargazers_count":25,"watchers_count":25,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":44,"mirror_url":null,"open_issues_count":13,"forks":44,"open_issues":13,"watchers":25,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/feedhenry/fh-fhc/pulls/211"},"html":{"href":"https://github.com/feedhenry/fh-fhc/pull/211"},"issue":{"href":"https://api.github.com/repos/feedhenry/fh-fhc/issues/211"},"comments":{"href":"https://api.github.com/repos/feedhenry/fh-fhc/issues/211/comments"},"review_comments":{"href":"https://api.github.com/repos/feedhenry/fh-fhc/pulls/211/comments"},"review_comment":{"href":"https://api.github.com/repos/feedhenry/fh-fhc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/feedhenry/fh-fhc/pulls/211/commits"},"statuses":{"href":"https://api.github.com/repos/feedhenry/fh-fhc/statuses/24f582acbc5dacb8f54360438b9aababe9aaeca9"}}}}