-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_clone_org.ps1
More file actions
35 lines (33 loc) · 1.45 KB
/
github_clone_org.ps1
File metadata and controls
35 lines (33 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Git clone all the repos under an Organization/User
$org = "GoogleContainerTools"
$skipLocal = $true
# Fix for Powershell default to TLSv1.0
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Tls12
[Net.ServicePointManager]::SecurityProtocol = "Tls11, Tls12"
$subDirs = Get-ChildItem -Directory -Name
$userURL = "https://api.github.com/users/" + $org
$reqUser = Invoke-RestMethod $userURL
$repos = $reqUser.public_repos
$pageCount = 0; $perPage = 100; $repoCount = 0
Do {
$pageCount += 1
$pagedURL = "https://api.github.com/orgs/" + $org + "/repos?page=" + $pageCount + "&per_page=" + $perPage
$request = Invoke-WebRequest -Uri $pagedURL
$reqJson = ConvertFrom-Json ($request.Content)
#$reqJson = ConvertFrom-Json $([String]::new($request.Content)) #This is nicer
foreach ($item in $reqJson){
$repoCount += 1
$URL = $item.clone_url
if ($skipLocal){
$localDir = $URL -replace "https://github.com/$org/(.*)\.git",'$1'
if ($subDirs){
if ( $subDirs.Contains($localDir) ){
Write-Host "($repoCount / $repos) Skipping Local: $localDir" -ForegroundColor Red
continue
}
}
}
Write-Host "($repoCount / $repos) Cloning: $URL" -ForegroundColor Green
git clone $URL
}
} While ( $request.Headers.Link.Contains("next") )