def test_valid_list(): tree = ["test/file.file", "test/newfile.file", "test/file.png"] files = filter_content_return_one_of_type(tree, "test", "file") assert "test/file.file" in files assert "test/newfile.file" not in files assert "test/file.png" in files
def test_valid_objects(): tree = [ AIOGitHubAPIRepositoryTreeContent( { "path": "test/file.file", "type": "blob" }, "test/test", "master"), AIOGitHubAPIRepositoryTreeContent( { "path": "test/newfile.file", "type": "blob" }, "test/test", "master"), AIOGitHubAPIRepositoryTreeContent( { "path": "test/file.png", "type": "blob" }, "test/test", "master"), ] files = [ x.filename for x in filter_content_return_one_of_type( tree, "test", "file", "full_path") ] assert "file.file" in files assert "newfile.file" not in files assert "file.png" in files
def gather_files_to_download(repository): """Return a list of file objects to be downloaded.""" files = [] tree = repository.tree ref = f"{repository.ref}".replace("tags/", "") releaseobjects = repository.releases.objects category = repository.data.category remotelocation = repository.content.path.remote if should_try_releases(repository): for release in releaseobjects or []: if ref == release.tag_name: for asset in release.assets or []: files.append(asset) if files: return files if repository.content.single: for treefile in tree: if treefile.filename == repository.data.file_name: files.append( FileInformation(treefile.download_url, treefile.full_path, treefile.filename)) return files if category == "plugin": for treefile in tree: if treefile.path in ["", "dist"]: if remotelocation == "dist" and not treefile.filename.startswith( "dist"): continue if not remotelocation: if not treefile.filename.endswith(".js"): continue if treefile.path != "": continue if not treefile.is_directory: files.append( FileInformation(treefile.download_url, treefile.full_path, treefile.filename)) if files: return files if repository.data.content_in_root: if not repository.data.filename: if category == "theme": tree = filter_content_return_one_of_type( repository.tree, "", "yaml", "full_path") for path in tree: if path.is_directory: continue if path.full_path.startswith(repository.content.path.remote): files.append( FileInformation(path.download_url, path.full_path, path.filename)) return files