Skip to content

Instantly share code, notes, and snippets.

@Timberfang
Created December 12, 2022 01:35
Show Gist options
  • Save Timberfang/cef8f3e72ff3d5e97d60ee1c3b3157fb to your computer and use it in GitHub Desktop.
Save Timberfang/cef8f3e72ff3d5e97d60ee1c3b3157fb to your computer and use it in GitHub Desktop.
Download a GitHub repository from a list stored in a csv file. Requires git.
#Requires -Version 5.1
#Requires -Modules PowerShellForGitHub
Set-StrictMode -Version 3.0
function Read-Choice {
$Selection = $RepoList | Out-GridView -PassThru -Title 'Select one or more repositories'
if (-Not $Selection){Exit}
ForEach($Entry in $Selection) {
Get-Repository -OwnerName $Entry.Owner -RepositoryName $Entry.Repo
}
}
function Get-Repository {
<#
.SYNOPSIS
Download a GitHub repository.
.DESCRIPTION
This function will download a GitHub repository.
This repository can be either public or private.
.PARAMETER OwnerName
Name of owner of repository. For example, for the repository PowerShell/vscode-powershell, the owner is "PowerShell".
.PARAMETER RepositoryName
Name of repository. For example, for the repository PowerShell/vscode-powershell, the repository is "vscode-powershell".
.EXAMPLE
Get-Repo -Owner Lycaon37 -Repo PZ-Improved-Komodo
Download the repository PZ-Improved-Komodo
.EXAMPLE
Get-Repo -Owner ciderapp -Repo cider-releases -Asset 6
Download the repository for Cider."
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$OwnerName,
[Parameter(Mandatory,ValueFromPipeline)]
[string]$RepositoryName,
[int]$Asset = 0
)
begin {
# Test GitHub Authentication.
if(-not (Test-GitHubAuthenticationConfigured)){
$SecureString = (Read-Host "Please enter your personal access token." | ConvertTo-SecureString -AsPlainText -Force)
$Credential = New-Object System.Management.Automation.PSCredential "username is ignored", $SecureString
Set-GitHubAuthentication -Credential $Credential
$SecureString = $null # clear this out now that it's no longer needed
$Credential = $null # clear this out now that it's no longer needed
}
}
process {
git clone https://github.com/$OwnerName/$RepositoryName.git $PSScriptRoot\$RepositoryName
}
end {
Write-Verbose "Download of $RepositoryName complete."
}
}
# Collect data from CSV
$RepoList = Get-ChildItem -Path $PSScriptRoot -Filter *.csv | ForEach-Object {
Import-CSV -Path $_
}
Read-Choice
Owner Repo
PowerShell PowerShell
cataclysmbnteam Cataclysm-BN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment