dsh-reminder-notify 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/client.js +24 -2
- package/docs/PUBLISH.md +1 -1
- package/docs/detail.en.md +1 -0
- package/docs/detail.zh.md +1 -0
- package/index.js +63 -0
- package/package.json +1 -1
- package/publish/index.json +2 -2
- package/scripts/github-push.ps1 +170 -0
package/README.md
CHANGED
|
@@ -102,6 +102,19 @@ reminder.config() // 当前生效配置的只读副
|
|
|
102
102
|
|
|
103
103
|
## 出问题先自检(0.16 起)
|
|
104
104
|
|
|
105
|
+
面板「高级:历史、余额与宿主」里的「工程与可靠性:自检」有三个按钮:**运行自检**(逐项打勾)、**弹样卡**、**测 GitHub**。
|
|
106
|
+
其中「GitHub 连通性」一项会在 hosts 里发现「把 github.com 指到 127.0.0.1」的本机重定向时标红——那是 Steam++(Watt Toolkit)
|
|
107
|
+
加速 GitHub 的做法:加速器在跑时正常,它没接管(只开了进程没点「一键加速」/被强杀)时浏览器和 git 都会连不上。
|
|
108
|
+
|
|
109
|
+
推送时如果遇到这种情况,直接跑:
|
|
110
|
+
|
|
111
|
+
```powershell
|
|
112
|
+
powershell -NoProfile -ExecutionPolicy Bypass -File scripts/github-push.ps1 -Token ghp_xxx
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
它会先测通不通;不通且发现本机重定向就临时注释 + 刷 DNS 再测,通了才 push,结束再按原样还原 hosts(`-KeepChanges` 保留改动、`-DryRun` 只探测不推送)。
|
|
116
|
+
|
|
117
|
+
|
|
105
118
|
设置面板最下面的「工程与可靠性:自检」里有两个按钮:
|
|
106
119
|
|
|
107
120
|
- **运行自检**:逐条检查系统 / PowerShell / 宿主脚本 / 提示音目录与文件 / 历史文件可写 / 面板路由 / `notify_user` / 配置可写 / 余额接口 / 宿主服务 API / 最近一次宿主退出码,✗ 会带上具体路径或原因。
|
package/client.js
CHANGED
|
@@ -276,6 +276,10 @@ window.__ModuleLoader__.load({
|
|
|
276
276
|
doctorProbe: '弹样卡',
|
|
277
277
|
doctorProbeOk: '样卡已弹出,能看到就说明宿主正常。',
|
|
278
278
|
doctorProbeFailed: '自检失败:',
|
|
279
|
+
doctorGithub: '测 GitHub',
|
|
280
|
+
doctorGithubOk: 'GitHub 能连上:HTTP ',
|
|
281
|
+
doctorGithubFailed: 'GitHub 连不上:',
|
|
282
|
+
check_github: 'GitHub 连通性',
|
|
279
283
|
doctorLastExit: '最近退出码',
|
|
280
284
|
doctorFailures: '最近失败次数',
|
|
281
285
|
check_platform: '系统',
|
|
@@ -412,6 +416,10 @@ window.__ModuleLoader__.load({
|
|
|
412
416
|
doctorProbe: 'Probe a card',
|
|
413
417
|
doctorProbeOk: 'A probe card is on screen; if you can see it, the host is fine.',
|
|
414
418
|
doctorProbeFailed: 'Self-check failed: ',
|
|
419
|
+
doctorGithub: 'Test GitHub',
|
|
420
|
+
doctorGithubOk: 'GitHub reachable: HTTP ',
|
|
421
|
+
doctorGithubFailed: 'GitHub unreachable: ',
|
|
422
|
+
check_github: 'GitHub reachability',
|
|
415
423
|
doctorLastExit: 'last exit code',
|
|
416
424
|
doctorFailures: 'recent failures',
|
|
417
425
|
check_platform: 'platform',
|
|
@@ -943,11 +951,11 @@ window.__ModuleLoader__.load({
|
|
|
943
951
|
setMessage(null)
|
|
944
952
|
Promise.resolve()
|
|
945
953
|
.then(() => {
|
|
946
|
-
const init = mode === 'probe'
|
|
954
|
+
const init = mode === 'probe' || mode === 'github'
|
|
947
955
|
? {
|
|
948
956
|
method: 'POST',
|
|
949
957
|
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
950
|
-
body: JSON.stringify({ mode
|
|
958
|
+
body: JSON.stringify({ mode }),
|
|
951
959
|
}
|
|
952
960
|
: { headers: { accept: 'application/json' } }
|
|
953
961
|
return fetch(DOCTOR_ROUTE, init)
|
|
@@ -967,6 +975,15 @@ window.__ModuleLoader__.load({
|
|
|
967
975
|
setDoctorBusy(false)
|
|
968
976
|
if (data && data.report) setDoctor(data.report)
|
|
969
977
|
const label = typeof t === 'function' ? t : (key) => key
|
|
978
|
+
if (mode === 'github') {
|
|
979
|
+
const probe = data && data.github ? data.github : {}
|
|
980
|
+
if (probe.ok === true) {
|
|
981
|
+
setMessage({ ok: true, text: label('doctorGithubOk') + String(probe.statusCode || '') + ' · ' + String(probe.ms || 0) + 'ms' })
|
|
982
|
+
} else {
|
|
983
|
+
setMessage({ ok: false, text: label('doctorGithubFailed') + String(probe.error || ('HTTP ' + (probe.statusCode || 0))) })
|
|
984
|
+
}
|
|
985
|
+
return
|
|
986
|
+
}
|
|
970
987
|
if (mode === 'probe') {
|
|
971
988
|
const card = data && data.card ? data.card : {}
|
|
972
989
|
if (card.ok === false) {
|
|
@@ -1505,6 +1522,11 @@ window.__ModuleLoader__.load({
|
|
|
1505
1522
|
{ type: 'button', className: 'drn-btn drn-digest-btn', disabled: doctorBusy, onClick: () => runDoctor('probe') },
|
|
1506
1523
|
label('doctorProbe'),
|
|
1507
1524
|
),
|
|
1525
|
+
h(
|
|
1526
|
+
'button',
|
|
1527
|
+
{ type: 'button', className: 'drn-btn drn-digest-btn', disabled: doctorBusy, onClick: () => runDoctor('github') },
|
|
1528
|
+
label(doctorBusy ? 'doctorRunning' : 'doctorGithub'),
|
|
1529
|
+
),
|
|
1508
1530
|
),
|
|
1509
1531
|
),
|
|
1510
1532
|
]
|
package/docs/PUBLISH.md
CHANGED
|
@@ -12,7 +12,7 @@ DSH 的「插件市场 → 发现」页读的是**索引 URL**:一份 JSON(
|
|
|
12
12
|
| 索引地址(他人添加这个) | `https://jiangshuaiye1203.github.io/dsh-reminder-notify/publish/index.json` |
|
|
13
13
|
| 站点首页 | https://jiangshuaiye1203.github.io/dsh-reminder-notify/ |
|
|
14
14
|
| npm 包 | https://www.npmjs.com/package/dsh-reminder-notify |
|
|
15
|
-
| 当前版本 | **0.
|
|
15
|
+
| 当前版本 | **0.16.0**,装源为 **npm**(`dsh-reminder-notify@0.16.0`),不再是 git 固定提交 |
|
|
16
16
|
| Pages | Deploy from a branch,`main` / `(root)` |
|
|
17
17
|
|
|
18
18
|
发新版(npm 源):改代码 → 升 `package.json` 版本 → `scripts\publish-npm.cmd` 发布到 npm →
|
package/docs/detail.en.md
CHANGED
|
@@ -11,3 +11,4 @@ Cards are drawn by the bundled `host/ReminderHost.ps1` with the built-in PowerSh
|
|
|
11
11
|
- **Want it on your phone**: open push under "Digest & push", pick the format, paste your own webhook URL (WeCom bot or Server Chan), then press "Send one now".
|
|
12
12
|
- **Everything else**: folded into "How it works (expand to read)" inside the settings panel below, one topic at a time.
|
|
13
13
|
- **For other plugins**: this plugin exposes a `reminder` service (`notify` / `digest` / `stats` / `config`); see the README.
|
|
14
|
+
- The self-check now has a **GitHub reachability** item (it flags hosts entries pointing github.com at 127.0.0.1, i.e. the Steam++ acceleration table) plus a **Test GitHub** button; `scripts/github-push.ps1` repairs that state around a push and restores hosts afterwards.
|
package/docs/detail.zh.md
CHANGED
|
@@ -11,3 +11,4 @@
|
|
|
11
11
|
- **想推到手机**:在「日报与推送」里打开推送、选格式、填自己的 webhook 地址(企业微信机器人或 Server 酱),点「现在发一条」验证。
|
|
12
12
|
- **其余说明**:全部收在下面设置面板的「使用说明(点开才看)」里,一次只展开一条。
|
|
13
13
|
- **给别的插件用**:本插件对外提供 `reminder` 服务(`notify` / `digest` / `stats` / `config`),写法见 README。
|
|
14
|
+
- 自检里新增「GitHub 连通性」:hosts 里有指向 127.0.0.1 的 github 行(Steam++ 加速表)时标红,另有「测 GitHub」按钮现测一次;推送用 `scripts/github-push.ps1` 可自动处理并还原。
|
package/index.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import { spawn } from 'node:child_process'
|
|
13
13
|
import fs from 'node:fs'
|
|
14
|
+
import https from 'node:https'
|
|
14
15
|
import os from 'node:os'
|
|
15
16
|
import path from 'node:path'
|
|
16
17
|
import { fileURLToPath } from 'node:url'
|
|
@@ -1649,6 +1650,33 @@ export function doctorReport(ctx, getSettings) {
|
|
|
1649
1650
|
add('account', service('deepseekAccount') !== undefined, service('deepseekAccount') === undefined ? '读不到余额(不影响卡片)' : '可读余额')
|
|
1650
1651
|
add('service-api', typeof ctx.provide === 'function', typeof ctx.provide === 'function' ? "可 provide('reminder')" : '旧宿主没有 ctx.provide')
|
|
1651
1652
|
|
|
1653
|
+
// 0.16.1:GitHub 连通性。Steam++(Watt Toolkit)加速 GitHub 靠改 hosts 把 github.com
|
|
1654
|
+
// 指到 127.0.0.1,由它的本地代理接住;它没接管(只开了进程没点「一键加速」/被强杀)时,
|
|
1655
|
+
// 浏览器和 git 都会连不上。这里做静态判断:hosts 里有没有本机重定向。
|
|
1656
|
+
// 真正「能不能连」用 POST /doctor {mode:'github'} 现测。
|
|
1657
|
+
const hostsFile = process.platform === 'win32'
|
|
1658
|
+
? path.join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'drivers', 'etc', 'hosts')
|
|
1659
|
+
: '/etc/hosts'
|
|
1660
|
+
let githubLines = []
|
|
1661
|
+
try {
|
|
1662
|
+
githubLines = fs.readFileSync(hostsFile, 'utf8')
|
|
1663
|
+
.split(/\r?\n/)
|
|
1664
|
+
.map((line) => line.trim())
|
|
1665
|
+
.filter((line) => line !== '' && !line.startsWith('#'))
|
|
1666
|
+
.filter((line) => /^\d{1,3}(\.\d{1,3}){3}\s/.test(line))
|
|
1667
|
+
.filter((line) => /github\.com|githubusercontent\.com/i.test(line))
|
|
1668
|
+
} catch {
|
|
1669
|
+
githubLines = []
|
|
1670
|
+
}
|
|
1671
|
+
const loopback = githubLines.filter((line) => /^127\.0\.0\.1\s/.test(line))
|
|
1672
|
+
if (githubLines.length === 0) {
|
|
1673
|
+
add('github', true, 'hosts 里没有 github 重定向(裸连)')
|
|
1674
|
+
} else if (loopback.length === 0) {
|
|
1675
|
+
add('github', true, 'hosts 指向 ' + githubLines[0].split(/\s+/)[0])
|
|
1676
|
+
} else {
|
|
1677
|
+
add('github', false, 'hosts 把 github 指到 127.0.0.1(Steam++ 加速表);加速器没接管就连不上,跑 scripts/github-push.ps1 会自动处理')
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1652
1680
|
const lastExit = hostHealth.lastExit
|
|
1653
1681
|
const hostOk = lastExit === null || lastExit === 0
|
|
1654
1682
|
add('host-exit', hostOk, lastExit === null ? '还没有弹过卡片' : `最近一次退出码 ${lastExit}`)
|
|
@@ -1673,6 +1701,37 @@ export function doctorReport(ctx, getSettings) {
|
|
|
1673
1701
|
|
|
1674
1702
|
const DOCTOR_ROUTE = '/dsh-reminder-notify/doctor'
|
|
1675
1703
|
|
|
1704
|
+
/** 现测一次 https://github.com(HEAD,8 秒超时)。 */
|
|
1705
|
+
export function probeGithub(timeoutMs = 8000) {
|
|
1706
|
+
const started = Date.now()
|
|
1707
|
+
return new Promise((resolve) => {
|
|
1708
|
+
let settled = false
|
|
1709
|
+
const done = (payload) => {
|
|
1710
|
+
if (settled) return
|
|
1711
|
+
settled = true
|
|
1712
|
+
resolve({ ...payload, ms: Date.now() - started })
|
|
1713
|
+
}
|
|
1714
|
+
try {
|
|
1715
|
+
const req = https.request(
|
|
1716
|
+
{ method: 'HEAD', host: 'github.com', path: '/', timeout: timeoutMs, headers: { 'user-agent': 'dsh-reminder-notify-doctor' } },
|
|
1717
|
+
(res) => {
|
|
1718
|
+
res.resume()
|
|
1719
|
+
const code = res.statusCode ?? 0
|
|
1720
|
+
done({ ok: code >= 200 && code < 500, statusCode: code })
|
|
1721
|
+
},
|
|
1722
|
+
)
|
|
1723
|
+
req.on('timeout', () => {
|
|
1724
|
+
req.destroy()
|
|
1725
|
+
done({ ok: false, error: `timeout ${timeoutMs}ms` })
|
|
1726
|
+
})
|
|
1727
|
+
req.on('error', (error) => done({ ok: false, error: String(error?.message ?? error) }))
|
|
1728
|
+
req.end()
|
|
1729
|
+
} catch (error) {
|
|
1730
|
+
done({ ok: false, error: String(error?.message ?? error) })
|
|
1731
|
+
}
|
|
1732
|
+
})
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1676
1735
|
function registerDoctorRoute(ctx, getSettings) {
|
|
1677
1736
|
const web = typeof ctx.get === 'function' ? ctx.get('webServer') : undefined
|
|
1678
1737
|
if (web === undefined || web === null || typeof web.register !== 'function') {
|
|
@@ -1695,6 +1754,10 @@ function registerDoctorRoute(ctx, getSettings) {
|
|
|
1695
1754
|
const body = await readJsonBody(req)
|
|
1696
1755
|
const mode = body !== null && typeof body === 'object' ? str(body.mode, 'check') : 'check'
|
|
1697
1756
|
if (mode === 'check') return reply(res, 200, { ok: true, report: doctorReport(ctx, getSettings) })
|
|
1757
|
+
if (mode === 'github') {
|
|
1758
|
+
const probe = await probeGithub()
|
|
1759
|
+
return reply(res, 200, { ok: true, mode: 'github', github: probe })
|
|
1760
|
+
}
|
|
1698
1761
|
if (mode === 'probe') {
|
|
1699
1762
|
const card = await notify(
|
|
1700
1763
|
'raw',
|
package/package.json
CHANGED
package/publish/index.json
CHANGED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# github-push.ps1 —— 推送前自动处理「Steam++ 加速表把 github.com 指到 127.0.0.1」的情况。
|
|
2
|
+
#
|
|
3
|
+
# 背景:Steam++(Watt Toolkit)加速 GitHub 的原理是改 hosts,把 github.com 指到
|
|
4
|
+
# 127.0.0.1,由它自己的本地代理接住。加速器在跑时一切正常;它没接管(进程开了但
|
|
5
|
+
# 没点「一键加速」、被强杀、崩了)时,浏览器和 git 都会连不上,报
|
|
6
|
+
# ERR_CONNECTION_REFUSED / Empty reply from server。
|
|
7
|
+
#
|
|
8
|
+
# 这个脚本做的事:
|
|
9
|
+
# 1. 先测 https://github.com 通不通;
|
|
10
|
+
# 2. 不通且 hosts 里有 127.0.0.1 的 github 行 → 临时注释它们(加 [dsh-temp] 标记)+ 刷 DNS,再测一次;
|
|
11
|
+
# 3. 通了就 git push(用 -Token,或环境变量 GITHUB_TOKEN,走 extraHeader,不落盘);
|
|
12
|
+
# 4. 无论成功失败,默认结束后把临时注释还原(-KeepChanges 则保留改动,方便继续用裸连)。
|
|
13
|
+
#
|
|
14
|
+
# 用法:
|
|
15
|
+
# powershell -NoProfile -ExecutionPolicy Bypass -File scripts/github-push.ps1 -DryRun
|
|
16
|
+
# powershell -NoProfile -ExecutionPolicy Bypass -File scripts/github-push.ps1 -Token ghp_xxx
|
|
17
|
+
# powershell -NoProfile -ExecutionPolicy Bypass -File scripts/github-push.ps1 -Token ghp_xxx -KeepChanges
|
|
18
|
+
|
|
19
|
+
param(
|
|
20
|
+
[string]$Remote = 'origin',
|
|
21
|
+
[string]$Branch = 'main',
|
|
22
|
+
[string]$Token = $env:GITHUB_TOKEN,
|
|
23
|
+
[string]$RepoRoot = (Split-Path -Parent $PSScriptRoot),
|
|
24
|
+
[switch]$DryRun,
|
|
25
|
+
[switch]$KeepChanges
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
$ErrorActionPreference = 'Stop'
|
|
29
|
+
$HostsPath = Join-Path $env:SystemRoot 'System32\drivers\etc\hosts'
|
|
30
|
+
$Marker = '# [dsh-temp] '
|
|
31
|
+
$script:changed = $false
|
|
32
|
+
$script:restored = $false
|
|
33
|
+
$script:original = @()
|
|
34
|
+
|
|
35
|
+
function Test-GitHub {
|
|
36
|
+
# 用独立进程的 curl.exe 探测:不受 PowerShell 进程内 DNS / 连接池缓存影响,
|
|
37
|
+
# 注释 hosts 后重测能立刻反映真实结果。没有 curl 时退回 HttpWebRequest。
|
|
38
|
+
$curl = Join-Path $env:SystemRoot 'System32\curl.exe'
|
|
39
|
+
if (Test-Path $curl) {
|
|
40
|
+
try {
|
|
41
|
+
$raw = (& $curl -s -o NUL -w '%{http_code}' --max-time 8 --ssl-no-revoke -I https://github.com/ 2>$null | Out-String).Trim()
|
|
42
|
+
$code = 0
|
|
43
|
+
[void][int]::TryParse($raw, [ref]$code)
|
|
44
|
+
if ($code -gt 0) { return @{ ok = ($code -ge 200 -and $code -lt 500); code = $code; error = '' } }
|
|
45
|
+
return @{ ok = $false; code = 0; error = 'curl 无响应(连接超时)' }
|
|
46
|
+
} catch {
|
|
47
|
+
return @{ ok = $false; code = 0; error = $_.Exception.Message }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
52
|
+
$req = [System.Net.HttpWebRequest]::Create('https://github.com/')
|
|
53
|
+
$req.Method = 'HEAD'
|
|
54
|
+
$req.Timeout = 8000
|
|
55
|
+
$req.UserAgent = 'dsh-github-push'
|
|
56
|
+
$res = $req.GetResponse()
|
|
57
|
+
$code = [int]$res.StatusCode
|
|
58
|
+
$res.Close()
|
|
59
|
+
return @{ ok = ($code -ge 200 -and $code -lt 500); code = $code; error = '' }
|
|
60
|
+
} catch {
|
|
61
|
+
return @{ ok = $false; code = 0; error = $_.Exception.Message }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function Clear-Dns {
|
|
66
|
+
try { & "$env:SystemRoot\System32\ipconfig.exe" /flushdns 2>$null | Out-Null } catch { }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function Get-HostsBlockers {
|
|
70
|
+
if (-not (Test-Path $HostsPath)) { return @() }
|
|
71
|
+
$lines = [System.IO.File]::ReadAllLines($HostsPath)
|
|
72
|
+
$hits = New-Object System.Collections.ArrayList
|
|
73
|
+
for ($i = 0; $i -lt $lines.Length; $i++) {
|
|
74
|
+
$trim = $lines[$i].Trim()
|
|
75
|
+
if ($trim -eq '' -or $trim.StartsWith('#')) { continue }
|
|
76
|
+
if ($trim -match '^127\.0\.0\.1\s' -and $trim -match 'github') { [void]$hits.Add($i) }
|
|
77
|
+
}
|
|
78
|
+
return @($hits)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function Set-HostsLines([string[]]$Lines) {
|
|
82
|
+
[System.IO.File]::WriteAllLines($HostsPath, $Lines, (New-Object System.Text.UTF8Encoding($false)))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function Restore-Hosts {
|
|
86
|
+
if (-not $script:changed) { return }
|
|
87
|
+
if ($KeepChanges) {
|
|
88
|
+
Write-Host ' hosts 保持改动(Steam++ 的屏蔽行仍被注释,GitHub 走裸连)。'
|
|
89
|
+
} else {
|
|
90
|
+
try {
|
|
91
|
+
Set-HostsLines $script:original
|
|
92
|
+
Clear-Dns
|
|
93
|
+
Write-Host ' hosts 已还原成原样。'
|
|
94
|
+
$script:restored = $true
|
|
95
|
+
} catch {
|
|
96
|
+
Write-Host (" hosts 还原失败,请手动检查:{0}" -f $_.Exception.Message)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
$script:changed = $false
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
Write-Host '[1/4] 测试 https://github.com ...'
|
|
104
|
+
$probe = Test-GitHub
|
|
105
|
+
if ($probe.ok) {
|
|
106
|
+
Write-Host (" OK(HTTP {0})" -f $probe.code)
|
|
107
|
+
} else {
|
|
108
|
+
Write-Host (" 连不上:{0}" -f $probe.error)
|
|
109
|
+
$blockers = Get-HostsBlockers
|
|
110
|
+
if ($blockers.Count -eq 0) {
|
|
111
|
+
Write-Host ' hosts 里没有 127.0.0.1 的 github 行,问题不在 hosts(可能是代理 / 网络)。'
|
|
112
|
+
Write-Host ' 建议:打开 Steam++ → 网络加速 → 勾 GitHub → 一键加速,并保持它运行。'
|
|
113
|
+
if (-not $DryRun) { exit 2 }
|
|
114
|
+
} else {
|
|
115
|
+
Write-Host (" 发现 {0} 行本机重定向(Steam++ 加速表),临时注释后重试 ..." -f $blockers.Count)
|
|
116
|
+
$script:original = @([System.IO.File]::ReadAllLines($HostsPath))
|
|
117
|
+
$lines = @($script:original)
|
|
118
|
+
foreach ($i in $blockers) { $lines[$i] = $Marker + $lines[$i] }
|
|
119
|
+
Set-HostsLines $lines
|
|
120
|
+
$script:changed = $true
|
|
121
|
+
Clear-Dns
|
|
122
|
+
$probe = Test-GitHub
|
|
123
|
+
if ($probe.ok) {
|
|
124
|
+
Write-Host (" OK(HTTP {0})" -f $probe.code)
|
|
125
|
+
} else {
|
|
126
|
+
Write-Host (" 仍然连不上:{0}" -f $probe.error)
|
|
127
|
+
Write-Host ' 建议:打开 Steam++ → 网络加速 → 勾 GitHub → 一键加速,保持运行后重试。'
|
|
128
|
+
Restore-Hosts
|
|
129
|
+
if (-not $DryRun) { exit 2 }
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
Write-Host '[2/4] 检查仓库状态 ...'
|
|
135
|
+
Push-Location $RepoRoot
|
|
136
|
+
try {
|
|
137
|
+
$status = git status --porcelain
|
|
138
|
+
if ($status) {
|
|
139
|
+
Write-Host ' 工作树有未提交的改动(脚本不会替你提交):'
|
|
140
|
+
$status | ForEach-Object { Write-Host " $_" }
|
|
141
|
+
}
|
|
142
|
+
$ahead = (git rev-list --count "origin/$Branch..HEAD" 2>$null | Out-String).Trim()
|
|
143
|
+
Write-Host (" 待推送提交:{0} 个" -f $ahead)
|
|
144
|
+
|
|
145
|
+
Write-Host '[3/4] 推送 ...'
|
|
146
|
+
if ($DryRun) {
|
|
147
|
+
Write-Host ' -DryRun:跳过实际推送。'
|
|
148
|
+
} elseif ($ahead -eq '0') {
|
|
149
|
+
Write-Host ' 没有需要推送的提交。'
|
|
150
|
+
} elseif (-not $Token) {
|
|
151
|
+
Write-Host ' 没给令牌:请加 -Token ghp_xxx,或先设置环境变量 GITHUB_TOKEN。'
|
|
152
|
+
Write-Host ' 令牌在 https://github.com/settings/tokens/new 生成(勾 repo;要改 .github/workflows 还要勾 workflow)。'
|
|
153
|
+
} else {
|
|
154
|
+
$basic = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("x-access-token:$Token"))
|
|
155
|
+
& git -c credential.helper= -c "http.https://github.com/.extraHeader=Authorization: Basic $basic" push $Remote $Branch
|
|
156
|
+
if ($LASTEXITCODE -ne 0) { throw "git push 失败(退出码 $LASTEXITCODE)" }
|
|
157
|
+
Write-Host ' 推送完成。记得去 https://github.com/settings/tokens 删掉这个临时令牌。'
|
|
158
|
+
}
|
|
159
|
+
} finally {
|
|
160
|
+
Pop-Location
|
|
161
|
+
}
|
|
162
|
+
} catch {
|
|
163
|
+
Write-Host ("出错:{0}" -f $_.Exception.Message)
|
|
164
|
+
exit 1
|
|
165
|
+
} finally {
|
|
166
|
+
Write-Host '[4/4] 收尾 ...'
|
|
167
|
+
$wasChanged = $script:changed
|
|
168
|
+
Restore-Hosts
|
|
169
|
+
if (-not $wasChanged) { Write-Host ' hosts 未改动。' }
|
|
170
|
+
}
|