





















@@ -0,0 +1,84 @@
1+import { spawnSync } from "node:child_process";
2+import { chmodSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
3+import { tmpdir } from "node:os";
4+import path from "node:path";
5+import { describe, expect, it } from "vitest";
6+7+const repoRoot = path.resolve(import.meta.dirname, "../..");
8+const helperPath = path.join(
9+repoRoot,
10+".agents/skills/openclaw-pr-maintainer/scripts/github-activity.sh",
11+);
12+13+function runHelper(args: string[]) {
14+const dir = mkdtempSync(path.join(tmpdir(), "github-activity-helper-"));
15+const binDir = path.join(dir, "bin");
16+const logPath = path.join(dir, "gh.log");
17+const ghPath = path.join(binDir, "gh");
18+mkdirSync(binDir);
19+writeFileSync(
20+ghPath,
21+`#!/usr/bin/env bash
22+set -euo pipefail
23+printf '%s\\t' "$@" >> "$FAKE_GH_LOG"
24+printf '\\n' >> "$FAKE_GH_LOG"
25+if [[ "$1" == "api" && "$2" == users/* ]]; then
26+ printf '{"login":"kevinslin","name":"Kevin Lin","created_at":"2010-09-21T00:00:00Z","type":"User"}\\n'
27+ exit 0
28+fi
29+if [[ "$1" == "api" && "$2" == "--paginate" && "$3" == repos/*/issues* ]]; then
30+ printf 'pr\\nissue\\npr\\n'
31+ exit 0
32+fi
33+if [[ "$1" == "api" && "$2" == "--paginate" && "$3" == repos/*/commits* ]]; then
34+ printf 'sha-one\\nsha-two\\n'
35+ exit 0
36+fi
37+if [[ "$1" == "api" && "$2" == "graphql" ]]; then
38+ printf '{"totalCommitContributions":8,"totalIssueContributions":1,"totalPullRequestContributions":3,"totalPullRequestReviewContributions":2}\\n'
39+ exit 0
40+fi
41+printf 'unexpected gh args: %s\\n' "$*" >&2
42+exit 64
43+`,
44+);
45+chmodSync(ghPath, 0o755);
46+const result = spawnSync("bash", [helperPath, ...args], {
47+cwd: repoRoot,
48+encoding: "utf8",
49+env: {
50+ ...process.env,
51+FAKE_GH_LOG: logPath,
52+PATH: `${binDir}:${process.env.PATH ?? ""}`,
53+},
54+});
55+return {
56+log: readFileSync(logPath, "utf8"),
57+ result,
58+};
59+}
60+61+describe("openclaw-pr-maintainer github activity helper", () => {
62+it("counts PRs and issues from one paginated issues response", () => {
63+const { log, result } = runHelper(["--months", "1", "kevinslin"]);
64+65+expect(result.status).toBe(0);
66+expect(result.stderr).toBe("");
67+expect(result.stdout).toContain("Kevin Lin (@kevinslin, User, account created 2010-09-21");
68+expect(result.stdout).toContain("openclaw/openclaw last 1mo: 2 PRs, 1 issues, 2 commits");
69+expect(log.match(/repos\/openclaw\/openclaw\/issues/g)).toHaveLength(1);
70+expect(log.match(/repos\/openclaw\/openclaw\/commits/g)).toHaveLength(1);
71+expect(log).toMatch(/since=\d{4}-\d{2}-\d{2}T00:00:00Z/);
72+});
73+74+it("uses the hourly global activity window for cacheable GraphQL reads", () => {
75+const { log, result } = runHelper(["--months", "1", "--global", "kevinslin"]);
76+77+expect(result.status).toBe(0);
78+expect(result.stdout).toContain(
79+"GitHub public last 1mo: 8 commits, 3 PRs, 1 issues, 2 reviews",
80+);
81+expect(log.match(/api\tgraphql/g)).toHaveLength(1);
82+expect(log).toMatch(/to=\d{4}-\d{2}-\d{2}T\d{2}:00:00Z/);
83+});
84+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。