{"action":"created","comment":{"url":"https://api.github.com/repos/CentOS/container-pipeline-service/pulls/comments/75686373","id":75686373,"diff_hunk":"@@ -0,0 +1,182 @@\n+from yaml import load, safe_dump\n+from glob import glob\n+import os\n+from argparse import ArgumentParser\n+from collections import defaultdict\n+\n+\n+class IndexGenerator:\n+    \"\"\"Thus class transforms index.d to index.yml and vice versa, Genearting one or the other, as needed\"\"\"\n+\n+    def __init__(self, indexd_path=\"./index.d\", index_yml=\"./index.yml\", reverse=False):\n+        \"\"\"Initialze a generator, giving path of index.d and index.yml and specifying is reverse transform needs to be\n+        done\"\"\"\n+\n+        self._index_dotd = indexd_path\n+        self._index_yml = index_yml\n+        self._reverse = reverse\n+\n+        # If not reverse, check index.d folder for existence.\n+        if not self._reverse:\n+                if not os.path.exists(self._index_dotd):\n+                    raise ValueError(\"Invalid path specified.\")\n+\n+        # Otherwise, check for index.yml existance\n+        else:\n+            if not os.path.exists(self._index_yml):\n+                raise ValueError(\"Invalid path specified\")\n+\n+        return\n+\n+    def _genindexyml(self, potential_index_files):\n+        \"\"\"Generate index.yml from index.d files\"\"\"\n+\n+        current_index = 1\n+        index_yml = {\n+            \"Projects\": []\n+        }\n+\n+        # Read every yaml file in list of yaml files\n+        for potential_index_file_path in potential_index_files:\n+\n+            # Get the file basename by path split and take the 2nd part which is only the file name\n+            file_name = os.path.split(potential_index_file_path)[1]\n+            namespace = \"\"\n+\n+            # If a filename contains a ., take everything before the . as project namespace\n+            if \".\" in file_name:\n+                namespace = file_name.split(\".\")[0]\n+\n+            # Otherwise the project namespace is the entire filename\n+            else:\n+                namespace = file_name\n+\n+            potential_index_data = None\n+\n+            # Read the yaml data in the file\n+            with open(potential_index_file_path, \"r\") as potential_index_file:\n+                potential_index_data = load(potential_index_file)\n+\n+            # Go through every entry in the yaml data file, extracting what is needed.\n+            for entry in potential_index_data:\n+                tid = current_index\n+                app_id = namespace\n+\n+                # Append the collected and generated information to indexyml data collector\n+                index_yml[\"Projects\"].append({\n+                    \"id\": tid,\n+                    \"app-id\": app_id,\n+                    \"job-id\": entry[\"job-id\"],\n+                    \"git-url\": entry[\"git-url\"],\n+                    \"git-path\": entry[\"git-path\"],\n+                    \"git-branch\": entry[\"git-branch\"],\n+                    \"target-file\": entry[\"target-file\"],\n+                    \"desired-tag\": entry[\"desired-tag\"],\n+                    \"notify-email\": entry[\"notify-email\"],\n+                    \"depends-on\": entry[\"depends-on\"]\n+                })\n+\n+                current_index += 1\n+\n+        # Dump the indexyml data to specfied index.yml\n+        with open(self._index_yml, \"w\") as index_yml_file: \n+            safe_dump(index_yml, index_yml_file, default_flow_style=False, indent=2)\n+\n+        # Add few lines of comment indicating the the file is generated.\n+        commentline = \"\"\"This file is generated by the CentOS Community Container Pipeline Service\\n\n+                      Please do not edit this file manually.\\n\\n\n+                      \"\"\"\n+\n+        with open(self._index_yml, \"r\") as original:\n+            data = original.read()\n+\n+        with open(self._index_yml, \"w\") as modified:\n+            modified.write(data)\n+\n+        return\n+\n+    def _genindexd(self):\n+        \"\"\"Generate index.d files given index.yml\"\"\"\n+\n+        index_yml = None\n+        indexd_data = {}\n+\n+        # Open the indexyml file and read the yaml data\n+        with open(self._index_yml, \"r\") as index_file:\n+            index_yml = load(index_file)\n+\n+        # For every project in the indexyml file, collect the necessary data\n+        for project in defaultdict(index_yml[\"Projects\"]):\n+            app_id = project[\"app-id\"]\n+\n+            # If no desired-tag is specified, assume a default, otherwise take specified desired-tag\n+            if \"desired-tag\" not in project:\n+                desired_tag = \"latest\"\n+\n+            else:\n+                desired_tag = project[\"desired-tag\"]\n+\n+            # If there isnt already indexd data entry for a specific appid, add it.\n+            # The appid will be used later on to set the filenames\n+            if app_id not in indexd_data:\n+                indexd_data[app_id] = []\n+\n+            # Append the collected and generated data to indexd data\n+            indexd_data[app_id].append({\n+                \"job-id\": project[\"job-id\"],\n+                \"git-url\": project[\"git-url\"],\n+                \"git-path\": project[\"git-path\"],\n+                \"git-branch\": project[\"git-branch\"],\n+                \"target-file\": project[\"target-file\"],\n+                \"notify-email\": project[\"notify-email\"],\n+                \"desired-tag\": desired_tag,\n+                \"depends-on\": project[\"depends-on\"]\n+            })\n+\n+        # Iterate through the indexd data, reading\n+        # key : appid, name of the index.d file (appid.yml)\n+        # value : list of entries to go into that file\n+        for key, value in indexd_data.items():\n+\n+            # Dump the yml value to the key.yml in index.d\n+            if key is not None:\n+                file_name = self._index_dotd + \"/\" + key + \".yml\"\n+\n+                if os.path.exists(file_name):\n+                    os.remove(file_name)\n+                with open(file_name, \"a+\") as the_file:\n+                    safe_dump(value, the_file, default_flow_style=False)\n+\n+        return","path":"jenkinsbuilder/indexdindexymltransform.py","position":148,"original_position":150,"commit_id":"3e5aea6ca0eda2a32bedf25755e524e3ea91f963","original_commit_id":"7cbe6384289a292571d701d0ebd5aac94b947b7e","user":{"login":"rtnpro","id":231684,"avatar_url":"https://avatars.githubusercontent.com/u/231684?v=3","gravatar_id":"","url":"https://api.github.com/users/rtnpro","html_url":"https://github.com/rtnpro","followers_url":"https://api.github.com/users/rtnpro/followers","following_url":"https://api.github.com/users/rtnpro/following{/other_user}","gists_url":"https://api.github.com/users/rtnpro/gists{/gist_id}","starred_url":"https://api.github.com/users/rtnpro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rtnpro/subscriptions","organizations_url":"https://api.github.com/users/rtnpro/orgs","repos_url":"https://api.github.com/users/rtnpro/repos","events_url":"https://api.github.com/users/rtnpro/events{/privacy}","received_events_url":"https://api.github.com/users/rtnpro/received_events","type":"User","site_admin":false},"body":"@mohammedzee1000 ping?","created_at":"2016-08-22T14:22:48Z","updated_at":"2016-08-22T14:22:48Z","html_url":"https://github.com/CentOS/container-pipeline-service/pull/33#discussion_r75686373","pull_request_url":"https://api.github.com/repos/CentOS/container-pipeline-service/pulls/33","_links":{"self":{"href":"https://api.github.com/repos/CentOS/container-pipeline-service/pulls/comments/75686373"},"html":{"href":"https://github.com/CentOS/container-pipeline-service/pull/33#discussion_r75686373"},"pull_request":{"href":"https://api.github.com/repos/CentOS/container-pipeline-service/pulls/33"}}},"pull_request":{"url":"https://api.github.com/repos/CentOS/container-pipeline-service/pulls/33","id":82148829,"html_url":"https://github.com/CentOS/container-pipeline-service/pull/33","diff_url":"https://github.com/CentOS/container-pipeline-service/pull/33.diff","patch_url":"https://github.com/CentOS/container-pipeline-service/pull/33.patch","issue_url":"https://api.github.com/repos/CentOS/container-pipeline-service/issues/33","number":33,"state":"open","locked":false,"title":"Added script to transform index.d to index.yml and vice versa.","user":{"login":"mohammedzee1000","id":8547729,"avatar_url":"https://avatars.githubusercontent.com/u/8547729?v=3","gravatar_id":"","url":"https://api.github.com/users/mohammedzee1000","html_url":"https://github.com/mohammedzee1000","followers_url":"https://api.github.com/users/mohammedzee1000/followers","following_url":"https://api.github.com/users/mohammedzee1000/following{/other_user}","gists_url":"https://api.github.com/users/mohammedzee1000/gists{/gist_id}","starred_url":"https://api.github.com/users/mohammedzee1000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mohammedzee1000/subscriptions","organizations_url":"https://api.github.com/users/mohammedzee1000/orgs","repos_url":"https://api.github.com/users/mohammedzee1000/repos","events_url":"https://api.github.com/users/mohammedzee1000/events{/privacy}","received_events_url":"https://api.github.com/users/mohammedzee1000/received_events","type":"User","site_admin":false},"body":"Changes verified on allinone.\r\n\r\nWill require modification of container index to the new index.d method before merging.","created_at":"2016-08-22T08:05:59Z","updated_at":"2016-08-22T14:22:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"74b99f12349e8cf0210fec3fdb9bdd8072713a17","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/CentOS/container-pipeline-service/pulls/33/commits","review_comments_url":"https://api.github.com/repos/CentOS/container-pipeline-service/pulls/33/comments","review_comment_url":"https://api.github.com/repos/CentOS/container-pipeline-service/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CentOS/container-pipeline-service/issues/33/comments","statuses_url":"https://api.github.com/repos/CentOS/container-pipeline-service/statuses/3e5aea6ca0eda2a32bedf25755e524e3ea91f963","head":{"label":"mohammedzee1000:2016-08-17_20-22-08-indexdotd-handler","ref":"2016-08-17_20-22-08-indexdotd-handler","sha":"3e5aea6ca0eda2a32bedf25755e524e3ea91f963","user":{"login":"mohammedzee1000","id":8547729,"avatar_url":"https://avatars.githubusercontent.com/u/8547729?v=3","gravatar_id":"","url":"https://api.github.com/users/mohammedzee1000","html_url":"https://github.com/mohammedzee1000","followers_url":"https://api.github.com/users/mohammedzee1000/followers","following_url":"https://api.github.com/users/mohammedzee1000/following{/other_user}","gists_url":"https://api.github.com/users/mohammedzee1000/gists{/gist_id}","starred_url":"https://api.github.com/users/mohammedzee1000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mohammedzee1000/subscriptions","organizations_url":"https://api.github.com/users/mohammedzee1000/orgs","repos_url":"https://api.github.com/users/mohammedzee1000/repos","events_url":"https://api.github.com/users/mohammedzee1000/events{/privacy}","received_events_url":"https://api.github.com/users/mohammedzee1000/received_events","type":"User","site_admin":false},"repo":{"id":63306545,"name":"container-pipeline-service","full_name":"mohammedzee1000/container-pipeline-service","owner":{"login":"mohammedzee1000","id":8547729,"avatar_url":"https://avatars.githubusercontent.com/u/8547729?v=3","gravatar_id":"","url":"https://api.github.com/users/mohammedzee1000","html_url":"https://github.com/mohammedzee1000","followers_url":"https://api.github.com/users/mohammedzee1000/followers","following_url":"https://api.github.com/users/mohammedzee1000/following{/other_user}","gists_url":"https://api.github.com/users/mohammedzee1000/gists{/gist_id}","starred_url":"https://api.github.com/users/mohammedzee1000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mohammedzee1000/subscriptions","organizations_url":"https://api.github.com/users/mohammedzee1000/orgs","repos_url":"https://api.github.com/users/mohammedzee1000/repos","events_url":"https://api.github.com/users/mohammedzee1000/events{/privacy}","received_events_url":"https://api.github.com/users/mohammedzee1000/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mohammedzee1000/container-pipeline-service","description":"Code, infrastructure and deployment backend for the CentOS Container Pipeline","fork":true,"url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service","forks_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/forks","keys_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/teams","hooks_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/hooks","issue_events_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/issues/events{/number}","events_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/events","assignees_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/assignees{/user}","branches_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/branches{/branch}","tags_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/tags","blobs_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/git/refs{/sha}","trees_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/statuses/{sha}","languages_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/languages","stargazers_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/stargazers","contributors_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/contributors","subscribers_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/subscribers","subscription_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/subscription","commits_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/commits{/sha}","git_commits_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/git/commits{/sha}","comments_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/comments{/number}","issue_comment_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/issues/comments{/number}","contents_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/contents/{+path}","compare_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/merges","archive_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/downloads","issues_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/issues{/number}","pulls_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/pulls{/number}","milestones_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/milestones{/number}","notifications_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/labels{/name}","releases_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/releases{/id}","deployments_url":"https://api.github.com/repos/mohammedzee1000/container-pipeline-service/deployments","created_at":"2016-07-14T05:56:42Z","updated_at":"2016-07-14T05:56:43Z","pushed_at":"2016-08-22T13:39:19Z","git_url":"git://github.com/mohammedzee1000/container-pipeline-service.git","ssh_url":"git@github.com:mohammedzee1000/container-pipeline-service.git","clone_url":"https://github.com/mohammedzee1000/container-pipeline-service.git","svn_url":"https://github.com/mohammedzee1000/container-pipeline-service","homepage":null,"size":293,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"CentOS:master","ref":"master","sha":"4e2ed76a0a73a705b23de46d16d771ac104e0200","user":{"login":"CentOS","id":79192,"avatar_url":"https://avatars.githubusercontent.com/u/79192?v=3","gravatar_id":"","url":"https://api.github.com/users/CentOS","html_url":"https://github.com/CentOS","followers_url":"https://api.github.com/users/CentOS/followers","following_url":"https://api.github.com/users/CentOS/following{/other_user}","gists_url":"https://api.github.com/users/CentOS/gists{/gist_id}","starred_url":"https://api.github.com/users/CentOS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CentOS/subscriptions","organizations_url":"https://api.github.com/users/CentOS/orgs","repos_url":"https://api.github.com/users/CentOS/repos","events_url":"https://api.github.com/users/CentOS/events{/privacy}","received_events_url":"https://api.github.com/users/CentOS/received_events","type":"Organization","site_admin":false},"repo":{"id":63242015,"name":"container-pipeline-service","full_name":"CentOS/container-pipeline-service","owner":{"login":"CentOS","id":79192,"avatar_url":"https://avatars.githubusercontent.com/u/79192?v=3","gravatar_id":"","url":"https://api.github.com/users/CentOS","html_url":"https://github.com/CentOS","followers_url":"https://api.github.com/users/CentOS/followers","following_url":"https://api.github.com/users/CentOS/following{/other_user}","gists_url":"https://api.github.com/users/CentOS/gists{/gist_id}","starred_url":"https://api.github.com/users/CentOS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CentOS/subscriptions","organizations_url":"https://api.github.com/users/CentOS/orgs","repos_url":"https://api.github.com/users/CentOS/repos","events_url":"https://api.github.com/users/CentOS/events{/privacy}","received_events_url":"https://api.github.com/users/CentOS/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CentOS/container-pipeline-service","description":"Code, infrastructure and deployment backend for the CentOS Container Pipeline","fork":false,"url":"https://api.github.com/repos/CentOS/container-pipeline-service","forks_url":"https://api.github.com/repos/CentOS/container-pipeline-service/forks","keys_url":"https://api.github.com/repos/CentOS/container-pipeline-service/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CentOS/container-pipeline-service/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CentOS/container-pipeline-service/teams","hooks_url":"https://api.github.com/repos/CentOS/container-pipeline-service/hooks","issue_events_url":"https://api.github.com/repos/CentOS/container-pipeline-service/issues/events{/number}","events_url":"https://api.github.com/repos/CentOS/container-pipeline-service/events","assignees_url":"https://api.github.com/repos/CentOS/container-pipeline-service/assignees{/user}","branches_url":"https://api.github.com/repos/CentOS/container-pipeline-service/branches{/branch}","tags_url":"https://api.github.com/repos/CentOS/container-pipeline-service/tags","blobs_url":"https://api.github.com/repos/CentOS/container-pipeline-service/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CentOS/container-pipeline-service/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CentOS/container-pipeline-service/git/refs{/sha}","trees_url":"https://api.github.com/repos/CentOS/container-pipeline-service/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CentOS/container-pipeline-service/statuses/{sha}","languages_url":"https://api.github.com/repos/CentOS/container-pipeline-service/languages","stargazers_url":"https://api.github.com/repos/CentOS/container-pipeline-service/stargazers","contributors_url":"https://api.github.com/repos/CentOS/container-pipeline-service/contributors","subscribers_url":"https://api.github.com/repos/CentOS/container-pipeline-service/subscribers","subscription_url":"https://api.github.com/repos/CentOS/container-pipeline-service/subscription","commits_url":"https://api.github.com/repos/CentOS/container-pipeline-service/commits{/sha}","git_commits_url":"https://api.github.com/repos/CentOS/container-pipeline-service/git/commits{/sha}","comments_url":"https://api.github.com/repos/CentOS/container-pipeline-service/comments{/number}","issue_comment_url":"https://api.github.com/repos/CentOS/container-pipeline-service/issues/comments{/number}","contents_url":"https://api.github.com/repos/CentOS/container-pipeline-service/contents/{+path}","compare_url":"https://api.github.com/repos/CentOS/container-pipeline-service/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CentOS/container-pipeline-service/merges","archive_url":"https://api.github.com/repos/CentOS/container-pipeline-service/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CentOS/container-pipeline-service/downloads","issues_url":"https://api.github.com/repos/CentOS/container-pipeline-service/issues{/number}","pulls_url":"https://api.github.com/repos/CentOS/container-pipeline-service/pulls{/number}","milestones_url":"https://api.github.com/repos/CentOS/container-pipeline-service/milestones{/number}","notifications_url":"https://api.github.com/repos/CentOS/container-pipeline-service/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CentOS/container-pipeline-service/labels{/name}","releases_url":"https://api.github.com/repos/CentOS/container-pipeline-service/releases{/id}","deployments_url":"https://api.github.com/repos/CentOS/container-pipeline-service/deployments","created_at":"2016-07-13T11:55:19Z","updated_at":"2016-08-20T16:58:39Z","pushed_at":"2016-08-22T13:39:19Z","git_url":"git://github.com/CentOS/container-pipeline-service.git","ssh_url":"git@github.com:CentOS/container-pipeline-service.git","clone_url":"https://github.com/CentOS/container-pipeline-service.git","svn_url":"https://github.com/CentOS/container-pipeline-service","homepage":null,"size":296,"stargazers_count":4,"watchers_count":4,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":9,"forks":7,"open_issues":9,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CentOS/container-pipeline-service/pulls/33"},"html":{"href":"https://github.com/CentOS/container-pipeline-service/pull/33"},"issue":{"href":"https://api.github.com/repos/CentOS/container-pipeline-service/issues/33"},"comments":{"href":"https://api.github.com/repos/CentOS/container-pipeline-service/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/CentOS/container-pipeline-service/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/CentOS/container-pipeline-service/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CentOS/container-pipeline-service/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/CentOS/container-pipeline-service/statuses/3e5aea6ca0eda2a32bedf25755e524e3ea91f963"}}}}
{"actor":{"display_login":"rtnpro"}}