def _fetchProject(self, targetdir, clone_url, name, commits, skip_dirs): self.logger.info('Fetching project "{}"'.format(name)) try: workdir = tempfile.mkdtemp() except IOError: self.logger.error("Cannot create temporary working directory") return try: try: repo = git.Repo.clone_from(clone_url, workdir) except git.exc.GitCommandError: self.logger.error('Cannot clone git repository "{}" to "{}"'.format(clone_url, workdir)) return for commit in commits: self.logger.info('Processing commit "{}"'.format(commit)) pid = ProjectID.get(name, commit) archive = os.path.join(targetdir, pid) + ".tar.gz" prefix = os.path.join(commit, "") try: with open(archive, "wb") as f: repo.archive(f, commit, prefix, format="tar.gz") except (IOError, git.exc.GitCommandError): self.logger.warn('Cannot create archive "{}"'.format(archive)) continue try: repo.git.checkout(commit) except git.exc.GitCommandError: self.logger.warn('Cannot checkout to commit "{}"'.format(commit)) continue input_data = { "resource": workdir, "directories_to_skip": skip_dirs, "project": name, "commit": commit, "ipprefix": name, } try: plugin = GoSymbolsExtractor() if not plugin.setData(input_data): self.logger.warn("Failed to set input data to " + "GoSymbolsExtractor plugin") continue if not plugin.execute(): self.logger.warn("Failed to execute " + "GoSymbolsExtractor plugin") continue output_data = plugin.getData() if not output_data: self.logger.warn("Failed to get output data from " + "GoSymbolsExtractor plugin") continue except: self.logger.warn("Unhandled exception occured during " + "execution of GoSymbolsExtractor plugin") continue api = os.path.join(targetdir, pid) + "-api.json" try: with open(api, "wb") as f: json.dump(output_data[1], f) except IOError: self.logger.error('Cannot save exported API to file "{}"'.format(api)) continue finally: shutil.rmtree(workdir, ignore_errors=True)
def test_valid_output(self, project): plugin = GoSymbolsExtractor() assert plugin.setData(self.input_data) assert plugin.execute() output_data = plugin.getData() assert output_data for data in output_data: validator = ArtefactSchemaValidator(data["artefact"]) assert validator.validate(data)
def getData(self): return GoSymbolsExtractor.getData(self)