github

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub API Emulator

GitHub API模拟器

Fully stateful GitHub REST API emulation. Creates, updates, and deletes persist in memory and affect related entities.
完全有状态的GitHub REST API模拟。创建、更新和删除操作会保存在内存中,并影响相关实体。

Start

启动

bash
undefined
bash
undefined

GitHub only

GitHub only

npx emulate --service github
npx emulate --service github

Default port

Default port


Or programmatically:

```typescript
import { createEmulator } from 'emulate'

const github = await createEmulator({ service: 'github', port: 4001 })
// github.url === 'http://localhost:4001'

或以编程方式启动:

```typescript
import { createEmulator } from 'emulate'

const github = await createEmulator({ service: 'github', port: 4001 })
// github.url === 'http://localhost:4001'

Auth

身份验证

Pass tokens as
Authorization: Bearer <token>
or
Authorization: token <token>
.
bash
curl http://localhost:4001/user \
  -H "Authorization: Bearer test_token_admin"
Public repo endpoints work without auth. Private repos and write operations require a valid token. When no token is provided, requests fall back to the first seeded user.
通过
Authorization: Bearer <token>
Authorization: token <token>
传递令牌。
bash
curl http://localhost:4001/user \
  -H "Authorization: Bearer test_token_admin"
公开仓库端点无需身份验证即可使用。私有仓库和写入操作需要有效的令牌。未提供令牌时,请求会默认使用第一个预置用户。

GitHub App JWT

GitHub App JWT

Configure apps in the seed config with a private key. Sign a JWT with
{ iss: "<app_id>" }
using RS256. The emulator verifies the signature and resolves the app.
yaml
github:
  apps:
    - app_id: 12345
      slug: my-github-app
      name: My GitHub App
      private_key: |
        -----BEGIN RSA PRIVATE KEY-----
        ...
        -----END RSA PRIVATE KEY-----
      permissions:
        contents: read
        issues: write
      events: [push, pull_request]
      webhook_url: http://localhost:8080/github/webhook
      webhook_secret: my-webhook-secret
      description: My CI/CD bot
      installations:
        - installation_id: 100
          account: my-org
          repository_selection: all
          permissions:
            contents: read
          events: [push]
          repositories: [my-org/org-repo]
在预置配置中使用私钥配置应用。使用RS256算法签署包含
{ iss: "<app_id>" }
的JWT。模拟器会验证签名并解析应用。
yaml
github:
  apps:
    - app_id: 12345
      slug: my-github-app
      name: My GitHub App
      private_key: |
        -----BEGIN RSA PRIVATE KEY-----
        ...
        -----END RSA PRIVATE KEY-----
      permissions:
        contents: read
        issues: write
      events: [push, pull_request]
      webhook_url: http://localhost:8080/github/webhook
      webhook_secret: my-webhook-secret
      description: My CI/CD bot
      installations:
        - installation_id: 100
          account: my-org
          repository_selection: all
          permissions:
            contents: read
          events: [push]
          repositories: [my-org/org-repo]

Pointing Your App at the Emulator

将你的应用指向模拟器

Environment Variable

环境变量

bash
GITHUB_EMULATOR_URL=http://localhost:4001
bash
GITHUB_EMULATOR_URL=http://localhost:4001

Octokit

Octokit

typescript
import { Octokit } from '@octokit/rest'

const octokit = new Octokit({
  baseUrl: process.env.GITHUB_EMULATOR_URL ?? 'https://api.github.com',
  auth: 'test_token_admin',
})
typescript
import { Octokit } from '@octokit/rest'

const octokit = new Octokit({
  baseUrl: process.env.GITHUB_EMULATOR_URL ?? 'https://api.github.com',
  auth: 'test_token_admin',
})

OAuth URL Mapping

OAuth URL映射

Real GitHub URLEmulator URL
https://github.com/login/oauth/authorize
$GITHUB_EMULATOR_URL/login/oauth/authorize
https://github.com/login/oauth/access_token
$GITHUB_EMULATOR_URL/login/oauth/access_token
https://api.github.com/user
$GITHUB_EMULATOR_URL/user
真实GitHub URL模拟器URL
https://github.com/login/oauth/authorize
$GITHUB_EMULATOR_URL/login/oauth/authorize
https://github.com/login/oauth/access_token
$GITHUB_EMULATOR_URL/login/oauth/access_token
https://api.github.com/user
$GITHUB_EMULATOR_URL/user

Auth.js / NextAuth.js

Auth.js / NextAuth.js

typescript
import GitHub from '@auth/core/providers/github'

GitHub({
  clientId: process.env.GITHUB_CLIENT_ID,
  clientSecret: process.env.GITHUB_CLIENT_SECRET,
  authorization: {
    url: `${process.env.GITHUB_EMULATOR_URL}/login/oauth/authorize`,
  },
  token: {
    url: `${process.env.GITHUB_EMULATOR_URL}/login/oauth/access_token`,
  },
  userinfo: {
    url: `${process.env.GITHUB_EMULATOR_URL}/user`,
  },
})
typescript
import GitHub from '@auth/core/providers/github'

GitHub({
  clientId: process.env.GITHUB_CLIENT_ID,
  clientSecret: process.env.GITHUB_CLIENT_SECRET,
  authorization: {
    url: `${process.env.GITHUB_EMULATOR_URL}/login/oauth/authorize`,
  },
  token: {
    url: `${process.env.GITHUB_EMULATOR_URL}/login/oauth/access_token`,
  },
  userinfo: {
    url: `${process.env.GITHUB_EMULATOR_URL}/user`,
  },
})

Seed Config

预置配置

yaml
tokens:
  test_token_admin:
    login: admin
    scopes: [repo, user, admin:org, admin:repo_hook]

github:
  users:
    - login: octocat
      name: The Octocat
      email: octocat@github.com
      bio: I am the Octocat
      company: GitHub
      location: San Francisco
      blog: https://github.blog
      twitter_username: github
      site_admin: false
  orgs:
    - login: my-org
      name: My Organization
      description: A test organization
      email: org@example.com
  repos:
    - owner: octocat
      name: hello-world
      description: My first repository
      language: JavaScript
      topics: [hello, world]
      default_branch: main
      private: false
    - owner: my-org
      name: org-repo
      description: An organization repository
      language: TypeScript
  oauth_apps:
    - client_id: Iv1.abc123
      client_secret: secret_abc123
      name: My Web App
      redirect_uris:
        - http://localhost:3000/api/auth/callback/github
Repos are auto-initialized with a commit, branch, and README unless
auto_init: false
is set.
yaml
tokens:
  test_token_admin:
    login: admin
    scopes: [repo, user, admin:org, admin:repo_hook]

github:
  users:
    - login: octocat
      name: The Octocat
      email: octocat@github.com
      bio: I am the Octocat
      company: GitHub
      location: San Francisco
      blog: https://github.blog
      twitter_username: github
      site_admin: false
  orgs:
    - login: my-org
      name: My Organization
      description: A test organization
      email: org@example.com
  repos:
    - owner: octocat
      name: hello-world
      description: My first repository
      language: JavaScript
      topics: [hello, world]
      default_branch: main
      private: false
    - owner: my-org
      name: org-repo
      description: An organization repository
      language: TypeScript
  oauth_apps:
    - client_id: Iv1.abc123
      client_secret: secret_abc123
      name: My Web App
      redirect_uris:
        - http://localhost:3000/api/auth/callback/github
除非设置
auto_init: false
,否则仓库会自动初始化提交、分支和README文件。

Pagination

分页

All list endpoints support
page
and
per_page
query params with
Link
headers:
bash
curl "http://localhost:4001/repos/octocat/hello-world/issues?page=1&per_page=10" \
  -H "Authorization: Bearer $TOKEN"
所有列表端点都支持
page
per_page
查询参数,并返回
Link
响应头:
bash
curl "http://localhost:4001/repos/octocat/hello-world/issues?page=1&per_page=10" \
  -H "Authorization: Bearer $TOKEN"

API Endpoints

API端点

Users

用户

bash
undefined
bash
undefined

Authenticated user

已认证用户

curl http://localhost:4001/user -H "Authorization: Bearer $TOKEN"
curl http://localhost:4001/user -H "Authorization: Bearer $TOKEN"

Update profile

更新个人资料

curl -X PATCH http://localhost:4001/user
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"bio": "Hello!"}'
curl -X PATCH http://localhost:4001/user
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"bio": "Hello!"}'

Get user by username

根据用户名获取用户信息

List users

列出所有用户

User repos / orgs / followers / following

用户的仓库/组织/关注者/关注的用户

User hovercard

用户悬浮卡片

User emails

用户邮箱

curl http://localhost:4001/user/emails -H "Authorization: Bearer $TOKEN"
undefined
curl http://localhost:4001/user/emails -H "Authorization: Bearer $TOKEN"
undefined

Repositories

仓库

bash
undefined
bash
undefined

Get repo

获取仓库信息

Create user repo

创建个人仓库

curl -X POST http://localhost:4001/user/repos
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"name": "new-repo", "private": false}'
curl -X POST http://localhost:4001/user/repos
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"name": "new-repo", "private": false}'

Create org repo

创建组织仓库

curl -X POST http://localhost:4001/orgs/my-org/repos
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"name": "org-project"}'
curl -X POST http://localhost:4001/orgs/my-org/repos
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"name": "org-project"}'

Update repo

更新仓库信息

curl -X PATCH http://localhost:4001/repos/octocat/hello-world
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"description": "Updated description"}'
curl -X PATCH http://localhost:4001/repos/octocat/hello-world
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"description": "Updated description"}'

Delete repo (cascades issues, PRs, etc.)

删除仓库(会级联删除议题、PR等)

curl -X DELETE http://localhost:4001/repos/octocat/hello-world
-H "Authorization: Bearer $TOKEN"
curl -X DELETE http://localhost:4001/repos/octocat/hello-world
-H "Authorization: Bearer $TOKEN"

Topics, languages, contributors, forks, collaborators, tags, transfer

主题、语言、贡献者、复刻、协作者、标签、转移

undefined
undefined

Issues

议题

bash
undefined
bash
undefined

List issues (filter by state, labels, assignee, milestone, creator, since)

列出议题(可按状态、标签、经办人、里程碑、创建者、时间过滤)

Create issue

创建议题

curl -X POST http://localhost:4001/repos/octocat/hello-world/issues
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"title": "Bug report", "body": "Details here", "labels": ["bug"]}'
curl -X POST http://localhost:4001/repos/octocat/hello-world/issues
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"title": "Bug report", "body": "Details here", "labels": ["bug"]}'

Get / update / lock / unlock / timeline / events / assignees

获取/更新/锁定/解锁/时间线/事件/经办人

undefined
undefined

Pull Requests

拉取请求(PR)

bash
undefined
bash
undefined

List PRs

列出PR

Create PR

创建PR

curl -X POST http://localhost:4001/repos/octocat/hello-world/pulls
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"title": "Feature", "head": "feature-branch", "base": "main"}'
curl -X POST http://localhost:4001/repos/octocat/hello-world/pulls
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"title": "Feature", "head": "feature-branch", "base": "main"}'

Merge PR (enforces branch protection)

合并PR(遵循分支保护规则)

curl -X PUT http://localhost:4001/repos/octocat/hello-world/pulls/1/merge
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"merge_method": "squash"}'
curl -X PUT http://localhost:4001/repos/octocat/hello-world/pulls/1/merge
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"merge_method": "squash"}'

Commits, files, requested reviewers, update branch

提交记录、文件、请求的审阅者、更新分支

undefined
undefined

Comments

评论

bash
undefined
bash
undefined

Issue comments: full CRUD

议题评论:完整的增删改查

curl http://localhost:4001/repos/octocat/hello-world/issues/1/comments curl -X POST http://localhost:4001/repos/octocat/hello-world/issues/1/comments
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"body": "Looks good!"}'
curl http://localhost:4001/repos/octocat/hello-world/issues/1/comments curl -X POST http://localhost:4001/repos/octocat/hello-world/issues/1/comments
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"body": "Looks good!"}'

Comment by ID (cross-resource)

根据ID获取评论(跨资源)

PR review comments

PR审阅评论

Commit comments

提交评论

Repo-wide comment listings

仓库范围的评论列表

Reviews

审阅

bash
undefined
bash
undefined

List / create / get / update / submit / dismiss reviews

列出/创建/获取/更新/提交/驳回审阅

curl http://localhost:4001/repos/octocat/hello-world/pulls/1/reviews curl -X POST http://localhost:4001/repos/octocat/hello-world/pulls/1/reviews
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"event": "APPROVE", "body": "LGTM"}'
undefined
curl http://localhost:4001/repos/octocat/hello-world/pulls/1/reviews curl -X POST http://localhost:4001/repos/octocat/hello-world/pulls/1/reviews
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"event": "APPROVE", "body": "LGTM"}'
undefined

Labels & Milestones

标签与里程碑

Full CRUD for labels and milestones. Add/remove labels from issues, replace all labels. List labels for a milestone.
支持标签和里程碑的完整增删改查操作。可向议题添加/移除标签、替换所有标签。列出里程碑关联的标签。

Branches & Git Data

分支与Git数据

bash
undefined
bash
undefined

List branches

列出分支

Branch protection CRUD (status checks, PR reviews, enforce admins)

分支保护增删改查(状态检查、PR审阅、管理员强制规则)

curl -X PUT http://localhost:4001/repos/octocat/hello-world/branches/main/protection
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"required_status_checks": {"strict": true, "contexts": ["ci"]}}'
curl -X PUT http://localhost:4001/repos/octocat/hello-world/branches/main/protection
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"required_status_checks": {"strict": true, "contexts": ["ci"]}}'

Refs, commits, trees (recursive), blobs, tags, matching-refs

引用、提交记录、树(递归)、 blob、标签、匹配引用

undefined
undefined

Organizations & Teams

组织与团队

bash
undefined
bash
undefined

List all orgs / user's orgs / get org / update org

列出所有组织/用户所属组织/获取组织信息/更新组织信息

curl http://localhost:4001/organizations curl http://localhost:4001/user/orgs -H "Authorization: Bearer $TOKEN" curl http://localhost:4001/orgs/my-org curl -X PATCH http://localhost:4001/orgs/my-org
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"description": "Updated org"}'
curl http://localhost:4001/organizations curl http://localhost:4001/user/orgs -H "Authorization: Bearer $TOKEN" curl http://localhost:4001/orgs/my-org curl -X PATCH http://localhost:4001/orgs/my-org
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"description": "Updated org"}'

Org members: list, get, remove

组织成员:列出、获取、移除

Org memberships: get, set (invite/update role)

组织成员身份:获取、设置(邀请/更新角色)

curl http://localhost:4001/orgs/my-org/memberships/octocat -H "Authorization: Bearer $TOKEN" curl -X PUT http://localhost:4001/orgs/my-org/memberships/octocat
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"role": "admin"}'
curl http://localhost:4001/orgs/my-org/memberships/octocat -H "Authorization: Bearer $TOKEN" curl -X PUT http://localhost:4001/orgs/my-org/memberships/octocat
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"role": "admin"}'

Teams: CRUD

团队:增删改查

curl http://localhost:4001/orgs/my-org/teams curl -X POST http://localhost:4001/orgs/my-org/teams
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"name": "engineering", "privacy": "closed"}'
curl http://localhost:4001/orgs/my-org/teams curl -X POST http://localhost:4001/orgs/my-org/teams
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"name": "engineering", "privacy": "closed"}'

Team members and memberships

团队成员与成员身份

curl http://localhost:4001/orgs/my-org/teams/engineering/members curl -X PUT http://localhost:4001/orgs/my-org/teams/engineering/memberships/octocat
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"role": "maintainer"}'
curl http://localhost:4001/orgs/my-org/teams/engineering/members curl -X PUT http://localhost:4001/orgs/my-org/teams/engineering/memberships/octocat
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"role": "maintainer"}'

Team repos: list, add, remove

团队仓库:列出、添加、移除

Legacy team endpoints by ID

通过ID访问的旧版团队端点

GitHub Apps

GitHub Apps

bash
undefined
bash
undefined

Get authenticated app (requires JWT auth)

获取已认证应用(需要JWT身份验证)

curl http://localhost:4001/app
-H "Authorization: Bearer <jwt>"
curl http://localhost:4001/app
-H "Authorization: Bearer <jwt>"

List app installations

列出应用安装实例

curl http://localhost:4001/app/installations
-H "Authorization: Bearer <jwt>"
curl http://localhost:4001/app/installations
-H "Authorization: Bearer <jwt>"

Get installation

获取安装实例信息

curl http://localhost:4001/app/installations/100
-H "Authorization: Bearer <jwt>"
curl http://localhost:4001/app/installations/100
-H "Authorization: Bearer <jwt>"

Create installation access token (mints ghs_... token)

创建安装访问令牌(生成ghs_...格式令牌)

curl -X POST http://localhost:4001/app/installations/100/access_tokens
-H "Authorization: Bearer <jwt>"
-H "Content-Type: application/json"
-d '{"permissions": {"contents": "read"}}'
curl -X POST http://localhost:4001/app/installations/100/access_tokens
-H "Authorization: Bearer <jwt>"
-H "Content-Type: application/json"
-d '{"permissions": {"contents": "read"}}'

Find installation for repo / org / user

根据仓库/组织/用户查找安装实例


App webhook delivery: when events occur, the emulator POSTs `event_callback` payloads to configured `webhook_url` with `X-GitHub-Event` and `X-Hub-Signature-256` headers.

应用Webhook交付:当事件发生时,模拟器会将`event_callback`负载POST到配置的`webhook_url`,并携带`X-GitHub-Event`和`X-Hub-Signature-256`请求头。

Releases

发布

bash
undefined
bash
undefined

Create release

创建发布

curl -X POST http://localhost:4001/repos/octocat/hello-world/releases
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"tag_name": "v1.0.0", "name": "v1.0.0"}'
curl -X POST http://localhost:4001/repos/octocat/hello-world/releases
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"tag_name": "v1.0.0", "name": "v1.0.0"}'

List, get, latest, by tag, generate notes

列出、获取、最新版本、按标签查找、生成发布说明

Release assets: list, upload

发布资产:列出、上传

curl http://localhost:4001/repos/octocat/hello-world/releases/1/assets curl -X POST http://localhost:4001/repos/octocat/hello-world/releases/1/assets
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/octet-stream"
-H "name: binary.zip"
--data-binary @binary.zip
undefined
curl http://localhost:4001/repos/octocat/hello-world/releases/1/assets curl -X POST http://localhost:4001/repos/octocat/hello-world/releases/1/assets
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/octet-stream"
-H "name: binary.zip"
--data-binary @binary.zip
undefined

Webhooks

Webhook

bash
undefined
bash
undefined

Create webhook (real HTTP delivery on state changes)

创建Webhook(状态变化时会触发真实HTTP交付)

curl -X POST http://localhost:4001/repos/octocat/hello-world/hooks
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"config": {"url": "http://localhost:8080/webhook"}, "events": ["push", "pull_request"]}'
curl -X POST http://localhost:4001/repos/octocat/hello-world/hooks
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"config": {"url": "http://localhost:8080/webhook"}, "events": ["push", "pull_request"]}'

Full CRUD, ping, test, deliveries

完整增删改查、 ping、测试、交付记录

Org webhooks also supported

同时支持组织Webhook

undefined
undefined

Search

搜索

bash
undefined
bash
undefined

Search repositories

搜索仓库

Search issues and PRs

搜索议题和PR

Search users, code, commits, topics, labels

搜索用户、代码、提交记录、主题、标签

undefined
undefined

Actions

Actions

bash
undefined
bash
undefined

Workflows: list, get, enable/disable, dispatch

工作流:列出、获取、启用/禁用、触发

Workflow runs: list, get, cancel, rerun, delete, logs

工作流运行:列出、获取、取消、重新运行、删除、日志

Jobs: list, get, logs

任务:列出、获取、日志

Artifacts: list, get, delete

制品:列出、获取、删除

Secrets: repo + org CRUD

密钥:仓库和组织级别的增删改查

undefined
undefined

Checks

Checks

bash
undefined
bash
undefined

Create check run

创建检查运行

curl -X POST http://localhost:4001/repos/octocat/hello-world/check-runs
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"name": "CI", "head_sha": "abc123", "status": "completed", "conclusion": "success"}'
curl -X POST http://localhost:4001/repos/octocat/hello-world/check-runs
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"name": "CI", "head_sha": "abc123", "status": "completed", "conclusion": "success"}'

Check suites: create, get, rerequest, preferences, list by ref

检查套件:创建、获取、重新请求、偏好设置、按引用列出

Check runs: list for suite, annotations

检查运行:列出套件下的运行、注释

Automatic suite status rollup from check run results

自动根据检查运行结果汇总套件状态

undefined
undefined

OAuth

OAuth

bash
undefined
bash
undefined

Authorize (browser flow, shows user picker)

授权(浏览器流程,显示用户选择器)

GET /login/oauth/authorize?client_id=...&redirect_uri=...&scope=...&state=...

GET /login/oauth/authorize?client_id=...&redirect_uri=...&scope=...&state=...

Token exchange

令牌交换

curl -X POST http://localhost:4001/login/oauth/access_token
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{"client_id": "Iv1.abc123", "client_secret": "secret_abc123", "code": "<code>"}'
curl -X POST http://localhost:4001/login/oauth/access_token
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{"client_id": "Iv1.abc123", "client_secret": "secret_abc123", "code": "<code>"}'

User emails

用户邮箱

curl http://localhost:4001/user/emails -H "Authorization: Bearer $TOKEN"
curl http://localhost:4001/user/emails -H "Authorization: Bearer $TOKEN"

OAuth app management (settings)

OAuth应用管理(设置)

curl http://localhost:4001/settings/applications -H "Authorization: Bearer $TOKEN" curl http://localhost:4001/settings/connections/applications/Iv1.abc123 -H "Authorization: Bearer $TOKEN"
curl http://localhost:4001/settings/applications -H "Authorization: Bearer $TOKEN" curl http://localhost:4001/settings/connections/applications/Iv1.abc123 -H "Authorization: Bearer $TOKEN"

Revoke OAuth app

撤销OAuth应用授权

undefined
undefined

Misc

其他

bash
curl http://localhost:4001/rate_limit
curl http://localhost:4001/meta
curl http://localhost:4001/emojis
curl http://localhost:4001/versions
curl http://localhost:4001/octocat
curl http://localhost:4001/zen
bash
curl http://localhost:4001/rate_limit
curl http://localhost:4001/meta
curl http://localhost:4001/emojis
curl http://localhost:4001/versions
curl http://localhost:4001/octocat
curl http://localhost:4001/zen

Common Patterns

常见模式

Create Repo, Issue, and PR

创建仓库、议题和PR

bash
TOKEN="test_token_admin"
BASE="http://localhost:4001"
bash
TOKEN="test_token_admin"
BASE="http://localhost:4001"

Create repo

创建仓库

curl -X POST $BASE/user/repos
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"name": "my-project"}'
curl -X POST $BASE/user/repos
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"name": "my-project"}'

Create issue

创建议题

curl -X POST $BASE/repos/admin/my-project/issues
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"title": "First issue"}'
curl -X POST $BASE/repos/admin/my-project/issues
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"title": "First issue"}'

Create PR

创建PR

curl -X POST $BASE/repos/admin/my-project/pulls
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"title": "First PR", "head": "feature", "base": "main"}'
undefined
curl -X POST $BASE/repos/admin/my-project/pulls
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"title": "First PR", "head": "feature", "base": "main"}'
undefined

GitHub App Installation Token Flow

GitHub App安装令牌流程

bash
undefined
bash
undefined

1. Sign a JWT with { iss: "12345" } using the app's private key (RS256)

1. 使用应用私钥(RS256算法)签署包含 { iss: "12345" } 的JWT

2. Create an installation access token

2. 创建安装访问令牌

curl -X POST $BASE/app/installations/100/access_tokens
-H "Authorization: Bearer <jwt>"
-H "Content-Type: application/json"
-d '{"permissions": {"contents": "read", "issues": "write"}}'
curl -X POST $BASE/app/installations/100/access_tokens
-H "Authorization: Bearer <jwt>"
-H "Content-Type: application/json"
-d '{"permissions": {"contents": "read", "issues": "write"}}'

Returns { "token": "ghs_...", ... }

返回 { "token": "ghs_...", ... }

3. Use the installation token to call API endpoints

3. 使用安装令牌调用API端点

curl $BASE/repos/my-org/org-repo
-H "Authorization: Bearer ghs_..."
undefined
curl $BASE/repos/my-org/org-repo
-H "Authorization: Bearer ghs_..."
undefined

OAuth Flow

OAuth流程

  1. Redirect user to
    $GITHUB_EMULATOR_URL/login/oauth/authorize?client_id=...&redirect_uri=...&scope=user+repo&state=...
  2. User picks a seeded user on the emulator's UI
  3. Emulator redirects back with
    ?code=...&state=...
  4. Exchange code for token via
    POST /login/oauth/access_token
  5. Use token to call API endpoints
  1. 将用户重定向到
    $GITHUB_EMULATOR_URL/login/oauth/authorize?client_id=...&redirect_uri=...&scope=user+repo&state=...
  2. 用户在模拟器UI中选择一个预置用户
  3. 模拟器重定向回应用,并携带
    ?code=...&state=...
    参数
  4. 通过
    POST /login/oauth/access_token
    交换令牌
  5. 使用令牌调用API端点