Skip to content

Commit

Permalink
add GITHUB_BACKUPSTARS
Browse files Browse the repository at this point in the history
  • Loading branch information
1ARdotNO committed Nov 19, 2024
1 parent 7579e04 commit 36264e8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ udpate
- GITHUB_INCLUDE_WIKI=yes #optional defaults to yes, set to no to exclude wiki's
- GITHUB_INCLUDE_ISSUES=yes #optional defaults to yes, set to no to exclude issues
- GITHUB_REPOS=repo1,repo2 # optional, use if only backing up specific repo's and org is not set
- GITHUB_BACKUPSTARS=false #optional, use to backup all of your starred repos, targets the user for which the token used belongs to. (recommended to use with ARCHIVEPERITEM true to make a neat archive of all of these)
#Atlassian cloud backup
- ATLASSIANCLOUD_TOKEN=yourapitoken
- ATLASSIANCLOUD_USERNAME=yourusername #emailaddress
Expand Down
40 changes: 40 additions & 0 deletions prescripts/github.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,46 @@ elseif ($ENV:GITHUB_REPOS) {
}
}

if($ENV:GITHUB_BACKUPSTARS -eq "True"){
function Get-GitHubStars {
param (
[string]$Token,
[string]$BaseUrl = "https://api.github.com",
[int]$PerPage = 30
)

# Initialize variables
$headers = @{
Authorization = "token $Token"
Accept = "application/vnd.github.v3+json"
}
$stars = @()
$page = 1

# Loop through pages until all results are retrieved
do {
$url = "$BaseUrl/user/starred?per_page=$PerPage&page=$page"
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get

# Add results to the array
$stars += $response

# Check if the response has content
$hasMoreData = $response.Count -eq $PerPage
$page++
} while ($hasMoreData)

# Return all starred repositories
return $stars
}
$allStars=Get-GitHubStars -Token $ENV:GITHUB_TOKEN
$repos+=$allStars.html_url | ForEach-Object {
Get-GitHubRepository -AccessToken $ENV:GITHUB_TOKEN -Uri $_
}

}


#ERROR IF 0 REPOS are detected
if($repos.count -eq 0){"FATAL ERROR: 0 REPOS FOUND OR SELECTED"}

Expand Down

0 comments on commit 36264e8

Please sign in to comment.