gitlink-cli/workflows/academic/10-research-progress.ps1

71 lines
3.6 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# GitLink 科研辅助 — 场景 5进度跟踪与预警 (PowerShell)
param(
[string]$Owner, [string]$Repo, [string]$Org = "",
[int]$Weeks = 4, [string]$Output = "",
[switch]$NoWiki, [switch]$DryRun
)
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Import-Module "$ScriptDir\lib\common.psm1" -Force
$ErrorActionPreference = "Continue"
Check-Auth
if ($Org) { $Owner = $Org; $Repo = "__org__" }
else { $resolved = Resolve-OwnerRepo -Owner $Owner -Repo $Repo; $Owner = $resolved.Owner; $Repo = $resolved.Repo }
$Today = Get-Date -Format "yyyy-MM-dd"
$OutputDir = Join-Path $ScriptDir "..\output"
if (-not (Test-Path $OutputDir)) { New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null }
Log-Title "GitLink 科研辅助 — 进度跟踪与预警"
# 1. Issues
Log-Step "1/4 Issue 数据..."
$openIssues = Invoke-GL @("issue", "+list", "--owner", $Owner, "--repo", $Repo, "--state", "open", "--limit", "100")
$closedIssues = Invoke-GL @("issue", "+list", "--owner", $Owner, "--repo", $Repo, "--state", "closed", "--limit", "100")
$totalOpen = if ($openIssues.ok) { @($openIssues.data.issues ?? $openIssues.data).Count } else { 0 }
$totalClosed = if ($closedIssues.ok) { @($closedIssues.data.issues ?? $closedIssues.data).Count } else { 0 }
# 2. PRs
Log-Step "2/4 PR 数据..."
$mergedPrs = Invoke-GL @("pr", "+list", "--owner", $Owner, "--repo", $Repo, "--state", "merged", "--limit", "100")
$openPrs = Invoke-GL @("pr", "+list", "--owner", $Owner, "--repo", $Repo, "--state", "open", "--limit", "50")
$totalMerged = if ($mergedPrs.ok) { @($mergedPrs.data.issues ?? $mergedPrs.data.pulls ?? $mergedPrs.data).Count } else { 0 }
$totalOpenPrs = if ($openPrs.ok) { @($openPrs.data.issues ?? $openPrs.data.pulls ?? $openPrs.data).Count } else { 0 }
# 3. Releases & CI
Log-Step "3/4 Release & CI..."
$releases = Invoke-GL @("release", "+list", "--owner", $Owner, "--repo", $Repo, "--limit", "20")
$releaseCount = if ($releases.ok) { @($releases.data).Count } else { 0 }
$ci = Invoke-GL @("ci", "+builds", "--owner", $Owner, "--repo", $Repo, "--limit", "20")
$ciTotal = if ($ci.ok) { @($ci.data).Count } else { 0 }
# 4. Health score
Log-Step "4/4 健康评分..."
$iv = [Math]::Min($totalClosed / ($Weeks * 7), 1.0)
$pr = if (($totalMerged + $totalOpenPrs) -gt 0) { $totalMerged / ($totalMerged + $totalOpenPrs) } else { 0 }
$rc = if ($releaseCount -ge 3) { 1.0 } elseif ($releaseCount -ge 1) { 0.5 } else { 0.2 }
$health = [Math]::Round(($iv * 0.30 + $pr * 0.25 + $rc * 0.25 + [Math]::Min(($totalClosed * 0.01), 1.0) * 0.10 + 0.5 * 0.10) * 100, 1)
# Anomalies
$anomalies = @()
if ($totalOpen -gt 20) { $anomalies += "[Warning] 开放 Issue 数量($totalOpen)偏高" }
if ($totalOpenPrs -gt 5) { $anomalies += "[Warning] $totalOpenPrs 个开放 PR 积压" }
if ($releaseCount -eq 0) { $anomalies += "[Info] 无 Release 记录" }
if ($totalOpen -gt $totalClosed) { $anomalies += "[Warning] Issue 积压(开放 > 关闭)" }
$label = if ($health -ge 80) { "健康" } elseif ($health -ge 60) { "正常" } elseif ($health -ge 40) { "需关注" } else { "风险" }
Divider
Write-Host "====== 进度周报摘要 ======" -ForegroundColor White
Write-Host " 仓库: $Owner/$Repo"
Write-Host " 健康评分: $health/100 ($label)"
Write-Host " Issues: $totalOpen 开放 / $totalClosed 关闭"
Write-Host " PRs: $totalOpenPrs 开放 / $totalMerged 合并"
Write-Host " Releases: $releaseCount | CI: $ciTotal"
if ($anomalies.Count -gt 0) {
Write-Host " 异常信号 ($($anomalies.Count)):" -ForegroundColor Yellow
foreach ($a in $anomalies) { Write-Host " $a" }
} else { Write-Host " 未检测到异常" -ForegroundColor Green }
Divider
Log-Ok "分析完成"