Repository navigation
Expand file tree
/
Copy pathGiteaInit.ps1
More file actions
113 lines (100 loc) · 3.05 KB
/
Copy pathGiteaInit.ps1
File metadata and controls
113 lines (100 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
$ErrorActionPreference = "Stop"
. "$($PSScriptRoot)/ModuleMisc.ps1"
$Title = [System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath)
$ConfPath = "$($PSScriptRoot)\Config\$($Title).json"
# セットアップ
function local:Setup() {
winget install "Git.Git"
winget install "Gitea.Tea"
# ココまでやっといてね!
# tea login add --name nas0001 --url http://nas0001:3333 --token xxxxxxxxx
# tea login default nas00001
}
## 設定 #######################################################################
Add-Type -AssemblyName System.ComponentModel
Add-Type -AssemblyName System.Drawing
Invoke-Expression -Command @"
class GiteaInitConf {
[string] `$GITEAURL
[string] `$GITEAORG
[string] `$GITEAKEY
}
"@
# 設定初期化
function local:InitConfFile([string] $Path) {
if ((Test-Path -LiteralPath $Path) -eq $false) {
$Conf = New-Object GiteaInitConf -Property @{
GITEAURL = ""
GITEAORG = ""
GITEAKEY = ""
}
SaveConfFile $Path $Conf
}
}
# 設定書込
function local:SaveConfFile([string] $Path, [GiteaInitConf] $Conf) {
$null = New-Item ([System.IO.Path]::GetDirectoryName($Path)) -ItemType Directory -ErrorAction SilentlyContinue
$Conf | ConvertTo-Json | Out-File -FilePath $Path
}
# 設定読出
function local:LoadConfFile([string] $Path) {
$json = Get-Content -Path $Path | ConvertFrom-Json
$Conf = ConvertFromPSCO ([GiteaInitConf]) $json
return $Conf
}
# 設定編集
function local:EditConfFile([string] $Title, [string] $Path) {
$Conf = LoadConfFile $Path
$ret = ShowSettingDialog $Title $Conf
if ($ret -eq "OK") {
SaveConfFile $Path $Conf
}
}
## 本体 #########################################################################
function local:SetupGitea([string] $Path) {
try {
Push-Location $Path
# リポジトリ名制限
$Repository = [System.IO.Path]::GetFileName($Path)
if (($Repository -match "[^a-zA-Z0-9-]")) {
Write-Host "リポジトリフォルダ名は英数ハイフンのみ使用可能です"
return
}
tea repos create --owner $Conf.GITEAORG --name $Repository
if (-not (Test-Path "$Path\.git")) {
git.exe init
}
git.exe remote remove origin
git.exe remote add origin "http://$($Conf.GITEAURL)/$($Conf.GITEAORG)/$Repository.git"
} catch {
$null = Write-Host "Error:" $_.Exception.Message
} finally {
Pop-Location
}
}
## 本体 #######################################################################
# $args = @("$($ENV:USERPROFILE)\Desktop\bbb")
try {
$null = Write-Host "---$Title---"
# 設定初期化
InitConfFile $ConfPath
# 引数確認
if ($args.Count -eq 0) {
EditConfFile $Title $ConfPath
exit
}
# 処理実行
$Conf = LoadConfFile $ConfPath
foreach ($arg in $args) {
if (Test-Path -LiteralPath $arg) {
if ([System.IO.Directory]::Exists($arg)) {
SetupGitea $arg
}
}
}
} catch {
$null = Write-Host "---例外発生---"
$null = Write-Host $_.Exception.Message
$null = Write-Host $_.ScriptStackTrace
$null = Write-Host "--------------"
}