@@ -34,9 +34,83 @@ param (
3434 $WithDate
3535)
3636
37- $repos = Invoke-RestMethod - Uri " https://api.github.com/users/$UserName /repos" - Headers @ { " User-Agent" = " Mozilla/5.0" }
37+ # $repos = Invoke-RestMethod -Uri "https://api.github.com/users/$UserName/repos" -Headers @{ "User-Agent" = "Mozilla/5.0" }
38+ # gh命令返回的信息更多更全
39+ $ghRepos = gh repo list $UserName -- json ' name,url,sshUrl' -- limit 1000 -- source | ConvertFrom-Json
40+ # gh repo list --json
41+ # Specify one or more comma-separated fields for `--json`:
42+ # assignableUsers
43+ # codeOfConduct
44+ # contactLinks
45+ # createdAt
46+ # defaultBranchRef
47+ # deleteBranchOnMerge
48+ # description
49+ # diskUsage
50+ # forkCount
51+ # fundingLinks
52+ # hasIssuesEnabled
53+ # hasProjectsEnabled
54+ # hasWikiEnabled
55+ # homepageUrl
56+ # id
57+ # isArchived
58+ # isBlankIssuesEnabled
59+ # isEmpty
60+ # isFork
61+ # isInOrganization
62+ # isMirror
63+ # isPrivate
64+ # isSecurityPolicyEnabled
65+ # isTemplate
66+ # isUserConfigurationRepository
67+ # issueTemplates
68+ # issues
69+ # labels
70+ # languages
71+ # latestRelease
72+ # licenseInfo
73+ # mentionableUsers
74+ # mergeCommitAllowed
75+ # milestones
76+ # mirrorUrl
77+ # name
78+ # nameWithOwner
79+ # openGraphImageUrl
80+ # owner
81+ # parent
82+ # primaryLanguage
83+ # projects
84+ # pullRequestTemplates
85+ # pullRequests
86+ # pushedAt
87+ # rebaseMergeAllowed
88+ # repositoryTopics
89+ # securityPolicyUrl
90+ # squashMergeAllowed
91+ # sshUrl
92+ # stargazerCount
93+ # templateRepository
94+ # updatedAt
95+ # url
96+ # usesCustomOpenGraphImage
97+ # viewerCanAdminister
98+ # viewerDefaultCommitEmail
99+ # viewerDefaultMergeMethod
100+ # viewerHasStarred
101+ # viewerPermission
102+ # viewerPossibleCommitEmails
103+ # viewerSubscription
104+ # watchers
105+ $finalRepos = $ghRepos | ForEach-Object {
106+ # 创建新对象并添加必要的属性
107+ [PSCustomObject ]@ {
108+ name = $_.name
109+ clone_url = $_.url
110+ }
111+ }
38112
39- $repos
113+ $finalRepos
40114
41115$folderMame = $UserName
42116
@@ -53,17 +127,25 @@ if (-not (Test-Path $repoParentPath)) {
53127}
54128
55129
56- foreach ($repo in $repos ) {
130+ foreach ($repo in $finalRepos ) {
57131 $repoName = $repo.name
58132 $repoUrl = $repo.clone_url
59133 $repoPath = " $repoParentPath \$repoName "
60134
61- # 检查是否已经存在该目录,如果不存在则克隆完整仓库镜像
135+ # 检查是否已经存在该目录
62136 if (-not (Test-Path - Path $repoPath )) {
63137 gh repo clone $repoUrl $repoPath -- -- mirror
64138 }
65139 else {
66- Write-Output " Repository '$repoName ' already exists, skipping..."
140+ Write-Output " Repository '$repoName ' already exists, updating..."
141+ Push-Location $repoPath
142+ try {
143+ git fetch -- all
144+ git remote update
145+ }
146+ finally {
147+ Pop-Location
148+ }
67149 }
68150}
69151
0 commit comments