48 a 10 linhas de código - história do SDK JavaScript do GitHub


@octokit/restoriginalmente não é um desenvolvimento original do GitHub, e é uma adaptação do github - o pacote mais popular de 2017 do usuário @bkeepers . Neste post, falaremos sobre @octokit/rest- agora o SDK JavaScript oficial para a API REST do GitHub .


( ) JavaScript Octokit. open source , . Octokit, Probot, nock semantic-release. , . DEV community Twitter.

legacy


@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.


No final, gostaria de agradecer a Fabian Jacobs , Mike de Boer e Joe Gallo , que criaram e mantiveram o módulo githubantes de ele se transformar @octokit/rest.


All Articles