git - 使用 Powershell 下载随机 GitHub 存储库

标签 git powershell

我想随机抽取 GitHub 公共(public)存储库样本,将它们一一下载以用于统计目的。我尝试使用以下 Powershell 代码:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$id = Get-Random -Minimum 0 -Maximum 500
$jsonContent = Invoke-WebRequest "http://api.github.com/repositories?since=$id" | ConvertFrom-Json

我确实获得了公共(public)存储库的列表,但我无法限制它们的数量。 我尝试使用 ?page=1&per_page=1 但没有成功。我只想将 clone_url 解析为 git clone

有什么想法吗?也欢迎其他从 github 下载随机存储库的解决方案。

最佳答案

你很接近。这应该有效:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$id = Get-Random -Minimum 0 -Maximum 99
$jsonContent = Invoke-WebRequest "http://api.github.com/repositories?since=1" | ConvertFrom-Json

$gitUrl = Invoke-WebRequest -Uri ($jsonContent[$id].url) | ConvertFrom-Json |  Select-Object -ExpandProperty git_url

git clone $gitUrl

如果您想通过 ssh 克隆,请务必将 git_url 更改为 ssh_url

说明

调用http://api.github.com/repositories?since=x始终代表相同的最后 100 个存储库,因此无需随机化那里的数字。

第一次调用的列表为您提供了 100 个存储库的 api URL。因此,随机检查其中一个并 grep url,以使用另一个 WebRequest 克隆到存储库的 api URL。

关于git - 使用 Powershell 下载随机 GitHub 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53705079/

相关文章:

git - 在git中取消暂存已删除的文件

git - 使用 Git 检查脏索引或未跟踪的文件

powershell - 从 powershell 调用多个命令,例如 psftp

powershell - 在 PowerShell 中对属性上的对象进行分组

powershell - 使用 csv 作为输入运行 powershell 命令

security - 使用 powershell Set-GPPermissions cmdlet 设置 GPO 安全过滤器

arrays - 在 PowerShell 中选择数组的所有对象的一个​​属性的值

GNU screen 中的 Git 推送失败

git - 检索不是类似于存储的提交的已删除存储

java - 更改项目名称未反射(reflect)在 GitHub 上