From 8ecbf8a203e2a80f3b9714726f95bdc255c33d5b Mon Sep 17 00:00:00 2001 From: camelliamc <16583354+camelliamc@user.noreply.gitee.com> Date: Tue, 7 Jul 2026 09:25:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(workflows):=20=E4=BF=AE=E5=A4=8D=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=88=9D=E5=A7=8B=E5=8C=96/=E5=A4=9A=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=8D=8F=E5=90=8C=20+=20=E5=85=AC=E5=85=B1=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workflows/03-project-init.ps1 | 8 ++++---- workflows/04-multi-repo-collab.ps1 | 2 +- workflows/lib/common.psm1 | 25 ++++++++++++++++++------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/workflows/03-project-init.ps1 b/workflows/03-project-init.ps1 index 327f480a..4fc7e49f 100644 --- a/workflows/03-project-init.ps1 +++ b/workflows/03-project-init.ps1 @@ -1,4 +1,4 @@ -# ---------------------------------------------------------------- +# ---------------------------------------------------------------- # Scenario 3: One-Click Project Initialization # Flow: Input description -> Create repo -> README/CONTRIBUTING/CI config -> # Initial Issues -> Branch protection -> Initial Release @@ -92,7 +92,7 @@ $readmeContent += "This project is licensed under the MIT License." $wikiOk = $false for ($attempt = 1; $attempt -le 3; $attempt++) { - $wikiResult = Invoke-GL wiki,+create,--owner,$Owner,--repo,$Name,--title,"README",--body,$readmeContent + $wikiResult = Invoke-GL wiki,+create,--owner,$Owner,--repo,$Name,--title,"README",--content,$readmeContent if ($wikiResult -and (Get-JsonOk ($wikiResult | ConvertFrom-Json))) { Log-Ok "README created" $wikiOk = $true @@ -127,7 +127,7 @@ $contribContent += "- Include environment details" $wikiOk = $false for ($attempt = 1; $attempt -le 3; $attempt++) { - $wikiContrib = Invoke-GL wiki,+create,--owner,$Owner,--repo,$Name,--title,"CONTRIBUTING",--body,$contribContent + $wikiContrib = Invoke-GL wiki,+create,--owner,$Owner,--repo,$Name,--title,"CONTRIBUTING",--content,$contribContent if ($wikiContrib -and (Get-JsonOk ($wikiContrib | ConvertFrom-Json))) { Log-Ok "CONTRIBUTING guide created" $wikiOk = $true @@ -150,7 +150,7 @@ $ciContent += "3. **Deploy**: Deploy to staging (master branch only)" + "`n`n" $ciContent += "### Configuration" + "`n`n" $ciContent += "Create a ``.gitlink-ci.yml`` file in the repository root." -Invoke-GL wiki,+create,--owner,$Owner,--repo,$Name,--title,"CI/CD Configuration",--body,$ciContent | Out-Null +Invoke-GL wiki,+create,--owner,$Owner,--repo,$Name,--title,"CI/CD Configuration",--content,$ciContent | Out-Null Log-Ok "CI/CD configuration guide created" # -- Step 5: Create Initial Issues -- diff --git a/workflows/04-multi-repo-collab.ps1 b/workflows/04-multi-repo-collab.ps1 index 9e01e759..f7541934 100644 --- a/workflows/04-multi-repo-collab.ps1 +++ b/workflows/04-multi-repo-collab.ps1 @@ -1,4 +1,4 @@ -# ---------------------------------------------------------------- +# ---------------------------------------------------------------- # Scenario 4: Multi-Repo Collaboration # Flow: Cross-repo issue tracking -> PR status dashboard -> Coordinated release # diff --git a/workflows/lib/common.psm1 b/workflows/lib/common.psm1 index 612a8a0e..c3310061 100644 --- a/workflows/lib/common.psm1 +++ b/workflows/lib/common.psm1 @@ -1,5 +1,10 @@ # Common utilities for gitlink-cli workflow scripts (PowerShell 5.1+) +# CRITICAL: gitlink-cli outputs UTF-8 JSON, but PS 5.1 on Chinese Windows +# defaults to GBK (codepage 936) for decoding external program output. +# Without this, multi-byte UTF-8 chars get garbled and JSON parsing fails. +[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 + $Script:GL = "gitlink-cli" # -- Logging -- @@ -31,25 +36,31 @@ function Check-Auth { # -- CLI Wrapper -- function Invoke-GL { - param([string[]]$Args) - $output = & $Script:GL @Args --format json 2>&1 - return ($output -join "`n") + param([string[]]$Arguments) + # Suppress stderr to keep JSON output clean (errors go to console via error stream) + $output = & $Script:GL @Arguments --format json 2>$null + if ($output) { return ($output -join "`n") } + return "" } function Invoke-GLCheck { - param([string[]]$Args) - $output = Invoke-GL $Args + param([string[]]$Arguments) + $output = Invoke-GL $Arguments + if (-not $output) { + Log-Err "Command returned no output: $Script:GL $($Arguments -join ' ')" + return $null + } try { $json = $output | ConvertFrom-Json if (-not $json.ok) { $errMsg = if ($json.error.message) { $json.error.message } else { "unknown error" } - Log-Err "Command failed: $Script:GL $($Args -join ' ')" + Log-Err "Command failed: $Script:GL $($Arguments -join ' ')" Log-Err $errMsg return $null } return $json } catch { - Log-Err "Command failed (non-JSON): $Script:GL $($Args -join ' ')" + Log-Err "Command failed (non-JSON response): $Script:GL $($Arguments -join ' ')" Log-Err $output return $null }