Skip to content

Commit 7b82e6d

Browse files
committed
docs(downGithub.ps1): 更新脚本描述和参数说明
更新了脚本的.SYNOPSIS和.DESCRIPTION部分,添加了详细的参数说明和示例,以更好地描述脚本的功能和用法。同时,修改了仓库克隆命令,使用`gh repo clone`代替`git clone`,并添加了`--mirror`选项以克隆完整仓库镜像。
1 parent 4eacd64 commit 7b82e6d

1 file changed

Lines changed: 33 additions & 14 deletions

File tree

downGithub.ps1

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,52 @@
11
<#
22
.SYNOPSIS
3-
A short one-line action-based description, e.g. 'Tests if a function is valid'
3+
批量下载指定 GitHub 用户的所有仓库。
4+
45
.DESCRIPTION
5-
A longer description of the function, its purpose, common use cases, etc.
6-
.NOTES
7-
Information or caveats about the function e.g. 'This function is not supported in Linux'
8-
.LINK
9-
Specify a URI to a help page, this will show when Get-Help -Online is used.
10-
.EXAMPLE
11-
Test-MyTestFunction -Verbose
12-
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
13-
#>
6+
此脚本用于下载指定 GitHub 用户的所有公开仓库。
7+
可以选择是否在文件夹名称中包含日期。
148
9+
.PARAMETER UserName
10+
GitHub 用户名(必填)
1511
12+
.PARAMETER Path
13+
下载仓库的本地路径,默认为当前目录
14+
15+
.PARAMETER WithDate
16+
是否在文件夹名称中包含日期
17+
18+
.EXAMPLE
19+
.\downGithub.ps1 -UserName "octocat"
20+
下载用户 octocat 的所有仓库到当前目录
1621
22+
.EXAMPLE
23+
.\downGithub.ps1 -UserName "octocat" -Path "D:\GitRepos" -WithDate
24+
下载用户 octocat 的所有仓库到 D:\GitRepos,并在文件夹名称中包含日期
25+
#>
1726
[CmdletBinding()]
1827
param (
1928
[Parameter(Mandatory = $true)]
2029
$UserName = '',
2130
# 下载执行的路径
2231
[string]
23-
$Path = '.'
32+
$Path = '.',
33+
[switch]
34+
$WithDate
2435
)
2536

2637
$repos = Invoke-RestMethod -Uri "https://api.github.com/users/$UserName/repos" -Headers @{ "User-Agent" = "Mozilla/5.0" }
2738

2839
$repos
2940

30-
$repoParentPath = Join-Path $Path $UserName
41+
$folderMame = $UserName
42+
43+
if ($WithDate) {
44+
$dateString = Get-Date -Format "yyyyMMdd"
45+
$folderMame = "$dateString-$UserName"
46+
}
47+
48+
49+
$repoParentPath = Join-Path $Path $folderMame
3150

3251
if (-not (Test-Path $repoParentPath)) {
3352
New-Item -ItemType Directory -Force -Path $repoParentPath
@@ -39,9 +58,9 @@ foreach ($repo in $repos) {
3958
$repoUrl = $repo.clone_url
4059
$repoPath = "$repoParentPath\$repoName"
4160

42-
# 检查是否已经存在该目录,如果不存在则克隆仓库
61+
# 检查是否已经存在该目录,如果不存在则克隆完整仓库镜像
4362
if (-not (Test-Path -Path $repoPath)) {
44-
git clone $repoUrl $repoPath
63+
gh repo clone $repoUrl $repoPath -- --mirror
4564
}
4665
else {
4766
Write-Output "Repository '$repoName' already exists, skipping..."

0 commit comments

Comments
 (0)