# @emulators/github 中文文档

规范地址：https://npmcn.com/package/%40emulators/github/

版本：0\.13\.1
npm 元数据更新时间：2026-11-08T22:07:28.460Z
中文译文更新时间：2026-11-13T16:19:30.930Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40emulators/github
原文对照：https://npmcn.com/package/%40emulators/github/?lang=original
项目主页：https://emulate.dev/
源码仓库：https://github.com/vercel-labs/emulate

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：1.8 MB，36 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2026-03-26T20:34:49.145Z
- 最新版本发布：2026-11-08T22:07:28.161Z
- 近 30 天下载量：65794（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：19（近 12 个月 19 个）

## 中文简介

完全状态的 GitHub API 模拟 。 创建、更新和删除在内存中持续存在,并影响相关的实体.

## 安装

```sh
npm install @emulators/github
```

也可以使用：`pnpm add @emulators/github`、`yarn add @emulators/github`、`bun add @emulators/github`

## README

# @ 模拟器/ github

完全状态的 GitHub API 模拟 。 创建、更新和删除在内存中持续存在,并影响相关的实体.

部分 [模拟](https://github.com/vercel-labs/emulate) ——为CI和无网络沙盒提供本地出入口替换服务.

## 安装

```bash
npm install @emulators/github
```

## 终点

### 用户

-   `GET /user` ——认证用户
-   `PATCH /user` ——更新简介
-   `GET /users/:username` ——获得用户
-   `GET /users` 列表用户
-   `GET /users/:username/repos` ——列表用户重置
-   `GET /users/:username/orgs` ——列表用户群
-   `GET /users/:username/followers` - 名单追随者
-   `GET /users/:username/following` - 名单如下:

### 仓库

-   `GET /repos/:owner/:repo` - 拿回钱
-   `GET /repositories/:id` ——通过数字标识重取
-   `POST /user/repos` ——创建用户repo
-   `POST /orgs/:org/repos` ——创建org repo
-   `PATCH /repos/:owner/:repo` - 更新重播
-   `DELETE /repos/:owner/:repo` - 删除还本付息(cascades)
-   `GET/PUT /repos/:owner/:repo/topics` - 获得/取代专题
-   `GET /repos/:owner/:repo/languages` - 语文
-   `GET /repos/:owner/:repo/contributors` ——捐助者
-   `GET /repos/:owner/:repo/forks` ——列表叉
-   `POST /repos/:owner/:repo/forks` ——创建分叉
-   `GET/PUT/DELETE /repos/:owner/:repo/collaborators/:username` - 合作者
-   `GET /repos/:owner/:repo/collaborators/:username/permission`
-   `POST /repos/:owner/:repo/transfer` ——转回
-   `GET /repos/:owner/:repo/tags` ——列表标签

### 目录提交历史( C)

-   `GET /repos/:owner/:repo/readme` 获取存储器 README
-   `GET /repos/:owner/:repo/contents/:path` —— 在参考文献中获取文件或列出目录
-   发送 `Accept: application/vnd.github.raw` 或者说 `application/vnd.github.raw+json` 以文件内容和 README 请求接收原始字节;目录和子模块回复仍为 JSON
-   `GET /:owner/:repo/raw/:ref/:path` ——从已公布的原始 URL 下载文件内容;这与接受谈判分开
-   `PUT/DELETE /repos/:owner/:repo/contents/:path` —— 创建、更新或删除文件并输入更改
-   `GET /repos/:owner/:repo/commits` - 列表带有参考、路径、作者和日期过滤器
-   `GET /repos/:owner/:repo/commits/:ref` ——取得文件diffs和数据的承诺
-   `GET /repos/:owner/:repo/compare/:base...:head` - 比较两名裁判

### 问题

-   `GET /repos/:owner/:repo/issues` 列表(按状态、标签、受让人、里程碑、创建者分列,自此)
-   `POST /repos/:owner/:repo/issues` ——创建
-   `GET /repos/:owner/:repo/issues/:number` - 获取
-   `PATCH /repos/:owner/:repo/issues/:number` ——更新(状态过渡,事件)
-   `PUT/DELETE /repos/:owner/:repo/issues/:number/lock` - 锁定/解锁
-   `GET /repos/:owner/:repo/issues/:number/timeline` - 时间表活动
-   `GET /repos/:owner/:repo/issues/:number/events` - 活动
-   `POST/DELETE /repos/:owner/:repo/issues/:number/assignees` - 管理受让人

### 调取请求

-   `GET /repos/:owner/:repo/pulls` ——列表(按状态,头,底来过滤)
-   `POST /repos/:owner/:repo/pulls` ——创建
-   `GET /repos/:owner/:repo/pulls/:number` - 获取
-   `PATCH /repos/:owner/:repo/pulls/:number` - 最新情况
-   `PUT /repos/:owner/:repo/pulls/:number/merge` ——合并(与分行保护执法)
-   `GET /repos/:owner/:repo/pulls/:number/commits` - 清单承诺
-   `GET /repos/:owner/:repo/pulls/:number/files` ——列表文件
-   `POST/DELETE /repos/:owner/:repo/pulls/:number/requested_reviewers` 管理审查员
-   `PUT /repos/:owner/:repo/pulls/:number/update-branch` ——更新分支

### 评论

-   问题评论:全文 `/repos/:owner/:repo/issues/:number/comments`
-   审查评论:全文 `/repos/:owner/:repo/pulls/:number/comments`
-   提交评论: 完整 CRUD 打开 `/repos/:owner/:repo/commits/:sha/comments`
-   每种类型的全程列表

### 审查

-   `GET /repos/:owner/:repo/pulls/:number/reviews` 清单
-   `POST /repos/:owner/:repo/pulls/:number/reviews` ——创建(带有内置注释)
-   `GET/PUT /repos/:owner/:repo/pulls/:number/reviews/:id` - 获得/更新
-   `POST /repos/:owner/:repo/pulls/:number/reviews/:id/events` 提交
-   `PUT /repos/:owner/:repo/pulls/:number/reviews/:id/dismissals` 开除

### 标签和里程碑

-   标签:完整的 CRUD, 添加/删除问题, 替换全部
-   里程碑:完整的 CRUD, 状态过渡, 发行计数

### 分支和 Git 数据

-   部门:清单、获取、保护 CRUD(状态检查、公关审查、执行管理员)
-   参考文件:获取、匹配、创建、更新、删除
-   提交: 获取, 创建
-   树:得到(带有递归性),创建(带有内含内容)
-   Blobs: 获取, 创建
-   标记: 获取, 创建

### 组织和团队

-   类:获取、更新、列表
-   成员:名单、检查、删除、获得/确定成员
-   团队:完全CRUD,成员,重置

### 释放

-   释放: 完整的 CRUD, 最新的, 通过标签
-   释放资产:完整 CRUD,上传
-   生成发布注释

### 网络呼号

-   Repo webhoks: 完整 CRUD, ping, 测试, 交付
-   Org Webhooks: 完整 CRUD, ping 软件
-   在所有状态变化中向注册的 URL 发送真实的 HTTP

### 搜索

-   `GET /search/repositories` ——全查询语法(用户,org,语言,话题,恒星,叉等)
-   `GET /search/issues` ——发行+PRs(repo,是,是,是,是,是,是标签,是里程碑,状态等)
-   `GET /search/users` ——用户+角数
-   `GET /search/code` ——blob 内容搜索
-   `GET /search/commits` ——承诺信息搜索
-   `GET /search/topics` - 专题搜索
-   `GET /search/labels` ——标签搜索

### 行动

-   工作流程:列表、获取、启用/残疾、调度
-   工作流程运行: 列表、 获取、 取消、 重运行、 删除、 日志
-   任务:列表、获取、日志
-   艺术: 列表、 获取、 删除
-   秘诀: repo + org CRUD

### 检查

-   检查运行:创建,更新,获取,注释,重新请求,列表通过ref/suite. 基于参考的外观接受含有鞭打的分支和标记参考.
-   请检查access-date=中的日期值 (帮助) 检查套接字:创建,获得,首选,再请求,列表通过ref. 基于参考的外观接受含有鞭打的分支和标记参考.
-   从检查结果自动滚动套件状态

### 杂项

-   `GET /_emulate/installation-tokens` 检查无秘密的 GitHub App 安装到的元数据
-   `GET /rate_limit` ——费率限制状况
-   `GET /meta` ——服务器元数据
-   `GET /octocat` - ASCII艺术
-   `GET /emojis` - emoji URLs (英语)
-   `GET /zen` ——随机zen短语
-   `GET /versions` —— API 版本

## 认证

公共回波端点工作没有认证. 私人重置和写入操作需要有效的符号. 增殖用途 `page`编号 :`per_page` 与 `Link` 头.

安装访问令牌作为配置的 GitHub App bot 用于寄存器写入 。 仓库所有权,所选的寄存器访问,以及请求的App权限仍然执行. 需要拉动请求合并 `contents: write` 数据库中。 拉动请求分支更新需要 `pull_requests: write` 和 `contents: write` 在主仓库.

## 种子配置

```yaml
github:
  users:
    - login: octocat
      name: The Octocat
      email: octocat@github.com
  orgs:
    - login: my-org
      name: My Organization
      members:
        - login: octocat
          role: admin
  repos:
    - owner: octocat
      name: hello-world
      language: JavaScript
      auto_init: true
  oauth_apps:
    - client_id: "Iv1.abc123"
      client_secret: "secret_abc123"
      name: "My Web App"
      redirect_uris:
        - "http://localhost:3000/api/auth/callback/github"
  apps:
    - app_id: 12345
      slug: "my-github-app"
      name: "My GitHub App"
      private_key: |
        -----BEGIN RSA PRIVATE KEY-----
        ...your PEM key...
        -----END RSA PRIVATE KEY-----
      permissions:
        contents: read
        issues: write
      events: [push, pull_request]
      installations:
        - installation_id: 100
          account: my-org
          repository_selection: all
```

组织 `members` 是可选的。 每个条目引用一个种子用户 `login`· ; `role` 默认为 `member`时 `admin` 创建一个组织管理员。 未知用户被忽略 。 成员由合成成员支持 `members` 因此,他们也通过团队成员端点出现,并允许进入私人组织的储存库.

这个 `private_key` 调用时需要字段 `seedFromConfig` 直接说 要生成省略的密钥, 请先生成种子, 使用 `materializeGitHubSeedConfig` 并保留返回的关键材料:

```typescript
import { materializeGitHubSeedConfig, seedFromConfig } from '@emulators/github'

const materialized = await materializeGitHubSeedConfig({
  apps: [{ app_id: 12345, slug: 'my-github-app', name: 'My GitHub App' }],
})

seedFromConfig(store, baseUrl, materialized.config)
const privateKey = materialized.generatedPrivateKeys[0]?.private_key
```

这个 `emulate` 软件包在 `createEmulator` 并打开生成的密钥 `generatedSecrets`。当请求私人递送文件时,CLI也可以这样做:

Next.js和Nuxt适配器也实现省去密钥. 他们返回的服务器处理器曝光 `generatedSecrets()`,而持久性则在寒冷的开始中恢复同样的特性。 保持持续快照的隐私,因为它们包含签名密钥. 自定义持久性后端必须执行原子 `initialize()` 使用生成身份时的语义.

```bash
npx emulate start --service github --seed emulate.config.yaml \
  --generated-secrets-file .emulate-secrets.json
```

目的地决不能存在。 模拟去除所继承的ACL,验证有效的所有者独有访问,并在打开收听器或配置无埠之前发布完整的JSON. 处理起步失败取出引号自有文物. 硬性终止可以留下一个完整的文物,在确认没有引用时必须手动取出. 明确密钥不列入文物. Linux 要求 `setfacl` 财务报告和审定财务报表 `getfacl` 从 `acl` 软件包。 当访问控制无法被校验且不支持在Windows上时,会关闭此旗帜. 无 `--generated-secrets-file`, CLI 种子文件继续需要 `private_key`。 。 。 .

## 链接

-   [完整文档](https://emulate.dev/github)
-   [GitHub 图像](https://github.com/vercel-labs/emulate)

## 常见问题

### @emulators/github 是什么？

完全状态的 GitHub API 模拟 。 创建、更新和删除在内存中持续存在,并影响相关的实体\.

### 如何安装 @emulators/github？

在项目目录运行 npm install @emulators/github，或使用 pnpm add / yarn add / bun add。

### @emulators/github 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @emulators/github 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @emulators/github 可以商用吗？

@emulators/github 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @emulators/github 的下载量有多少？

根据 npm 官方下载统计，@emulators/github 在 2026/10/14 – 2026/11/12 这 30 天内被下载 65,794 次，日均约 2,193 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @emulators/github 还在维护吗？

最新版本 0\.13\.1 发布于 2026/11/09（4 天前）；至今共发布 19 个版本，其中过去 12 个月发布了 19 个；首次发布于 2026/03/27。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

