{"action":"created","comment":{"url":"https://api.github.com/repos/coreos/coreos-assembler/pulls/comments/238913117","pull_request_review_id":181569772,"id":238913117,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzODkxMzExNw==","diff_hunk":"@@ -0,0 +1,177 @@\n+#!/usr/bin/python3 -u\n+# Allows users to operate on the tags in `builds.json`\n+#\n+# Examples:\n+#\n+#   $ coreos-assembler tag update --tag smoketested --build 47.152\n+#   $ coreos-assembler tag delete --tag beta\n+#   $ coreos-assembler tag list\n+#\n+import argparse\n+import json\n+import os\n+import sys\n+\n+sys.path.insert(0, '/usr/lib/coreos-assembler')\n+from cmdlib import fatal, rfc3339_time, write_json\n+\n+\n+def main():\n+    \"\"\"Main entry point\"\"\"\n+\n+    args = parse_args()\n+    args.func(args)\n+\n+\n+def parse_args():\n+    \"\"\"Parse args and dispatch\"\"\"\n+\n+    parser = argparse.ArgumentParser()\n+    subparsers = parser.add_subparsers(dest=\"cmd\", title=\"Tag actions\")\n+    subparsers.required = True\n+\n+    delete = subparsers.add_parser(\"delete\",\n+                                   help=\"Delete a tag from the metadata\")\n+    delete.add_argument(\"--tag\", help=\"Tag to delete from metadata\",\n+                        required=True)\n+    delete.set_defaults(func=cmd_delete)\n+\n+    list_tags = subparsers.add_parser(\"list\", help=\"List available tags in \"\n+                                                   \"the metadata\")\n+    list_tags.set_defaults(func=cmd_list)\n+\n+    update = subparsers.add_parser(\"update\", help=\"Update existing tag or \"\n+                                                  \"create a new tag\")\n+    update.add_argument(\"--tag\", help=\"Tag to be updated\", required=True)\n+    update.add_argument(\"--build\", help=\"Build to update tag with\",\n+                        required=True)\n+    update.add_argument(\"--force\", help=\"Force the update of a tag\",\n+                        action=\"store_true\")\n+    update.set_defaults(func=cmd_update)\n+\n+    return parser.parse_args()\n+\n+\n+def init_build_data():\n+    \"\"\"Initialize build metadata\"\"\"\n+\n+    builds_json = \"builds/builds.json\"\n+\n+    if os.path.isfile(builds_json):\n+        with open(builds_json) as json_file:\n+            build_data = json.load(json_file)\n+    else:\n+        print(\"INFO: Did not find existing builds.json; starting with empty \"\n+              \"build list and tags list\")\n+        build_data = {\"builds\": [], \"tags\": []}\n+\n+    return build_data\n+\n+\n+def finalize_json(build_data):\n+    \"\"\"Wrapper around cmdlib.write_json()\"\"\"\n+\n+    builds_json = \"builds/builds.json\"\n+\n+    build_data['timestamp'] = rfc3339_time()\n+    write_json(builds_json, build_data)\n+\n+\n+def available_builds(build_data):\n+    \"\"\"Returns the availble build IDs from build metadata\"\"\"\n+\n+    return build_data[\"builds\"]\n+\n+\n+def available_tags(build_data):\n+    \"\"\"Returns the available tag names from build metadata\"\"\"\n+\n+    return [t.get(\"name\") for t in build_data.get(\"tags\", {})]\n+\n+\n+def cmd_list(args):\n+    \"\"\"List available tags in build metadata\"\"\"\n+\n+    build_data = init_build_data()\n+    avail_tags = available_tags(build_data)\n+    if not avail_tags:\n+        print(\"No tags found\")\n+        return\n+\n+    for tag in build_data[\"tags\"]:\n+        print(json.dumps({\"name\": tag.get(\"name\"),\n+                          \"created\": tag.get(\"created\"),\n+                          \"target\": tag.get(\"target\")}))\n+\n+\n+def cmd_update(args):\n+    \"\"\"Create or update a tag to new build ID\"\"\"\n+\n+    build_data = init_build_data()\n+    avail_tags = available_tags(build_data)\n+    avail_builds = available_builds(build_data)\n+\n+    if \"tags\" not in build_data:\n+        build_data[\"tags\"] = []\n+\n+    # tag not available, so let's create it\n+    if args.tag not in avail_tags:\n+        # build not available, check for force\n+        if args.build not in avail_builds:\n+            # force not used, gotta bail\n+            if not args.force:\n+                fatal(\"Cannot create a tag with a build that does not exist\")\n+            if args.force:\n+                print(f\"INFO: Creating a new tag with a build ({args.build}) \"\n+                      \"that does not exist\")","path":"src/cmd-tag","position":126,"original_position":126,"commit_id":"ad14f9013d22e91d6bda567ca639e71482f984e5","original_commit_id":"ad14f9013d22e91d6bda567ca639e71482f984e5","user":{"login":"miabbott","id":10236257,"node_id":"MDQ6VXNlcjEwMjM2MjU3","avatar_url":"https://avatars2.githubusercontent.com/u/10236257?v=4","gravatar_id":"","url":"https://api.github.com/users/miabbott","html_url":"https://github.com/miabbott","followers_url":"https://api.github.com/users/miabbott/followers","following_url":"https://api.github.com/users/miabbott/following{/other_user}","gists_url":"https://api.github.com/users/miabbott/gists{/gist_id}","starred_url":"https://api.github.com/users/miabbott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miabbott/subscriptions","organizations_url":"https://api.github.com/users/miabbott/orgs","repos_url":"https://api.github.com/users/miabbott/repos","events_url":"https://api.github.com/users/miabbott/events{/privacy}","received_events_url":"https://api.github.com/users/miabbott/received_events","type":"User","site_admin":false},"body":"f-strings are used in other parts of the code base and this tool will typically be invoked via the container (which is [built on Fedora 28](https://github.com/coreos/coreos-assembler/blob/master/Dockerfile#L1)), so I feel OK sticking with them.","created_at":"2018-12-05T02:30:01Z","updated_at":"2018-12-05T02:30:01Z","html_url":"https://github.com/coreos/coreos-assembler/pull/243#discussion_r238913117","pull_request_url":"https://api.github.com/repos/coreos/coreos-assembler/pulls/243","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/coreos/coreos-assembler/pulls/comments/238913117"},"html":{"href":"https://github.com/coreos/coreos-assembler/pull/243#discussion_r238913117"},"pull_request":{"href":"https://api.github.com/repos/coreos/coreos-assembler/pulls/243"}},"in_reply_to_id":238867023},"pull_request":{"url":"https://api.github.com/repos/coreos/coreos-assembler/pulls/243","id":235097324,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM1MDk3MzI0","html_url":"https://github.com/coreos/coreos-assembler/pull/243","diff_url":"https://github.com/coreos/coreos-assembler/pull/243.diff","patch_url":"https://github.com/coreos/coreos-assembler/pull/243.patch","issue_url":"https://api.github.com/repos/coreos/coreos-assembler/issues/243","number":243,"state":"open","locked":false,"title":"build-tag: new command to manipulate tagging","user":{"login":"miabbott","id":10236257,"node_id":"MDQ6VXNlcjEwMjM2MjU3","avatar_url":"https://avatars2.githubusercontent.com/u/10236257?v=4","gravatar_id":"","url":"https://api.github.com/users/miabbott","html_url":"https://github.com/miabbott","followers_url":"https://api.github.com/users/miabbott/followers","following_url":"https://api.github.com/users/miabbott/following{/other_user}","gists_url":"https://api.github.com/users/miabbott/gists{/gist_id}","starred_url":"https://api.github.com/users/miabbott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miabbott/subscriptions","organizations_url":"https://api.github.com/users/miabbott/orgs","repos_url":"https://api.github.com/users/miabbott/repos","events_url":"https://api.github.com/users/miabbott/events{/privacy}","received_events_url":"https://api.github.com/users/miabbott/received_events","type":"User","site_admin":false},"body":"The `build-tag` command allows the user to list, create, delete, and\r\nupdate tags in the `builds.json` metadata.\r\n\r\nCloses #184","created_at":"2018-11-30T19:51:02Z","updated_at":"2018-12-05T02:30:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d4f22e5f6c28dd733952ecff2c65b6218b6f8690","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/coreos/coreos-assembler/pulls/243/commits","review_comments_url":"https://api.github.com/repos/coreos/coreos-assembler/pulls/243/comments","review_comment_url":"https://api.github.com/repos/coreos/coreos-assembler/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coreos/coreos-assembler/issues/243/comments","statuses_url":"https://api.github.com/repos/coreos/coreos-assembler/statuses/ad14f9013d22e91d6bda567ca639e71482f984e5","head":{"label":"miabbott:tagging","ref":"tagging","sha":"ad14f9013d22e91d6bda567ca639e71482f984e5","user":{"login":"miabbott","id":10236257,"node_id":"MDQ6VXNlcjEwMjM2MjU3","avatar_url":"https://avatars2.githubusercontent.com/u/10236257?v=4","gravatar_id":"","url":"https://api.github.com/users/miabbott","html_url":"https://github.com/miabbott","followers_url":"https://api.github.com/users/miabbott/followers","following_url":"https://api.github.com/users/miabbott/following{/other_user}","gists_url":"https://api.github.com/users/miabbott/gists{/gist_id}","starred_url":"https://api.github.com/users/miabbott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miabbott/subscriptions","organizations_url":"https://api.github.com/users/miabbott/orgs","repos_url":"https://api.github.com/users/miabbott/repos","events_url":"https://api.github.com/users/miabbott/events{/privacy}","received_events_url":"https://api.github.com/users/miabbott/received_events","type":"User","site_admin":false},"repo":{"id":137792317,"node_id":"MDEwOlJlcG9zaXRvcnkxMzc3OTIzMTc=","name":"coreos-assembler","full_name":"miabbott/coreos-assembler","private":false,"owner":{"login":"miabbott","id":10236257,"node_id":"MDQ6VXNlcjEwMjM2MjU3","avatar_url":"https://avatars2.githubusercontent.com/u/10236257?v=4","gravatar_id":"","url":"https://api.github.com/users/miabbott","html_url":"https://github.com/miabbott","followers_url":"https://api.github.com/users/miabbott/followers","following_url":"https://api.github.com/users/miabbott/following{/other_user}","gists_url":"https://api.github.com/users/miabbott/gists{/gist_id}","starred_url":"https://api.github.com/users/miabbott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miabbott/subscriptions","organizations_url":"https://api.github.com/users/miabbott/orgs","repos_url":"https://api.github.com/users/miabbott/repos","events_url":"https://api.github.com/users/miabbott/events{/privacy}","received_events_url":"https://api.github.com/users/miabbott/received_events","type":"User","site_admin":false},"html_url":"https://github.com/miabbott/coreos-assembler","description":"\"rpm-ostree compose tree\" as a container","fork":true,"url":"https://api.github.com/repos/miabbott/coreos-assembler","forks_url":"https://api.github.com/repos/miabbott/coreos-assembler/forks","keys_url":"https://api.github.com/repos/miabbott/coreos-assembler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/miabbott/coreos-assembler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/miabbott/coreos-assembler/teams","hooks_url":"https://api.github.com/repos/miabbott/coreos-assembler/hooks","issue_events_url":"https://api.github.com/repos/miabbott/coreos-assembler/issues/events{/number}","events_url":"https://api.github.com/repos/miabbott/coreos-assembler/events","assignees_url":"https://api.github.com/repos/miabbott/coreos-assembler/assignees{/user}","branches_url":"https://api.github.com/repos/miabbott/coreos-assembler/branches{/branch}","tags_url":"https://api.github.com/repos/miabbott/coreos-assembler/tags","blobs_url":"https://api.github.com/repos/miabbott/coreos-assembler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/miabbott/coreos-assembler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/miabbott/coreos-assembler/git/refs{/sha}","trees_url":"https://api.github.com/repos/miabbott/coreos-assembler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/miabbott/coreos-assembler/statuses/{sha}","languages_url":"https://api.github.com/repos/miabbott/coreos-assembler/languages","stargazers_url":"https://api.github.com/repos/miabbott/coreos-assembler/stargazers","contributors_url":"https://api.github.com/repos/miabbott/coreos-assembler/contributors","subscribers_url":"https://api.github.com/repos/miabbott/coreos-assembler/subscribers","subscription_url":"https://api.github.com/repos/miabbott/coreos-assembler/subscription","commits_url":"https://api.github.com/repos/miabbott/coreos-assembler/commits{/sha}","git_commits_url":"https://api.github.com/repos/miabbott/coreos-assembler/git/commits{/sha}","comments_url":"https://api.github.com/repos/miabbott/coreos-assembler/comments{/number}","issue_comment_url":"https://api.github.com/repos/miabbott/coreos-assembler/issues/comments{/number}","contents_url":"https://api.github.com/repos/miabbott/coreos-assembler/contents/{+path}","compare_url":"https://api.github.com/repos/miabbott/coreos-assembler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/miabbott/coreos-assembler/merges","archive_url":"https://api.github.com/repos/miabbott/coreos-assembler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/miabbott/coreos-assembler/downloads","issues_url":"https://api.github.com/repos/miabbott/coreos-assembler/issues{/number}","pulls_url":"https://api.github.com/repos/miabbott/coreos-assembler/pulls{/number}","milestones_url":"https://api.github.com/repos/miabbott/coreos-assembler/milestones{/number}","notifications_url":"https://api.github.com/repos/miabbott/coreos-assembler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/miabbott/coreos-assembler/labels{/name}","releases_url":"https://api.github.com/repos/miabbott/coreos-assembler/releases{/id}","deployments_url":"https://api.github.com/repos/miabbott/coreos-assembler/deployments","created_at":"2018-06-18T18:41:48Z","updated_at":"2018-11-14T19:27:27Z","pushed_at":"2018-12-04T21:37:38Z","git_url":"git://github.com/miabbott/coreos-assembler.git","ssh_url":"git@github.com:miabbott/coreos-assembler.git","clone_url":"https://github.com/miabbott/coreos-assembler.git","svn_url":"https://github.com/miabbott/coreos-assembler","homepage":null,"size":246,"stargazers_count":0,"watchers_count":0,"language":"Shell","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"coreos:master","ref":"master","sha":"7af5b50d9e5089f7b82268c16f037b6500e2c040","user":{"login":"coreos","id":3730757,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3MzA3NTc=","avatar_url":"https://avatars3.githubusercontent.com/u/3730757?v=4","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"repo":{"id":133999225,"node_id":"MDEwOlJlcG9zaXRvcnkxMzM5OTkyMjU=","name":"coreos-assembler","full_name":"coreos/coreos-assembler","private":false,"owner":{"login":"coreos","id":3730757,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3MzA3NTc=","avatar_url":"https://avatars3.githubusercontent.com/u/3730757?v=4","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/coreos/coreos-assembler","description":"Tooling container to assemble CoreOS-like systems","fork":false,"url":"https://api.github.com/repos/coreos/coreos-assembler","forks_url":"https://api.github.com/repos/coreos/coreos-assembler/forks","keys_url":"https://api.github.com/repos/coreos/coreos-assembler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coreos/coreos-assembler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coreos/coreos-assembler/teams","hooks_url":"https://api.github.com/repos/coreos/coreos-assembler/hooks","issue_events_url":"https://api.github.com/repos/coreos/coreos-assembler/issues/events{/number}","events_url":"https://api.github.com/repos/coreos/coreos-assembler/events","assignees_url":"https://api.github.com/repos/coreos/coreos-assembler/assignees{/user}","branches_url":"https://api.github.com/repos/coreos/coreos-assembler/branches{/branch}","tags_url":"https://api.github.com/repos/coreos/coreos-assembler/tags","blobs_url":"https://api.github.com/repos/coreos/coreos-assembler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coreos/coreos-assembler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coreos/coreos-assembler/git/refs{/sha}","trees_url":"https://api.github.com/repos/coreos/coreos-assembler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coreos/coreos-assembler/statuses/{sha}","languages_url":"https://api.github.com/repos/coreos/coreos-assembler/languages","stargazers_url":"https://api.github.com/repos/coreos/coreos-assembler/stargazers","contributors_url":"https://api.github.com/repos/coreos/coreos-assembler/contributors","subscribers_url":"https://api.github.com/repos/coreos/coreos-assembler/subscribers","subscription_url":"https://api.github.com/repos/coreos/coreos-assembler/subscription","commits_url":"https://api.github.com/repos/coreos/coreos-assembler/commits{/sha}","git_commits_url":"https://api.github.com/repos/coreos/coreos-assembler/git/commits{/sha}","comments_url":"https://api.github.com/repos/coreos/coreos-assembler/comments{/number}","issue_comment_url":"https://api.github.com/repos/coreos/coreos-assembler/issues/comments{/number}","contents_url":"https://api.github.com/repos/coreos/coreos-assembler/contents/{+path}","compare_url":"https://api.github.com/repos/coreos/coreos-assembler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coreos/coreos-assembler/merges","archive_url":"https://api.github.com/repos/coreos/coreos-assembler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coreos/coreos-assembler/downloads","issues_url":"https://api.github.com/repos/coreos/coreos-assembler/issues{/number}","pulls_url":"https://api.github.com/repos/coreos/coreos-assembler/pulls{/number}","milestones_url":"https://api.github.com/repos/coreos/coreos-assembler/milestones{/number}","notifications_url":"https://api.github.com/repos/coreos/coreos-assembler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coreos/coreos-assembler/labels{/name}","releases_url":"https://api.github.com/repos/coreos/coreos-assembler/releases{/id}","deployments_url":"https://api.github.com/repos/coreos/coreos-assembler/deployments","created_at":"2018-05-18T20:07:27Z","updated_at":"2018-11-30T18:52:14Z","pushed_at":"2018-12-04T21:37:40Z","git_url":"git://github.com/coreos/coreos-assembler.git","ssh_url":"git@github.com:coreos/coreos-assembler.git","clone_url":"https://github.com/coreos/coreos-assembler.git","svn_url":"https://github.com/coreos/coreos-assembler","homepage":"","size":247,"stargazers_count":23,"watchers_count":23,"language":"Shell","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"archived":false,"open_issues_count":26,"license":null,"forks":24,"open_issues":26,"watchers":23,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coreos/coreos-assembler/pulls/243"},"html":{"href":"https://github.com/coreos/coreos-assembler/pull/243"},"issue":{"href":"https://api.github.com/repos/coreos/coreos-assembler/issues/243"},"comments":{"href":"https://api.github.com/repos/coreos/coreos-assembler/issues/243/comments"},"review_comments":{"href":"https://api.github.com/repos/coreos/coreos-assembler/pulls/243/comments"},"review_comment":{"href":"https://api.github.com/repos/coreos/coreos-assembler/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coreos/coreos-assembler/pulls/243/commits"},"statuses":{"href":"https://api.github.com/repos/coreos/coreos-assembler/statuses/ad14f9013d22e91d6bda567ca639e71482f984e5"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"miabbott"}}