proof-pr 0.1.12 → 0.1.13
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 +10 -2
- package/dist/index.js +178 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ ProofPR 是给开源维护者和工程团队使用的 PR 证据门禁。它在
|
|
|
12
12
|
npx proof-pr@latest --version
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
当前应输出 `0.1.
|
|
15
|
+
当前应输出 `0.1.13`。
|
|
16
16
|
|
|
17
17
|
不知道用哪个功能时:
|
|
18
18
|
|
|
@@ -30,6 +30,14 @@ npx proof-pr@latest init
|
|
|
30
30
|
|
|
31
31
|
这个命令会生成 `.proofpr.yml` 和 `.github/workflows/proofpr.yml`,提交后打开 PR 即可看到报告。
|
|
32
32
|
|
|
33
|
+
体检接入状态:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx proof-pr@latest doctor
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
这个命令会检查配置文件、workflow、Action 版本、PR 权限和本地 diff 是否可读。
|
|
40
|
+
|
|
33
41
|
本地扫描当前分支:
|
|
34
42
|
|
|
35
43
|
```bash
|
|
@@ -57,7 +65,7 @@ npx proof-pr@latest benchmark --cases benchmarks/cases
|
|
|
57
65
|
## GitHub Action
|
|
58
66
|
|
|
59
67
|
```yaml
|
|
60
|
-
- uses: linsk27/proof-pr@v0.1.
|
|
68
|
+
- uses: linsk27/proof-pr@v0.1.13
|
|
61
69
|
with:
|
|
62
70
|
fail-on: high
|
|
63
71
|
comment: "true"
|
package/dist/index.js
CHANGED
|
@@ -25728,17 +25728,32 @@ function dedupeFindings(findings) {
|
|
|
25728
25728
|
|
|
25729
25729
|
|
|
25730
25730
|
const execFileAsync = (0,external_node_util_namespaceObject.promisify)(external_node_child_process_.execFile);
|
|
25731
|
+
const CLI_VERSION = "0.1.13";
|
|
25731
25732
|
const build_program = new Command();
|
|
25732
25733
|
build_program
|
|
25733
25734
|
.name("proof-pr")
|
|
25734
25735
|
.description("Review pull request evidence, scope, and safety before maintainers spend time on it.")
|
|
25735
|
-
.version(
|
|
25736
|
+
.version(CLI_VERSION);
|
|
25736
25737
|
build_program
|
|
25737
25738
|
.command("guide")
|
|
25738
25739
|
.description("Show a copy-paste friendly guide for common ProofPR tasks.")
|
|
25739
25740
|
.action(() => {
|
|
25740
25741
|
process.stdout.write(renderGuide());
|
|
25741
25742
|
});
|
|
25743
|
+
build_program
|
|
25744
|
+
.command("doctor")
|
|
25745
|
+
.description("Check whether ProofPR is installed correctly in the current repository.")
|
|
25746
|
+
.option("--config <path>", "Path to .proofpr.yml.", ".proofpr.yml")
|
|
25747
|
+
.option("--workflow-path <path>", "Path to the GitHub Actions workflow.", ".github/workflows/proofpr.yml")
|
|
25748
|
+
.option("--base <ref>", "Base git ref used for local diff checks.", "origin/main")
|
|
25749
|
+
.option("--head <ref>", "Head git ref used for local diff checks.", "HEAD")
|
|
25750
|
+
.action(async (options) => {
|
|
25751
|
+
const report = await runDoctor(options);
|
|
25752
|
+
process.stdout.write(renderDoctorReport(report));
|
|
25753
|
+
if (report.checks.some((check) => check.level === "fail")) {
|
|
25754
|
+
process.exitCode = 1;
|
|
25755
|
+
}
|
|
25756
|
+
});
|
|
25742
25757
|
build_program
|
|
25743
25758
|
.command("scan", { isDefault: true })
|
|
25744
25759
|
.description("Scan a git diff and print a ProofPR report.")
|
|
@@ -25836,27 +25851,31 @@ function renderGuide() {
|
|
|
25836
25851
|
npx proof-pr@latest init
|
|
25837
25852
|
然后提交 .proofpr.yml 和 .github/workflows/proofpr.yml,打开 PR 后看评论和 Actions summary。
|
|
25838
25853
|
|
|
25839
|
-
2.
|
|
25854
|
+
2. 体检当前仓库接入状态
|
|
25855
|
+
npx proof-pr@latest doctor
|
|
25856
|
+
检查配置文件、workflow、Action 版本、PR 权限和本地 diff 是否正常。
|
|
25857
|
+
|
|
25858
|
+
3. 本地检查当前分支
|
|
25840
25859
|
npx proof-pr@latest scan --base origin/main --head HEAD --locale zh-CN
|
|
25841
25860
|
适合在发 PR 前先看风险、证据评分和 Review 行动清单。
|
|
25842
25861
|
|
|
25843
|
-
|
|
25862
|
+
4. 生成可分享 HTML 报告
|
|
25844
25863
|
npx proof-pr@latest scan --base origin/main --head HEAD --locale zh-CN --format html --output proofpr-report.html
|
|
25845
25864
|
生成后用浏览器打开 proofpr-report.html。
|
|
25846
25865
|
|
|
25847
|
-
|
|
25866
|
+
5. 生成 GitHub Code Scanning 的 SARIF
|
|
25848
25867
|
npx proof-pr@latest scan --base origin/main --head HEAD --format sarif --output proofpr.sarif
|
|
25849
25868
|
适合在 CI 里配合 github/codeql-action/upload-sarif 使用。
|
|
25850
25869
|
|
|
25851
|
-
|
|
25870
|
+
6. 试跑内置风险案例
|
|
25852
25871
|
npx proof-pr@latest scan --diff-file examples/cases/workflow-untrusted-checkout.diff --locale zh-CN
|
|
25853
25872
|
不需要改项目代码,也能快速看到 ProofPR 会抓什么风险。
|
|
25854
25873
|
|
|
25855
|
-
|
|
25874
|
+
7. 验证规则样本是否仍然命中
|
|
25856
25875
|
npx proof-pr@latest benchmark --cases benchmarks/cases
|
|
25857
25876
|
适合维护 ProofPR 规则或发版前回归。
|
|
25858
25877
|
|
|
25859
|
-
|
|
25878
|
+
8. 调整审查强度
|
|
25860
25879
|
打开 .proofpr.yml,把 preset 改成 security-strict、dependency-careful 或 mcp-security。
|
|
25861
25880
|
|
|
25862
25881
|
结果在哪里看:
|
|
@@ -25864,6 +25883,157 @@ function renderGuide() {
|
|
|
25864
25883
|
- 本地 CLI:终端输出;如果用了 --output,就看写出的 HTML / JSON / SARIF / Markdown 文件。
|
|
25865
25884
|
`;
|
|
25866
25885
|
}
|
|
25886
|
+
async function runDoctor(options) {
|
|
25887
|
+
const checks = [];
|
|
25888
|
+
const nextSteps = new Set();
|
|
25889
|
+
if (await pathExists(options.config)) {
|
|
25890
|
+
try {
|
|
25891
|
+
const config = await loadConfig(options.config);
|
|
25892
|
+
checks.push({
|
|
25893
|
+
level: "pass",
|
|
25894
|
+
title: `${options.config} 可读取`,
|
|
25895
|
+
detail: `locale=${config.locale}, preset=${config.preset}, riskThreshold=${config.riskThreshold}`
|
|
25896
|
+
});
|
|
25897
|
+
if (config.comment.enabled) {
|
|
25898
|
+
checks.push({ level: "pass", title: "PR 评论已启用", detail: "comment.enabled=true" });
|
|
25899
|
+
}
|
|
25900
|
+
else {
|
|
25901
|
+
checks.push({ level: "warn", title: "PR 评论未启用", detail: "comment.enabled=false" });
|
|
25902
|
+
nextSteps.add("如果希望在 PR Conversation 里看到报告,把 .proofpr.yml 的 comment.enabled 改成 true。");
|
|
25903
|
+
}
|
|
25904
|
+
}
|
|
25905
|
+
catch (error) {
|
|
25906
|
+
checks.push({
|
|
25907
|
+
level: "fail",
|
|
25908
|
+
title: `${options.config} 解析失败`,
|
|
25909
|
+
detail: error instanceof Error ? error.message : String(error)
|
|
25910
|
+
});
|
|
25911
|
+
nextSteps.add("修复 .proofpr.yml 的 YAML 格式,或重新运行 npx proof-pr@latest init --force。");
|
|
25912
|
+
}
|
|
25913
|
+
}
|
|
25914
|
+
else {
|
|
25915
|
+
checks.push({ level: "fail", title: `缺少 ${options.config}` });
|
|
25916
|
+
nextSteps.add("运行 npx proof-pr@latest init 生成 .proofpr.yml 和 GitHub Actions workflow。");
|
|
25917
|
+
}
|
|
25918
|
+
if (await pathExists(options.workflowPath)) {
|
|
25919
|
+
const workflow = await (0,promises_namespaceObject.readFile)(options.workflowPath, "utf8");
|
|
25920
|
+
checks.push({ level: "pass", title: `${options.workflowPath} 已存在` });
|
|
25921
|
+
inspectWorkflow(workflow, checks, nextSteps);
|
|
25922
|
+
}
|
|
25923
|
+
else {
|
|
25924
|
+
checks.push({ level: "fail", title: `缺少 ${options.workflowPath}` });
|
|
25925
|
+
nextSteps.add("运行 npx proof-pr@latest init 生成 .github/workflows/proofpr.yml。");
|
|
25926
|
+
}
|
|
25927
|
+
await inspectGitDiff(options, checks, nextSteps);
|
|
25928
|
+
if (nextSteps.size === 0) {
|
|
25929
|
+
nextSteps.add("当前接入状态正常;可以打开 PR,或运行 npx proof-pr@latest scan --base origin/main --head HEAD --locale zh-CN 做本地自查。");
|
|
25930
|
+
}
|
|
25931
|
+
return { checks, nextSteps: [...nextSteps] };
|
|
25932
|
+
}
|
|
25933
|
+
function inspectWorkflow(workflow, checks, nextSteps) {
|
|
25934
|
+
if (/pull_request\s*:/.test(workflow)) {
|
|
25935
|
+
checks.push({ level: "pass", title: "workflow 会在 Pull Request 事件运行" });
|
|
25936
|
+
}
|
|
25937
|
+
else {
|
|
25938
|
+
checks.push({ level: "fail", title: "workflow 没有监听 pull_request" });
|
|
25939
|
+
nextSteps.add("确认 .github/workflows/proofpr.yml 包含 on.pull_request。");
|
|
25940
|
+
}
|
|
25941
|
+
const actionVersion = workflow.match(/linsk27\/proof-pr@(v[0-9]+\.[0-9]+\.[0-9]+)/)?.[1];
|
|
25942
|
+
if (!actionVersion) {
|
|
25943
|
+
checks.push({ level: "fail", title: "workflow 没有使用 linsk27/proof-pr Action" });
|
|
25944
|
+
nextSteps.add(`把 workflow step 更新为 uses: linsk27/proof-pr@v${CLI_VERSION}。`);
|
|
25945
|
+
}
|
|
25946
|
+
else if (actionVersion === `v${CLI_VERSION}`) {
|
|
25947
|
+
checks.push({ level: "pass", title: `GitHub Action 版本为 ${actionVersion}` });
|
|
25948
|
+
}
|
|
25949
|
+
else {
|
|
25950
|
+
checks.push({
|
|
25951
|
+
level: "warn",
|
|
25952
|
+
title: `GitHub Action 版本较旧:${actionVersion}`,
|
|
25953
|
+
detail: `当前 CLI 版本是 v${CLI_VERSION}`
|
|
25954
|
+
});
|
|
25955
|
+
nextSteps.add(`把 workflow 里的 uses 更新为 linsk27/proof-pr@v${CLI_VERSION}。`);
|
|
25956
|
+
}
|
|
25957
|
+
if (/pull-requests\s*:\s*write/.test(workflow)) {
|
|
25958
|
+
checks.push({ level: "pass", title: "workflow 具备写 PR 评论权限" });
|
|
25959
|
+
}
|
|
25960
|
+
else {
|
|
25961
|
+
checks.push({ level: "warn", title: "workflow 可能缺少 pull-requests: write 权限" });
|
|
25962
|
+
nextSteps.add("如果需要自动评论 PR,在 workflow permissions 中加入 pull-requests: write。");
|
|
25963
|
+
}
|
|
25964
|
+
if (/contents\s*:\s*read/.test(workflow)) {
|
|
25965
|
+
checks.push({ level: "pass", title: "workflow 具备读取仓库内容权限" });
|
|
25966
|
+
}
|
|
25967
|
+
else {
|
|
25968
|
+
checks.push({ level: "warn", title: "workflow 未显式声明 contents: read" });
|
|
25969
|
+
nextSteps.add("建议在 workflow permissions 中加入 contents: read。");
|
|
25970
|
+
}
|
|
25971
|
+
}
|
|
25972
|
+
async function inspectGitDiff(options, checks, nextSteps) {
|
|
25973
|
+
try {
|
|
25974
|
+
const { stdout } = await execFileAsync("git", ["rev-parse", "--is-inside-work-tree"]);
|
|
25975
|
+
if (stdout.trim() !== "true") {
|
|
25976
|
+
checks.push({ level: "warn", title: "当前目录不是 Git 仓库" });
|
|
25977
|
+
nextSteps.add("进入项目 Git 仓库根目录后再运行 npx proof-pr@latest doctor。");
|
|
25978
|
+
return;
|
|
25979
|
+
}
|
|
25980
|
+
}
|
|
25981
|
+
catch {
|
|
25982
|
+
checks.push({ level: "warn", title: "当前目录不是 Git 仓库" });
|
|
25983
|
+
nextSteps.add("进入项目 Git 仓库根目录后再运行 npx proof-pr@latest doctor。");
|
|
25984
|
+
return;
|
|
25985
|
+
}
|
|
25986
|
+
checks.push({ level: "pass", title: "当前目录位于 Git 仓库中" });
|
|
25987
|
+
try {
|
|
25988
|
+
const branch = (await execFileAsync("git", ["branch", "--show-current"])).stdout.trim();
|
|
25989
|
+
checks.push({
|
|
25990
|
+
level: "info",
|
|
25991
|
+
title: branch ? `当前分支:${branch}` : "当前处于 detached HEAD"
|
|
25992
|
+
});
|
|
25993
|
+
}
|
|
25994
|
+
catch {
|
|
25995
|
+
checks.push({ level: "info", title: "无法读取当前分支名" });
|
|
25996
|
+
}
|
|
25997
|
+
try {
|
|
25998
|
+
const diff = await readGitDiff(options.base, options.head);
|
|
25999
|
+
checks.push({
|
|
26000
|
+
level: "pass",
|
|
26001
|
+
title: `可以读取 ${options.base}...${options.head} diff`,
|
|
26002
|
+
detail: diff.length === 0 ? "当前没有可扫描的 diff。" : `diff 大小约 ${diff.length} 字符。`
|
|
26003
|
+
});
|
|
26004
|
+
}
|
|
26005
|
+
catch (error) {
|
|
26006
|
+
checks.push({
|
|
26007
|
+
level: "warn",
|
|
26008
|
+
title: `无法读取 ${options.base}...${options.head} diff`,
|
|
26009
|
+
detail: error instanceof Error ? error.message : String(error)
|
|
26010
|
+
});
|
|
26011
|
+
nextSteps.add(`运行 git fetch origin 后重试;如果主分支不是 main,请使用 --base origin/master 或你的实际主分支。`);
|
|
26012
|
+
}
|
|
26013
|
+
}
|
|
26014
|
+
function renderDoctorReport(report) {
|
|
26015
|
+
const failCount = report.checks.filter((check) => check.level === "fail").length;
|
|
26016
|
+
const warnCount = report.checks.filter((check) => check.level === "warn").length;
|
|
26017
|
+
const status = failCount > 0 ? "需要先修复" : warnCount > 0 ? "基本可用,但建议优化" : "接入正常";
|
|
26018
|
+
const checks = report.checks
|
|
26019
|
+
.map((check) => {
|
|
26020
|
+
const detail = check.detail ? `\n ${check.detail}` : "";
|
|
26021
|
+
return `[${check.level}] ${check.title}${detail}`;
|
|
26022
|
+
})
|
|
26023
|
+
.join("\n");
|
|
26024
|
+
const nextSteps = report.nextSteps.map((step) => `- ${step}`).join("\n");
|
|
26025
|
+
return `ProofPR doctor
|
|
26026
|
+
|
|
26027
|
+
状态:${status}
|
|
26028
|
+
统计:${failCount} fail, ${warnCount} warn, ${report.checks.length} checks
|
|
26029
|
+
|
|
26030
|
+
Checks:
|
|
26031
|
+
${checks}
|
|
26032
|
+
|
|
26033
|
+
Next:
|
|
26034
|
+
${nextSteps}
|
|
26035
|
+
`;
|
|
26036
|
+
}
|
|
25867
26037
|
async function readGitDiff(base, head) {
|
|
25868
26038
|
const args = ["diff", "--no-ext-diff", "--unified=0"];
|
|
25869
26039
|
if (base) {
|
|
@@ -25925,7 +26095,7 @@ jobs:
|
|
|
25925
26095
|
runs-on: ubuntu-latest
|
|
25926
26096
|
steps:
|
|
25927
26097
|
- uses: actions/checkout@v4
|
|
25928
|
-
- uses: linsk27/proof-pr@
|
|
26098
|
+
- uses: linsk27/proof-pr@v${CLI_VERSION}
|
|
25929
26099
|
with:
|
|
25930
26100
|
fail-on: ${failOn}
|
|
25931
26101
|
comment: "true"
|