Skip to content

Instantly share code, notes, and snippets.

@kbilsted
Last active June 11, 2022 14:51
Show Gist options
  • Save kbilsted/9b0e74a8e77d67a2edef39c5d38c5e12 to your computer and use it in GitHub Desktop.
Save kbilsted/9b0e74a8e77d67a2edef39c5d38c5e12 to your computer and use it in GitHub Desktop.

Revisions

  1. kbilsted revised this gist Jun 11, 2022. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions PullOrCloneAll
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,6 @@
    $git="C:\Program Files\Git\bin\git.exe"
    $gitHubApiKey = convertto-securestring "ghp_sdafsdfsdaf..." -asplaintext -force


    [Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls11, Tls, Ssl3"

    function PullOrCloneAll($path="c:\src")
    {
    cd $path
  2. kbilsted revised this gist Jun 11, 2022. No changes.
  3. kbilsted revised this gist Jun 11, 2022. 1 changed file with 12 additions and 4 deletions.
    16 changes: 12 additions & 4 deletions PullOrCloneAll
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,9 @@
    # remember to change the $gitHubApiKey
    # remember to change the $uri username

    $git="C:\Program Files\Git\bin\git.exe"
    $gitHubApiKey = "asdjklasdjadsjkasdjklasdjklasdjkl"
    $gitHubApiKey = convertto-securestring "ghp_sdafsdfsdaf..." -asplaintext -force


    [Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls11, Tls, Ssl3"

    @@ -27,7 +31,7 @@ function PullOrCloneAll($path="c:\src")
    }
    function FetchRepoList()
    {
    $uri = "https://api.github.com:443/users/XXXXXXXXXX/repos?page=&per_page=100&access_token="+$gitHubApiKey
    $uri = "https://api.github.com:443/users/kbilsted/repos?page=&per_page=100"

    $all = @()
    $page = 0
    @@ -40,7 +44,7 @@ function FetchRepoList()
    $page += 1
    $urin = $uri.replace("?page=","?page="+$page)

    $repositories = (Invoke-RestMethod -Uri $urin)
    $repositories = (Invoke-RestMethod -Uri $urin -Token $gitHubApiKey)

    Foreach($repo IN $repositories)
    {
    @@ -96,4 +100,8 @@ function Clone($repo)
    {
    Write-Host("Clonning...");
    & $git clone -v --recurse-submodules --progress $repo.Clone_Url $repo.Name # alternatively replace "Clone_Url" with "ssh_url"
    }
    }

    (Get-Host).Version

    pullorcloneall
  4. kbilsted revised this gist Aug 15, 2021. No changes.
  5. kbilsted created this gist Aug 15, 2021.
    99 changes: 99 additions & 0 deletions PullOrCloneAll
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,99 @@
    $git="C:\Program Files\Git\bin\git.exe"
    $gitHubApiKey = "asdjklasdjadsjkasdjklasdjklasdjkl"

    [Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls11, Tls, Ssl3"

    function PullOrCloneAll($path="c:\src")
    {
    cd $path

    $repositories = FetchRepoList

    $i = 0
    Foreach($repo IN $repositories)
    {
    $i += 1
    Write-Host("{0,3} {1,-40} {2,-40}" -f ` $i, $repo.Name, $repo.Clone_Url)

    if(test-path $repo.Name)
    {
    Pull($repo);
    }
    else
    {
    Clone($repo);
    }
    }
    }
    function FetchRepoList()
    {
    $uri = "https://api.github.com:443/users/XXXXXXXXXX/repos?page=&per_page=100&access_token="+$gitHubApiKey

    $all = @()
    $page = 0

    $any = $TRUE
    while($any)
    {
    $any = $FALSE

    $page += 1
    $urin = $uri.replace("?page=","?page="+$page)

    $repositories = (Invoke-RestMethod -Uri $urin)

    Foreach($repo IN $repositories)
    {
    $all += $repo
    $any = $TRUE
    }
    }

    Write-Host("Found " + $All.Count + " repositories")

    return $all | Sort-Object -property Name
    }


    function MayPullFromRepo()
    {
    $status = & $git status --porcelain
    if($status.Length -gt 0)
    {
    Write-Host -ForegroundColor red "!! LOCAL CHANGES - giving up"
    Write-Host("'"+$status+"'" + $status.Length)
    return $FALSE
    }

    $branch = & $git rev-parse --abbrev-ref HEAD
    if($branch -ne "master")
    {
    Write-Host -ForegroundColor red "!! NOT ON MASTER - giving up"
    return $FALSE
    }

    return $TRUE
    }


    function Pull($repo)
    {
    cd $repo.Name

    if(MayPullFromRepo)
    {
    $pullresult = & $git pull --ff-only --no-stat
    if($pullresult -ne "Already up-to-date.")
    {
    Write-Host -ForegroundColor green "" + $pullresult
    }
    }

    cd $path
    }

    function Clone($repo)
    {
    Write-Host("Clonning...");
    & $git clone -v --recurse-submodules --progress $repo.Clone_Url $repo.Name # alternatively replace "Clone_Url" with "ssh_url"
    }