{"action":"created","comment":{"url":"https://api.github.com/repos/release-engineering/assayist/pulls/comments/230363276","pull_request_review_id":171086949,"id":230363276,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMDM2MzI3Ng==","diff_hunk":"@@ -0,0 +1,147 @@\n+# SPDX-License-Identifier: GPL-3.0+\n+\n+import os\n+import subprocess\n+\n+from assayist.common.models import content, source\n+from assayist.processor.base import Analyzer\n+from assayist.processor.utils import assert_command\n+from assayist.processor.logging import log\n+\n+\n+class ContainerGoAnalyzer(Analyzer):\n+    \"\"\"Analyze the Go executables in a container image layer.\"\"\"\n+\n+    # goversion executable path.\n+    GOVERSION = 'goversion'\n+\n+    # Backvendor executable path.\n+    BACKVENDOR = 'backvendor'\n+\n+    # Output format template for backvendor.\n+    # The module name will be followed by fields in this format.\n+    BACKVENDOR_TEMPLATE = '\\t{{.Ver}}\\t{{.Repo}}\\t{{.Rev}}'\n+\n+    # Types of identified source modules\n+    UPSTREAM = 'upstream'\n+    VENDORED = 'embedded_source_locations'\n+\n+    def run(self):\n+        \"\"\"Start the container Go analyzer.\"\"\"\n+\n+        # Check we have access to the executables we need.\n+        assert_command(self.BACKVENDOR)\n+        assert_command(self.GOVERSION)\n+\n+        build_info = self.read_metadata_file(self.BUILD_FILE)\n+        build_id = build_info['id']\n+        if not self.is_container_build(build_info):\n+            log.info(f'Skipping build {build_id} because the build is not a container')\n+            return\n+\n+        # This container's build is assumed to exist since it is\n+        # created by the main analyzer.\n+        build = content.Build.nodes.get(id_=build_id)\n+        source_location = build.source_location\n+        if not source_location:\n+            log.error('Missing source location for container build')\n+            return\n+\n+        self._process_source_code(source_location)\n+        self._claim_go_executables()\n+\n+    def _process_source_code(self, source_location):\n+        \"\"\"Run backvendor on the source code.\n+\n+        :param SourceLocation source_location: local source code DB node\n+        \"\"\"\n+        # Find the source code.\n+        srcdir = os.path.join(self.input_dir, self.SOURCE_DIR)\n+        options = ['-template', self.BACKVENDOR_TEMPLATE]\n+        cmd = [self.BACKVENDOR] + options + ['.']\n+        bv = subprocess.Popen(cmd, cwd=srcdir,\n+                              stdout=subprocess.PIPE,\n+                              stderr=subprocess.PIPE)\n+        (stdout, stderr) = bv.communicate()\n+        returncode = bv.wait()\n+        if returncode:\n+            raise RuntimeError(f'The command \"{\" \".join(cmd)}\" failed with: {stderr}')\n+\n+        # There may be many top-level repositories, but we are only\n+        # allowed a single 'upstream' relationship type. Only report\n+        # the first top-level repository as \"the upstream\" one.\n+        seen_toplevel = False\n+\n+        # Parse the output from backvendor.\n+        for line in stdout.splitlines():\n+            fields = line.split('\\t')\n+            if len(fields) != 4:\n+                log.error(f'invalid backvendor output: {line}')\n+                continue\n+\n+            mod, ver, repo, rev = fields\n+\n+            # The module field begins with an asterisk for a top-level module\n+            srctype = self.VENDORED\n+            if mod.startswith('*'):\n+                mod = mod[1:]\n+                if not seen_toplevel:\n+                    srctype = self.UPSTREAM\n+                    seen_toplevel = True\n+\n+            self._process_go_module(source_location, srctype,\n+                                    mod, ver, repo, rev)\n+\n+    def _process_go_module(self, source_location, srctype,\n+                           mod, ver, repo, rev):\n+        \"\"\"Update the database with the information from backvendor.\n+\n+        :param SourceLocation source_location: local source location DB node\n+        :param str srctype: either self.UPSTREAM or self.VENDORED\n+        :param str mod: module name\n+        :param str ver: version\n+        :param str repo: repository URL\n+        :param str rev: vcs revision\n+        \"\"\"\n+        upstream = self.create_or_update_source_location(\"#\".join(repo, rev),\n+                                                         ver)\n+        relationship = getattr(source_location, srctype)\n+        relationship.connect(upstream)\n+\n+        namespace, name = mod.split('/', 1)  # There must be at least one '/'\n+        component = source.Component.get_or_create({\n+            'canonical_type': 'golang',\n+            'canonical_namespace': namespace,\n+            'canonical_name': name})[0]\n+\n+        # Connect the component to the upstream source location\n+        component.source_locations.connect(upstream)\n+\n+        if srctype == self.UPSTREAM:\n+            # Connect the component to the local source location it is\n+            # the upstream for.\n+            component.source_locations.connect(source_location)\n+\n+    def _claim_go_executables(self):\n+        not_container_msg = 'Skipping archive {0} since it\\'s not a container image'\n+        for archive in self.read_metadata_file(self.ARCHIVE_FILE):\n+            if not self.is_container_archive(archive):\n+                log.debug(not_container_msg.format(archive['id']))\n+                continue\n+\n+            layer_dir = os.path.join(self.input_dir, 'unpacked_archives',\n+                                     'container_layer',\n+                                     archive['filename'])\n+\n+            cmd = [self.GOVERSION, '.']","path":"assayist/processor/container_go_analyzer.py","position":149,"original_position":136,"commit_id":"1bda94ec5d293113df3fc0bc1c9d3d3380d34ec2","original_commit_id":"f5c3c0a2a6424906f6b06038deb8b58b7690d37b","user":{"login":"mprahl","id":11711106,"node_id":"MDQ6VXNlcjExNzExMTA2","avatar_url":"https://avatars3.githubusercontent.com/u/11711106?v=4","gravatar_id":"","url":"https://api.github.com/users/mprahl","html_url":"https://github.com/mprahl","followers_url":"https://api.github.com/users/mprahl/followers","following_url":"https://api.github.com/users/mprahl/following{/other_user}","gists_url":"https://api.github.com/users/mprahl/gists{/gist_id}","starred_url":"https://api.github.com/users/mprahl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mprahl/subscriptions","organizations_url":"https://api.github.com/users/mprahl/orgs","repos_url":"https://api.github.com/users/mprahl/repos","events_url":"https://api.github.com/users/mprahl/events{/privacy}","received_events_url":"https://api.github.com/users/mprahl/received_events","type":"User","site_admin":false},"body":"@twaugh if you think that's reliable, then that sounds good.","created_at":"2018-11-02T12:52:30Z","updated_at":"2018-11-02T12:52:31Z","html_url":"https://github.com/release-engineering/assayist/pull/33#discussion_r230363276","pull_request_url":"https://api.github.com/repos/release-engineering/assayist/pulls/33","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/release-engineering/assayist/pulls/comments/230363276"},"html":{"href":"https://github.com/release-engineering/assayist/pull/33#discussion_r230363276"},"pull_request":{"href":"https://api.github.com/repos/release-engineering/assayist/pulls/33"}},"in_reply_to_id":230180134},"pull_request":{"url":"https://api.github.com/repos/release-engineering/assayist/pulls/33","id":226155761,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI2MTU1NzYx","html_url":"https://github.com/release-engineering/assayist/pull/33","diff_url":"https://github.com/release-engineering/assayist/pull/33.diff","patch_url":"https://github.com/release-engineering/assayist/pull/33.patch","issue_url":"https://api.github.com/repos/release-engineering/assayist/issues/33","number":33,"state":"open","locked":false,"title":"WIP: add the container Go analyzer","user":{"login":"twaugh","id":6985468,"node_id":"MDQ6VXNlcjY5ODU0Njg=","avatar_url":"https://avatars1.githubusercontent.com/u/6985468?v=4","gravatar_id":"","url":"https://api.github.com/users/twaugh","html_url":"https://github.com/twaugh","followers_url":"https://api.github.com/users/twaugh/followers","following_url":"https://api.github.com/users/twaugh/following{/other_user}","gists_url":"https://api.github.com/users/twaugh/gists{/gist_id}","starred_url":"https://api.github.com/users/twaugh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twaugh/subscriptions","organizations_url":"https://api.github.com/users/twaugh/orgs","repos_url":"https://api.github.com/users/twaugh/repos","events_url":"https://api.github.com/users/twaugh/events{/privacy}","received_events_url":"https://api.github.com/users/twaugh/received_events","type":"User","site_admin":false},"body":"- [x] Analyzer code\r\n- [ ] Tests","created_at":"2018-10-26T16:26:59Z","updated_at":"2018-11-02T12:52:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"df3213b5548c7fe9783f6485e81b4f817657f845","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/release-engineering/assayist/pulls/33/commits","review_comments_url":"https://api.github.com/repos/release-engineering/assayist/pulls/33/comments","review_comment_url":"https://api.github.com/repos/release-engineering/assayist/pulls/comments{/number}","comments_url":"https://api.github.com/repos/release-engineering/assayist/issues/33/comments","statuses_url":"https://api.github.com/repos/release-engineering/assayist/statuses/1bda94ec5d293113df3fc0bc1c9d3d3380d34ec2","head":{"label":"release-engineering:go-analyzer","ref":"go-analyzer","sha":"1bda94ec5d293113df3fc0bc1c9d3d3380d34ec2","user":{"login":"release-engineering","id":9591189,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk1OTExODk=","avatar_url":"https://avatars3.githubusercontent.com/u/9591189?v=4","gravatar_id":"","url":"https://api.github.com/users/release-engineering","html_url":"https://github.com/release-engineering","followers_url":"https://api.github.com/users/release-engineering/followers","following_url":"https://api.github.com/users/release-engineering/following{/other_user}","gists_url":"https://api.github.com/users/release-engineering/gists{/gist_id}","starred_url":"https://api.github.com/users/release-engineering/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/release-engineering/subscriptions","organizations_url":"https://api.github.com/users/release-engineering/orgs","repos_url":"https://api.github.com/users/release-engineering/repos","events_url":"https://api.github.com/users/release-engineering/events{/privacy}","received_events_url":"https://api.github.com/users/release-engineering/received_events","type":"Organization","site_admin":false},"repo":{"id":145765558,"node_id":"MDEwOlJlcG9zaXRvcnkxNDU3NjU1NTg=","name":"assayist","full_name":"release-engineering/assayist","private":false,"owner":{"login":"release-engineering","id":9591189,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk1OTExODk=","avatar_url":"https://avatars3.githubusercontent.com/u/9591189?v=4","gravatar_id":"","url":"https://api.github.com/users/release-engineering","html_url":"https://github.com/release-engineering","followers_url":"https://api.github.com/users/release-engineering/followers","following_url":"https://api.github.com/users/release-engineering/following{/other_user}","gists_url":"https://api.github.com/users/release-engineering/gists{/gist_id}","starred_url":"https://api.github.com/users/release-engineering/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/release-engineering/subscriptions","organizations_url":"https://api.github.com/users/release-engineering/orgs","repos_url":"https://api.github.com/users/release-engineering/repos","events_url":"https://api.github.com/users/release-engineering/events{/privacy}","received_events_url":"https://api.github.com/users/release-engineering/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/release-engineering/assayist","description":"Application to determining composition of build outputs and containers in the product pipeline","fork":false,"url":"https://api.github.com/repos/release-engineering/assayist","forks_url":"https://api.github.com/repos/release-engineering/assayist/forks","keys_url":"https://api.github.com/repos/release-engineering/assayist/keys{/key_id}","collaborators_url":"https://api.github.com/repos/release-engineering/assayist/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/release-engineering/assayist/teams","hooks_url":"https://api.github.com/repos/release-engineering/assayist/hooks","issue_events_url":"https://api.github.com/repos/release-engineering/assayist/issues/events{/number}","events_url":"https://api.github.com/repos/release-engineering/assayist/events","assignees_url":"https://api.github.com/repos/release-engineering/assayist/assignees{/user}","branches_url":"https://api.github.com/repos/release-engineering/assayist/branches{/branch}","tags_url":"https://api.github.com/repos/release-engineering/assayist/tags","blobs_url":"https://api.github.com/repos/release-engineering/assayist/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/release-engineering/assayist/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/release-engineering/assayist/git/refs{/sha}","trees_url":"https://api.github.com/repos/release-engineering/assayist/git/trees{/sha}","statuses_url":"https://api.github.com/repos/release-engineering/assayist/statuses/{sha}","languages_url":"https://api.github.com/repos/release-engineering/assayist/languages","stargazers_url":"https://api.github.com/repos/release-engineering/assayist/stargazers","contributors_url":"https://api.github.com/repos/release-engineering/assayist/contributors","subscribers_url":"https://api.github.com/repos/release-engineering/assayist/subscribers","subscription_url":"https://api.github.com/repos/release-engineering/assayist/subscription","commits_url":"https://api.github.com/repos/release-engineering/assayist/commits{/sha}","git_commits_url":"https://api.github.com/repos/release-engineering/assayist/git/commits{/sha}","comments_url":"https://api.github.com/repos/release-engineering/assayist/comments{/number}","issue_comment_url":"https://api.github.com/repos/release-engineering/assayist/issues/comments{/number}","contents_url":"https://api.github.com/repos/release-engineering/assayist/contents/{+path}","compare_url":"https://api.github.com/repos/release-engineering/assayist/compare/{base}...{head}","merges_url":"https://api.github.com/repos/release-engineering/assayist/merges","archive_url":"https://api.github.com/repos/release-engineering/assayist/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/release-engineering/assayist/downloads","issues_url":"https://api.github.com/repos/release-engineering/assayist/issues{/number}","pulls_url":"https://api.github.com/repos/release-engineering/assayist/pulls{/number}","milestones_url":"https://api.github.com/repos/release-engineering/assayist/milestones{/number}","notifications_url":"https://api.github.com/repos/release-engineering/assayist/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/release-engineering/assayist/labels{/name}","releases_url":"https://api.github.com/repos/release-engineering/assayist/releases{/id}","deployments_url":"https://api.github.com/repos/release-engineering/assayist/deployments","created_at":"2018-08-22T21:37:18Z","updated_at":"2018-11-01T22:32:24Z","pushed_at":"2018-11-02T11:49:33Z","git_url":"git://github.com/release-engineering/assayist.git","ssh_url":"git@github.com:release-engineering/assayist.git","clone_url":"https://github.com/release-engineering/assayist.git","svn_url":"https://github.com/release-engineering/assayist","homepage":null,"size":541,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":4,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":1,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"release-engineering:master","ref":"master","sha":"b0d79fdbbae35ca6cb85d282eb0efac5205cf8e7","user":{"login":"release-engineering","id":9591189,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk1OTExODk=","avatar_url":"https://avatars3.githubusercontent.com/u/9591189?v=4","gravatar_id":"","url":"https://api.github.com/users/release-engineering","html_url":"https://github.com/release-engineering","followers_url":"https://api.github.com/users/release-engineering/followers","following_url":"https://api.github.com/users/release-engineering/following{/other_user}","gists_url":"https://api.github.com/users/release-engineering/gists{/gist_id}","starred_url":"https://api.github.com/users/release-engineering/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/release-engineering/subscriptions","organizations_url":"https://api.github.com/users/release-engineering/orgs","repos_url":"https://api.github.com/users/release-engineering/repos","events_url":"https://api.github.com/users/release-engineering/events{/privacy}","received_events_url":"https://api.github.com/users/release-engineering/received_events","type":"Organization","site_admin":false},"repo":{"id":145765558,"node_id":"MDEwOlJlcG9zaXRvcnkxNDU3NjU1NTg=","name":"assayist","full_name":"release-engineering/assayist","private":false,"owner":{"login":"release-engineering","id":9591189,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk1OTExODk=","avatar_url":"https://avatars3.githubusercontent.com/u/9591189?v=4","gravatar_id":"","url":"https://api.github.com/users/release-engineering","html_url":"https://github.com/release-engineering","followers_url":"https://api.github.com/users/release-engineering/followers","following_url":"https://api.github.com/users/release-engineering/following{/other_user}","gists_url":"https://api.github.com/users/release-engineering/gists{/gist_id}","starred_url":"https://api.github.com/users/release-engineering/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/release-engineering/subscriptions","organizations_url":"https://api.github.com/users/release-engineering/orgs","repos_url":"https://api.github.com/users/release-engineering/repos","events_url":"https://api.github.com/users/release-engineering/events{/privacy}","received_events_url":"https://api.github.com/users/release-engineering/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/release-engineering/assayist","description":"Application to determining composition of build outputs and containers in the product pipeline","fork":false,"url":"https://api.github.com/repos/release-engineering/assayist","forks_url":"https://api.github.com/repos/release-engineering/assayist/forks","keys_url":"https://api.github.com/repos/release-engineering/assayist/keys{/key_id}","collaborators_url":"https://api.github.com/repos/release-engineering/assayist/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/release-engineering/assayist/teams","hooks_url":"https://api.github.com/repos/release-engineering/assayist/hooks","issue_events_url":"https://api.github.com/repos/release-engineering/assayist/issues/events{/number}","events_url":"https://api.github.com/repos/release-engineering/assayist/events","assignees_url":"https://api.github.com/repos/release-engineering/assayist/assignees{/user}","branches_url":"https://api.github.com/repos/release-engineering/assayist/branches{/branch}","tags_url":"https://api.github.com/repos/release-engineering/assayist/tags","blobs_url":"https://api.github.com/repos/release-engineering/assayist/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/release-engineering/assayist/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/release-engineering/assayist/git/refs{/sha}","trees_url":"https://api.github.com/repos/release-engineering/assayist/git/trees{/sha}","statuses_url":"https://api.github.com/repos/release-engineering/assayist/statuses/{sha}","languages_url":"https://api.github.com/repos/release-engineering/assayist/languages","stargazers_url":"https://api.github.com/repos/release-engineering/assayist/stargazers","contributors_url":"https://api.github.com/repos/release-engineering/assayist/contributors","subscribers_url":"https://api.github.com/repos/release-engineering/assayist/subscribers","subscription_url":"https://api.github.com/repos/release-engineering/assayist/subscription","commits_url":"https://api.github.com/repos/release-engineering/assayist/commits{/sha}","git_commits_url":"https://api.github.com/repos/release-engineering/assayist/git/commits{/sha}","comments_url":"https://api.github.com/repos/release-engineering/assayist/comments{/number}","issue_comment_url":"https://api.github.com/repos/release-engineering/assayist/issues/comments{/number}","contents_url":"https://api.github.com/repos/release-engineering/assayist/contents/{+path}","compare_url":"https://api.github.com/repos/release-engineering/assayist/compare/{base}...{head}","merges_url":"https://api.github.com/repos/release-engineering/assayist/merges","archive_url":"https://api.github.com/repos/release-engineering/assayist/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/release-engineering/assayist/downloads","issues_url":"https://api.github.com/repos/release-engineering/assayist/issues{/number}","pulls_url":"https://api.github.com/repos/release-engineering/assayist/pulls{/number}","milestones_url":"https://api.github.com/repos/release-engineering/assayist/milestones{/number}","notifications_url":"https://api.github.com/repos/release-engineering/assayist/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/release-engineering/assayist/labels{/name}","releases_url":"https://api.github.com/repos/release-engineering/assayist/releases{/id}","deployments_url":"https://api.github.com/repos/release-engineering/assayist/deployments","created_at":"2018-08-22T21:37:18Z","updated_at":"2018-11-01T22:32:24Z","pushed_at":"2018-11-02T11:49:33Z","git_url":"git://github.com/release-engineering/assayist.git","ssh_url":"git@github.com:release-engineering/assayist.git","clone_url":"https://github.com/release-engineering/assayist.git","svn_url":"https://github.com/release-engineering/assayist","homepage":null,"size":541,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":4,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":1,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/release-engineering/assayist/pulls/33"},"html":{"href":"https://github.com/release-engineering/assayist/pull/33"},"issue":{"href":"https://api.github.com/repos/release-engineering/assayist/issues/33"},"comments":{"href":"https://api.github.com/repos/release-engineering/assayist/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/release-engineering/assayist/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/release-engineering/assayist/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/release-engineering/assayist/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/release-engineering/assayist/statuses/1bda94ec5d293113df3fc0bc1c9d3d3380d34ec2"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"mprahl"}}