{"action":"created","comment":{"url":"https://api.github.com/repos/SUSE/machinery/pulls/comments/23375845","id":23375845,"diff_hunk":"@@ -15,93 +15,118 @@\n # To contact SUSE about this file by physical or electronic mail,\n # you may find current contact information at www.suse.com\n \n-require \"nokogiri\"\n-\n class RepositoriesInspector < Inspector\n   def inspect(system, description, options = {})\n     system.check_requirement(\"zypper\", \"--version\")\n \n-    xml = system.run_command(\n-      \"zypper\", \"--non-interactive\", \"--xmlout\", \"repos\", \"--details\", :stdout => :capture\n-    )\n-    details = system.run_command(\n-      \"zypper\", \"--non-interactive\", \"repos\", \"--details\", :stdout => :capture\n-    ).split(\"\\n\").select { |l| l =~ /\\A# +\\| |\\A *\\d+ \\| / }.\n-      map { |l| l.split(\"|\").map(&:strip) }\n-\n-    if !details.empty?\n-      # parse and remove header\n-      idx_prio = details.first.index(\"Priority\")\n-      idx_alias = details.first.index(\"Alias\")\n-      details.shift\n-\n-      prio = {}\n-      details.each_with_index do |entry,idx|\n-        prio[entry[idx_alias]] = entry[idx_prio].to_i\n-      end\n-\n-      credentials = {}\n-      credential_dir = \"/etc/zypp/credentials.d/\"\n-      credential_files = system.run_command(\n-        \"bash\", \"-c\",\n-        \"test -d '#{credential_dir}' && ls -1 '#{credential_dir}' || echo ''\",\n-        :stdout => :capture\n+    begin\n+      xml = system.run_command(\n+        \"zypper\", \"--non-interactive\", \"--xmlout\", \"repos\", \"--details\", :stdout => :capture\n       )\n-      credential_files.split(\"\\n\").each do |f|\n-        content = system.run_command(\n-          \"cat\", \"/etc/zypp/credentials.d/#{f}\", :stdout => :capture\n-        )\n-        content.match(/username=(\\w*)\\npassword=(\\w*)/)\n-        credentials[f] = {\n-          username: $1,\n-          password: $2\n-        }\n+      details = system.run_command(\n+        \"zypper\", \"--non-interactive\", \"repos\", \"--details\", :stdout => :capture\n+      ).split(\"\\n\").select { |l| l =~ /\\A# +\\| |\\A *\\d+ \\| / }.\n+        map { |l| l.split(\"|\").map(&:strip) }\n+    rescue Cheetah::ExecutionFailed => e\n+      if e.status.exitstatus == 6\n+        description.repositories = RepositoriesScope.new([])\n+        return \"Found 0 repositories.\"\n+      else\n+        raise e\n       end\n+    end\n \n-      reps = Nokogiri::XML(xml).xpath(\"/stream/repo-list/repo\")\n-      summary = \"Found #{reps.count} repositories.\"\n-      result = reps.map do |rep|\n-        pri_value = rep[\"priority\"] ? rep[\"priority\"].to_i : prio[rep[\"alias\"]]\n-\n-        # NCC\n-        rep.at_xpath(\"./url\").text.match(/\\?credentials=(\\w*)/)\n-        cred_value = $1\n-        if cred_value && credentials[cred_value]\n-          username = credentials[cred_value][:username]\n-          password = credentials[cred_value][:password]\n-        end\n-\n-        # SCC\n-        rep.at_xpath(\"./url\").text.match(/(https:\\/\\/updates.suse.com\\/SUSE\\/)/)\n-        scc_url = $1\n-        cred_value = \"SCCcredentials\"\n-        if scc_url && credentials[cred_value]\n-          username = credentials[cred_value][:username]\n-          password = credentials[cred_value][:password]\n-        end\n-\n-        repository = Repository.new(\n-          alias:       rep[\"alias\"],\n-          name:        rep[\"name\"],\n-          type:        rep[\"type\"],\n-          url:         rep.at_xpath(\"./url\").text,\n-          enabled:     rep[\"enabled\"] == \"1\",\n-          autorefresh: rep[\"autorefresh\"] == \"1\",\n-          gpgcheck:    rep[\"gpgcheck\"] == \"1\",\n-          priority:    pri_value\n-        )\n-        if username && password\n-          repository[:username] = username\n-          repository[:password] = password\n-        end\n-        repository\n-      end.sort_by(&:name)\n-    else\n+    if details.empty?\n       result = []\n       summary = \"Found 0 repositories.\"\n+    else\n+      priorities = parse_priorities_from_details(details)\n+      credentials = get_credentials_from_system(system)\n+      result = parse_repositories_from_xml(xml, priorities, credentials)\n+      summary = \"Found #{result.count} repositories.\"\n     end\n \n     description.repositories = RepositoriesScope.new(result)\n     summary\n   end\n+\n+  def parse_priorities_from_details(details)\n+    # parse and remove header\n+    idx_prio = details.first.index(\"Priority\")\n+    idx_alias = details.first.index(\"Alias\")\n+    details.shift\n+\n+    prio = {}\n+    details.each_with_index do |entry,idx|\n+      prio[entry[idx_alias]] = entry[idx_prio].to_i\n+    end\n+\n+    prio\n+  end\n+\n+  def get_credentials_from_system(system)\n+    credentials = {}\n+    credential_dir = \"/etc/zypp/credentials.d/\"\n+    credential_files = system.run_command(\n+      \"bash\", \"-c\",\n+      \"test -d '#{credential_dir}' && ls -1 '#{credential_dir}' || echo ''\",\n+      :stdout => :capture\n+    )\n+    credential_files.split(\"\\n\").each do |f|\n+      content = system.run_command(\n+        \"cat\", \"/etc/zypp/credentials.d/#{f}\", :stdout => :capture","path":"plugins/inspect/repositories_inspector.rb","position":138,"original_position":138,"commit_id":"f1a80a73e4be94f0075db727504d9d4729f9d8ac","original_commit_id":"f1a80a73e4be94f0075db727504d9d4729f9d8ac","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Use the new Ruby 1.9 hash syntax.","created_at":"2015-01-22T13:52:28Z","updated_at":"2015-01-22T13:52:28Z","html_url":"https://github.com/SUSE/machinery/pull/540#discussion_r23375845","pull_request_url":"https://api.github.com/repos/SUSE/machinery/pulls/540","_links":{"self":{"href":"https://api.github.com/repos/SUSE/machinery/pulls/comments/23375845"},"html":{"href":"https://github.com/SUSE/machinery/pull/540#discussion_r23375845"},"pull_request":{"href":"https://api.github.com/repos/SUSE/machinery/pulls/540"}}},"pull_request":{"url":"https://api.github.com/repos/SUSE/machinery/pulls/540","id":27843390,"html_url":"https://github.com/SUSE/machinery/pull/540","diff_url":"https://github.com/SUSE/machinery/pull/540.diff","patch_url":"https://github.com/SUSE/machinery/pull/540.patch","issue_url":"https://api.github.com/repos/SUSE/machinery/issues/540","number":540,"state":"open","locked":false,"title":"Fix empty repositories","user":{"login":"cornelius","id":23799,"avatar_url":"https://avatars.githubusercontent.com/u/23799?v=3","gravatar_id":"","url":"https://api.github.com/users/cornelius","html_url":"https://github.com/cornelius","followers_url":"https://api.github.com/users/cornelius/followers","following_url":"https://api.github.com/users/cornelius/following{/other_user}","gists_url":"https://api.github.com/users/cornelius/gists{/gist_id}","starred_url":"https://api.github.com/users/cornelius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cornelius/subscriptions","organizations_url":"https://api.github.com/users/cornelius/orgs","repos_url":"https://api.github.com/users/cornelius/repos","events_url":"https://api.github.com/users/cornelius/events{/privacy}","received_events_url":"https://api.github.com/users/cornelius/received_events","type":"User","site_admin":false},"body":"Fixes #536 ","created_at":"2015-01-22T13:52:22Z","updated_at":"2015-01-22T13:52:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cf7298623d1b163b02bcdbb65e8e6cd6dc292fdd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SUSE/machinery/pulls/540/commits","review_comments_url":"https://api.github.com/repos/SUSE/machinery/pulls/540/comments","review_comment_url":"https://api.github.com/repos/SUSE/machinery/pulls/comments/{number}","comments_url":"https://api.github.com/repos/SUSE/machinery/issues/540/comments","statuses_url":"https://api.github.com/repos/SUSE/machinery/statuses/f1a80a73e4be94f0075db727504d9d4729f9d8ac","head":{"label":"SUSE:fix-empty-repositories","ref":"fix-empty-repositories","sha":"f1a80a73e4be94f0075db727504d9d4729f9d8ac","user":{"login":"SUSE","id":1067733,"avatar_url":"https://avatars.githubusercontent.com/u/1067733?v=3","gravatar_id":"","url":"https://api.github.com/users/SUSE","html_url":"https://github.com/SUSE","followers_url":"https://api.github.com/users/SUSE/followers","following_url":"https://api.github.com/users/SUSE/following{/other_user}","gists_url":"https://api.github.com/users/SUSE/gists{/gist_id}","starred_url":"https://api.github.com/users/SUSE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUSE/subscriptions","organizations_url":"https://api.github.com/users/SUSE/orgs","repos_url":"https://api.github.com/users/SUSE/repos","events_url":"https://api.github.com/users/SUSE/events{/privacy}","received_events_url":"https://api.github.com/users/SUSE/received_events","type":"Organization","site_admin":false},"repo":{"id":21424418,"name":"machinery","full_name":"SUSE/machinery","owner":{"login":"SUSE","id":1067733,"avatar_url":"https://avatars.githubusercontent.com/u/1067733?v=3","gravatar_id":"","url":"https://api.github.com/users/SUSE","html_url":"https://github.com/SUSE","followers_url":"https://api.github.com/users/SUSE/followers","following_url":"https://api.github.com/users/SUSE/following{/other_user}","gists_url":"https://api.github.com/users/SUSE/gists{/gist_id}","starred_url":"https://api.github.com/users/SUSE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUSE/subscriptions","organizations_url":"https://api.github.com/users/SUSE/orgs","repos_url":"https://api.github.com/users/SUSE/repos","events_url":"https://api.github.com/users/SUSE/events{/privacy}","received_events_url":"https://api.github.com/users/SUSE/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SUSE/machinery","description":"A systems management toolkit for Linux","fork":false,"url":"https://api.github.com/repos/SUSE/machinery","forks_url":"https://api.github.com/repos/SUSE/machinery/forks","keys_url":"https://api.github.com/repos/SUSE/machinery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SUSE/machinery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SUSE/machinery/teams","hooks_url":"https://api.github.com/repos/SUSE/machinery/hooks","issue_events_url":"https://api.github.com/repos/SUSE/machinery/issues/events{/number}","events_url":"https://api.github.com/repos/SUSE/machinery/events","assignees_url":"https://api.github.com/repos/SUSE/machinery/assignees{/user}","branches_url":"https://api.github.com/repos/SUSE/machinery/branches{/branch}","tags_url":"https://api.github.com/repos/SUSE/machinery/tags","blobs_url":"https://api.github.com/repos/SUSE/machinery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SUSE/machinery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SUSE/machinery/git/refs{/sha}","trees_url":"https://api.github.com/repos/SUSE/machinery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SUSE/machinery/statuses/{sha}","languages_url":"https://api.github.com/repos/SUSE/machinery/languages","stargazers_url":"https://api.github.com/repos/SUSE/machinery/stargazers","contributors_url":"https://api.github.com/repos/SUSE/machinery/contributors","subscribers_url":"https://api.github.com/repos/SUSE/machinery/subscribers","subscription_url":"https://api.github.com/repos/SUSE/machinery/subscription","commits_url":"https://api.github.com/repos/SUSE/machinery/commits{/sha}","git_commits_url":"https://api.github.com/repos/SUSE/machinery/git/commits{/sha}","comments_url":"https://api.github.com/repos/SUSE/machinery/comments{/number}","issue_comment_url":"https://api.github.com/repos/SUSE/machinery/issues/comments/{number}","contents_url":"https://api.github.com/repos/SUSE/machinery/contents/{+path}","compare_url":"https://api.github.com/repos/SUSE/machinery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SUSE/machinery/merges","archive_url":"https://api.github.com/repos/SUSE/machinery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SUSE/machinery/downloads","issues_url":"https://api.github.com/repos/SUSE/machinery/issues{/number}","pulls_url":"https://api.github.com/repos/SUSE/machinery/pulls{/number}","milestones_url":"https://api.github.com/repos/SUSE/machinery/milestones{/number}","notifications_url":"https://api.github.com/repos/SUSE/machinery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SUSE/machinery/labels{/name}","releases_url":"https://api.github.com/repos/SUSE/machinery/releases{/id}","created_at":"2014-07-02T13:07:04Z","updated_at":"2015-01-20T13:28:10Z","pushed_at":"2015-01-22T13:51:42Z","git_url":"git://github.com/SUSE/machinery.git","ssh_url":"git@github.com:SUSE/machinery.git","clone_url":"https://github.com/SUSE/machinery.git","svn_url":"https://github.com/SUSE/machinery","homepage":"machinery-project.org","size":11614,"stargazers_count":38,"watchers_count":38,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":6,"mirror_url":null,"open_issues_count":28,"forks":6,"open_issues":28,"watchers":38,"default_branch":"master"}},"base":{"label":"SUSE:master","ref":"master","sha":"eb41dec50a46ac11a329f11cbd24960f9ca6b0f2","user":{"login":"SUSE","id":1067733,"avatar_url":"https://avatars.githubusercontent.com/u/1067733?v=3","gravatar_id":"","url":"https://api.github.com/users/SUSE","html_url":"https://github.com/SUSE","followers_url":"https://api.github.com/users/SUSE/followers","following_url":"https://api.github.com/users/SUSE/following{/other_user}","gists_url":"https://api.github.com/users/SUSE/gists{/gist_id}","starred_url":"https://api.github.com/users/SUSE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUSE/subscriptions","organizations_url":"https://api.github.com/users/SUSE/orgs","repos_url":"https://api.github.com/users/SUSE/repos","events_url":"https://api.github.com/users/SUSE/events{/privacy}","received_events_url":"https://api.github.com/users/SUSE/received_events","type":"Organization","site_admin":false},"repo":{"id":21424418,"name":"machinery","full_name":"SUSE/machinery","owner":{"login":"SUSE","id":1067733,"avatar_url":"https://avatars.githubusercontent.com/u/1067733?v=3","gravatar_id":"","url":"https://api.github.com/users/SUSE","html_url":"https://github.com/SUSE","followers_url":"https://api.github.com/users/SUSE/followers","following_url":"https://api.github.com/users/SUSE/following{/other_user}","gists_url":"https://api.github.com/users/SUSE/gists{/gist_id}","starred_url":"https://api.github.com/users/SUSE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUSE/subscriptions","organizations_url":"https://api.github.com/users/SUSE/orgs","repos_url":"https://api.github.com/users/SUSE/repos","events_url":"https://api.github.com/users/SUSE/events{/privacy}","received_events_url":"https://api.github.com/users/SUSE/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SUSE/machinery","description":"A systems management toolkit for Linux","fork":false,"url":"https://api.github.com/repos/SUSE/machinery","forks_url":"https://api.github.com/repos/SUSE/machinery/forks","keys_url":"https://api.github.com/repos/SUSE/machinery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SUSE/machinery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SUSE/machinery/teams","hooks_url":"https://api.github.com/repos/SUSE/machinery/hooks","issue_events_url":"https://api.github.com/repos/SUSE/machinery/issues/events{/number}","events_url":"https://api.github.com/repos/SUSE/machinery/events","assignees_url":"https://api.github.com/repos/SUSE/machinery/assignees{/user}","branches_url":"https://api.github.com/repos/SUSE/machinery/branches{/branch}","tags_url":"https://api.github.com/repos/SUSE/machinery/tags","blobs_url":"https://api.github.com/repos/SUSE/machinery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SUSE/machinery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SUSE/machinery/git/refs{/sha}","trees_url":"https://api.github.com/repos/SUSE/machinery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SUSE/machinery/statuses/{sha}","languages_url":"https://api.github.com/repos/SUSE/machinery/languages","stargazers_url":"https://api.github.com/repos/SUSE/machinery/stargazers","contributors_url":"https://api.github.com/repos/SUSE/machinery/contributors","subscribers_url":"https://api.github.com/repos/SUSE/machinery/subscribers","subscription_url":"https://api.github.com/repos/SUSE/machinery/subscription","commits_url":"https://api.github.com/repos/SUSE/machinery/commits{/sha}","git_commits_url":"https://api.github.com/repos/SUSE/machinery/git/commits{/sha}","comments_url":"https://api.github.com/repos/SUSE/machinery/comments{/number}","issue_comment_url":"https://api.github.com/repos/SUSE/machinery/issues/comments/{number}","contents_url":"https://api.github.com/repos/SUSE/machinery/contents/{+path}","compare_url":"https://api.github.com/repos/SUSE/machinery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SUSE/machinery/merges","archive_url":"https://api.github.com/repos/SUSE/machinery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SUSE/machinery/downloads","issues_url":"https://api.github.com/repos/SUSE/machinery/issues{/number}","pulls_url":"https://api.github.com/repos/SUSE/machinery/pulls{/number}","milestones_url":"https://api.github.com/repos/SUSE/machinery/milestones{/number}","notifications_url":"https://api.github.com/repos/SUSE/machinery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SUSE/machinery/labels{/name}","releases_url":"https://api.github.com/repos/SUSE/machinery/releases{/id}","created_at":"2014-07-02T13:07:04Z","updated_at":"2015-01-20T13:28:10Z","pushed_at":"2015-01-22T13:51:42Z","git_url":"git://github.com/SUSE/machinery.git","ssh_url":"git@github.com:SUSE/machinery.git","clone_url":"https://github.com/SUSE/machinery.git","svn_url":"https://github.com/SUSE/machinery","homepage":"machinery-project.org","size":11614,"stargazers_count":38,"watchers_count":38,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":6,"mirror_url":null,"open_issues_count":28,"forks":6,"open_issues":28,"watchers":38,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SUSE/machinery/pulls/540"},"html":{"href":"https://github.com/SUSE/machinery/pull/540"},"issue":{"href":"https://api.github.com/repos/SUSE/machinery/issues/540"},"comments":{"href":"https://api.github.com/repos/SUSE/machinery/issues/540/comments"},"review_comments":{"href":"https://api.github.com/repos/SUSE/machinery/pulls/540/comments"},"review_comment":{"href":"https://api.github.com/repos/SUSE/machinery/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/SUSE/machinery/pulls/540/commits"},"statuses":{"href":"https://api.github.com/repos/SUSE/machinery/statuses/f1a80a73e4be94f0075db727504d9d4729f9d8ac"}}}}