Skip to content

feat: 启动时自动发现 GitHub 用户组织,解决全新环境搜不到仓库的问题 - #208

Merged
lishuceo merged 2 commits into
mainfrom
feat/auto-discover-github-orgs
Apr 7, 2026
Merged

feat: 启动时自动发现 GitHub 用户组织,解决全新环境搜不到仓库的问题#208
lishuceo merged 2 commits into
mainfrom
feat/auto-discover-github-orgs

Conversation

@lishuceo

@lishuceo lishuceo commented Apr 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • 启动时通过 gh api user/orgs + gh api user 自动获取当前 GitHub 用户所属的组织和用户名
  • 将 API 发现的组织与 .repo-cache 目录结构发现的组织合并去重,注入系统提示词
  • 解决全新环境下搜索 sce-tools 等组织内仓库时因缺少 --owner 参数而找不到的问题

Test plan

  • npm run typecheck 通过
  • npx vitest run src/claude/__tests__/ — 41 个测试全部通过(含 8 个新增测试)
  • 部署后在全新环境中测试搜索 "sce-tools",验证能匹配到 taptap/sce-tools
  • 检查启动日志中是否出现 GitHub org cache initialized 及正确的组织列表

🤖 Generated with Claude Code

全新环境下 .repo-cache 为空,listKnownOrgs 返回空数组,
导致全局搜索无法匹配到组织内仓库(如 taptap/sce-tools)。
现在启动时通过 gh api 自动获取用户所属组织和用户名,
与缓存目录发现的组织合并,注入系统提示词的搜索指令中。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@claude

claude Bot commented Apr 7, 2026

Copy link
Copy Markdown

Claude finished @lishuceo's task in 1m 35s —— View job


PR Review: Auto-discover GitHub orgs

  • Check for previous review comments
  • Read changed files and understand context
  • Review code for bugs, security, and architecture issues
  • Post review summary

⚠️ Issues Found

Severity File Issue Confidence
🟡 Warning src/claude/executor.ts:238-241 Promise.all discards both results on partial failure — should use Promise.allSettled 80

Overall Assessment

Clean, well-scoped PR. The approach is sound — using gh api at startup to discover orgs and merging with cache-dir discovery is a good solution for the cold-start problem. Tests are thorough (8 new tests covering success, dedup, failure, ordering, and merge scenarios).

Positives:

  • execFile (not exec) used correctly — no shell injection risk
  • 10s timeout prevents startup from hanging
  • Fire-and-forget in index.ts with .catch(() => {}) — startup isn't blocked
  • Deduplication via Set works correctly
  • slice(0, 20) bump from 10 is reasonable for the expanded source

One suggestion: The Promise.all in initGitHubOrgCache means a failure in either API call (orgs or user login) discards both results. Promise.allSettled would make this more resilient — see inline comment with a suggested fix.

Not blocking — the current behavior is acceptable since the whole function is best-effort with a catch handler. But allSettled would be a small improvement for environments where one endpoint might be restricted.

Comment thread src/claude/executor.ts Outdated
- Promise.all → Promise.allSettled,避免 orgs API 失败时丢失 user login
- 移除未使用的 rmdirSync import
- Function → (...a: unknown[]) => void 修复 @typescript-eslint/ban-types

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@claude

claude Bot commented Apr 7, 2026

Copy link
Copy Markdown

Claude finished @lishuceo's task in 48s —— View job


PR Review: Auto-discover GitHub orgs (re-review after sync)

  • Check and resolve previous review comments
  • Read changed files and review current code
  • Post review summary

✅ Approved — No new issues found

1 previous issue fixed: Promise.allPromise.allSettled with proper partial-failure handling and a dedicated test case.

Code Review

Re-reviewed all 3 changed files after the sync. The code is clean:

  • executor.tsPromise.allSettled correctly preserves partial results (e.g., user login survives a 403 on user/orgs). execFile (not exec) avoids shell injection. 10s timeout is sensible. Dedup via Set and slice(0, 20) cap are both correct.
  • index.ts — Fire-and-forget with .catch(() => {}) is the right pattern here — startup is never blocked by org discovery.
  • github-orgs.test.ts — 8 tests cover all key scenarios: success, dedup, partial failure (403), total failure, cache-dir discovery, merge, ordering, and empty state. Good coverage.

No new issues with confidence ≥ 75.

@lishuceo
lishuceo merged commit 84ff529 into main Apr 7, 2026
8 checks passed
@lishuceo
lishuceo deleted the feat/auto-discover-github-orgs branch April 7, 2026 12:37
lishuceo added a commit that referenced this pull request Apr 8, 2026
* feat: 启动时自动发现 GitHub 用户组织,解决全新环境搜不到仓库的问题

全新环境下 .repo-cache 为空,listKnownOrgs 返回空数组,
导致全局搜索无法匹配到组织内仓库(如 taptap/sce-tools)。
现在启动时通过 gh api 自动获取用户所属组织和用户名,
与缓存目录发现的组织合并,注入系统提示词的搜索指令中。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: 使用 Promise.allSettled 保留部分结果 + 修复 lint errors

- Promise.all → Promise.allSettled,避免 orgs API 失败时丢失 user login
- 移除未使用的 rmdirSync import
- Function → (...a: unknown[]) => void 修复 @typescript-eslint/ban-types

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant