
@octokit/rest
最初不是GitHub的原始开发版,并且是github的改编版-github-用户2017年最受欢迎的软件包@bkeepers。在这篇文章中,我们将讨论@octokit/rest
-现在是GitHub REST API的官方JavaScript SDK 。
Gregor(本文的作者)是Octokit JavaScript开发人员。他是一位经验丰富的开源开发人员,对任务自动化有特殊的需求,并降低了各种类型和专业人士的入门门槛。除了Octokit之外,Gregor还致力于Probot,nock和语义发布。在业余时间,他会照顾他的三胞胎Nico,Ada和Kiana。可以在DEV社区和Twitter上找到更多Gregor资料。
遗产
@octokit/rest
, github
Node. 2010 . Node v0.1, package.json , npm .
2017 GitHub , github
GitHub API JavaScript SDK Node.js. 2017 . 16 , JavaScript , JSON TypeScript/Flow.
➜ rest.js git:(50720c8) wc -l lib/*
120 lib/error.js
3246 lib/index.d.ts
905 lib/index.js
3232 lib/index.js.flow
17 lib/promise.js
7995 lib/routes.json
143 lib/util.js
15658 total
. routes.json 8 , REST API GitHub. , / .
, (octokit/routes) REST API GitHub JSON. routes.json. , @octokit/rest
PR routes.json, . , routes.json REST API GitHub 10 275 . TypeScript 26 700 .
API , : .
. : "decomposability", "", . " ", " " "".
JavaScript Octokit JavaScript, . , . , , REST API, ( ""), . , .
, 2018 :

:
,
➜ rest.js git:(f7c9f86) wc -l index.* lib/**/*.{js,json}
31 index.js
3474 index.d.ts
3441 index.js.flow
101 lib/endpoint/ # 4 files
162 lib/request/ # 3 files
83 lib/plugins/authentication/ # 3 files
130 lib/plugins/endpoint-methods/ # 4 files
130 lib/plugins/pagination/ # 11 files
58 lib/parse-client-options.js
10628 lib/routes.json
18238 total
:
2018 , , v16 API . , .
:
,
➜ rest.js git:(01763bf) wc -l index.* plugins/**/*.{js,json} lib/**/*.js
14 index.js
26714 index.d.ts
110 lib/ # 6 files
86 plugins/authentication/ # 3 files
77 plugins/pagination/ # 3 files
39 plugins/register-endpoints/ # 3 files
108 plugins/validate/ # 2 files
10275 plugins/rest-api-endpoints/routes.json
37423 total
@octokit/core
— Octokit JavaScript, @octokit/rest
Octokit. @octokit/rest
. @octokit/rest
, .
@octokit/core
legacy , . — README @octokit/auth
. GitHub, (eng).
@octokit/core
lib/* plugins/authentication/*
. , :
validate
TypeScript . . , octokit.checks.create()
:
{
checks: {
create: {
headers: { accept: "application/vnd.github.antiope-preview+json" },
method: "POST",
params: {
actions: { type: "object[]" },
"actions[].description": { required: true, type: "string" },
"actions[].identifier": { required: true, type: "string" },
"actions[].label": { required: true, type: "string" },
completed_at: { type: "string" },
conclusion: {
enum: [
"success",
"failure",
"neutral",
"cancelled",
"timed_out",
"action_required"
],
type: "string"
},
details_url: { type: "string" },
external_id: { type: "string" },
head_sha: { required: true, type: "string" },
name: { required: true, type: "string" },
output: { type: "object" },
"output.annotations": { type: "object[]" },
"output.annotations[].annotation_level": {
enum: ["notice", "warning", "failure"],
required: true,
type: "string"
},
"output.annotations[].end_column": { type: "integer" },
"output.annotations[].end_line": { required: true, type: "integer" },
"output.annotations[].message": { required: true, type: "string" },
"output.annotations[].path": { required: true, type: "string" },
"output.annotations[].raw_details": { type: "string" },
"output.annotations[].start_column": { type: "integer" },
"output.annotations[].start_line": { required: true, type: "integer" },
"output.annotations[].title": { type: "string" },
"output.images": { type: "object[]" },
"output.images[].alt": { required: true, type: "string" },
"output.images[].caption": { type: "string" },
"output.images[].image_url": { required: true, type: "string" },
"output.summary": { required: true, type: "string" },
"output.text": { type: "string" },
"output.title": { required: true, type: "string" },
owner: { required: true, type: "string" },
repo: { required: true, type: "string" },
started_at: { type: "string" },
status: { enum: ["queued", "in_progress", "completed"], type: "string" }
},
url: "/repos/:owner/:repo/check-runs"
}
}
}
v17, :
{
checks: {
create: [
"POST /repos/{owner}/{repo}/check-runs",
{ mediaType: { previews: ["antiope"] } },
];
}
}
, 10 :
import { Octokit as Core } from "@octokit/core";
import { requestLog } from "@octokit/plugin-request-log";
import { paginateRest } from "@octokit/plugin-paginate-rest";
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
import { VERSION } from "./version";
export const Octokit = Core.plugin([
requestLog,
paginateRest,
restEndpointMethods,
]).defaults({ userAgent: `octokit-rest.js/${VERSION}` });
v16 v17, — .
2017 , . , JavaScript Octokit SDK SDK , octokit/fixtures
— , http .
, @octokit/rest
, 100% . , 100% .
. : ,
v17 10 , v16, API. , , v17, @octokit/rest
. , @octokit/core
@octokit/request
. smoke- @octokit/fixtures
.
@octokit/rest
REST API GitHub, 17 , JavaScript, API @octokit/rest
, , . GraphQL, @octokit/core
.
最后,我要感谢Fabian Jacobs,Mike de Boer和Joe Gallo,他们在模块github
变成之前创建并维护了该模块@octokit/rest
。