Add js_action.yaml
This commit is contained in:
Generated
Executable
+7
@@ -0,0 +1,7 @@
|
||||
MIT License Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
Generated
Executable
+76
@@ -0,0 +1,76 @@
|
||||
# plugin-rest-endpoint-methods.js
|
||||
|
||||
> Octokit plugin adding one method for all of api.github.com REST API endpoints
|
||||
|
||||
[](https://www.npmjs.com/package/@octokit/plugin-rest-endpoint-methods)
|
||||
[](https://github.com/octokit/plugin-rest-endpoint-methods.js/actions?workflow=Test)
|
||||
|
||||
## Usage
|
||||
|
||||
<table>
|
||||
<tbody valign=top align=left>
|
||||
<tr><th>
|
||||
Browsers
|
||||
</th><td width=100%>
|
||||
|
||||
Load `@octokit/plugin-rest-endpoint-methods` and [`@octokit/core`](https://github.com/octokit/core.js) (or core-compatible module) directly from [esm.sh](https://esm.sh)
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import { Octokit } from "https://esm.sh/@octokit/core";
|
||||
import { restEndpointMethods } from "https://esm.sh/@octokit/plugin-rest-endpoint-methods";
|
||||
</script>
|
||||
```
|
||||
|
||||
</td></tr>
|
||||
<tr><th>
|
||||
Node
|
||||
</th><td>
|
||||
|
||||
Install with `npm install @octokit/core @octokit/plugin-rest-endpoint-methods`. Optionally replace `@octokit/core` with a compatible module
|
||||
|
||||
```js
|
||||
const { Octokit } = require("@octokit/core");
|
||||
const {
|
||||
restEndpointMethods,
|
||||
} = require("@octokit/plugin-rest-endpoint-methods");
|
||||
```
|
||||
|
||||
</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
```js
|
||||
const MyOctokit = Octokit.plugin(restEndpointMethods);
|
||||
const octokit = new MyOctokit({ auth: "secret123" });
|
||||
|
||||
// https://developer.github.com/v3/users/#get-the-authenticated-user
|
||||
octokit.rest.users.getAuthenticated();
|
||||
```
|
||||
|
||||
There is one method for each REST API endpoint documented at [https://developer.github.com/v3](https://developer.github.com/v3). All endpoint methods are documented in the [docs/](docs/) folder, e.g. [docs/users/getAuthenticated.md](docs/users/getAuthenticated.md)
|
||||
|
||||
## TypeScript
|
||||
|
||||
Parameter and response types for all endpoint methods exported as `{ RestEndpointMethodTypes }`.
|
||||
|
||||
Example
|
||||
|
||||
```ts
|
||||
import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods";
|
||||
|
||||
type UpdateLabelParameters =
|
||||
RestEndpointMethodTypes["issues"]["updateLabel"]["parameters"];
|
||||
type UpdateLabelResponse =
|
||||
RestEndpointMethodTypes["issues"]["updateLabel"]["response"];
|
||||
```
|
||||
|
||||
In order to get types beyond parameters and responses, check out [`@octokit/openapi-types`](https://github.com/octokit/openapi-types.ts/#readme), which is a direct transpilation from GitHub's official OpenAPI specification.
|
||||
|
||||
## Contributing
|
||||
|
||||
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
Generated
Executable
+2106
File diff suppressed because it is too large
Load Diff
Generated
Executable
+7
File diff suppressed because one or more lines are too long
Generated
Executable
+125
@@ -0,0 +1,125 @@
|
||||
import ENDPOINTS from "./generated/endpoints.js";
|
||||
const endpointMethodsMap = /* @__PURE__ */ new Map();
|
||||
for (const [scope, endpoints] of Object.entries(ENDPOINTS)) {
|
||||
for (const [methodName, endpoint] of Object.entries(endpoints)) {
|
||||
const [route, defaults, decorations] = endpoint;
|
||||
const [method, url] = route.split(/ /);
|
||||
const endpointDefaults = Object.assign(
|
||||
{
|
||||
method,
|
||||
url
|
||||
},
|
||||
defaults
|
||||
);
|
||||
if (!endpointMethodsMap.has(scope)) {
|
||||
endpointMethodsMap.set(scope, /* @__PURE__ */ new Map());
|
||||
}
|
||||
endpointMethodsMap.get(scope).set(methodName, {
|
||||
scope,
|
||||
methodName,
|
||||
endpointDefaults,
|
||||
decorations
|
||||
});
|
||||
}
|
||||
}
|
||||
const handler = {
|
||||
has({ scope }, methodName) {
|
||||
return endpointMethodsMap.get(scope).has(methodName);
|
||||
},
|
||||
getOwnPropertyDescriptor(target, methodName) {
|
||||
return {
|
||||
value: this.get(target, methodName),
|
||||
// ensures method is in the cache
|
||||
configurable: true,
|
||||
writable: true,
|
||||
enumerable: true
|
||||
};
|
||||
},
|
||||
defineProperty(target, methodName, descriptor) {
|
||||
Object.defineProperty(target.cache, methodName, descriptor);
|
||||
return true;
|
||||
},
|
||||
deleteProperty(target, methodName) {
|
||||
delete target.cache[methodName];
|
||||
return true;
|
||||
},
|
||||
ownKeys({ scope }) {
|
||||
return [...endpointMethodsMap.get(scope).keys()];
|
||||
},
|
||||
set(target, methodName, value) {
|
||||
return target.cache[methodName] = value;
|
||||
},
|
||||
get({ octokit, scope, cache }, methodName) {
|
||||
if (cache[methodName]) {
|
||||
return cache[methodName];
|
||||
}
|
||||
const method = endpointMethodsMap.get(scope).get(methodName);
|
||||
if (!method) {
|
||||
return void 0;
|
||||
}
|
||||
const { endpointDefaults, decorations } = method;
|
||||
if (decorations) {
|
||||
cache[methodName] = decorate(
|
||||
octokit,
|
||||
scope,
|
||||
methodName,
|
||||
endpointDefaults,
|
||||
decorations
|
||||
);
|
||||
} else {
|
||||
cache[methodName] = octokit.request.defaults(endpointDefaults);
|
||||
}
|
||||
return cache[methodName];
|
||||
}
|
||||
};
|
||||
function endpointsToMethods(octokit) {
|
||||
const newMethods = {};
|
||||
for (const scope of endpointMethodsMap.keys()) {
|
||||
newMethods[scope] = new Proxy({ octokit, scope, cache: {} }, handler);
|
||||
}
|
||||
return newMethods;
|
||||
}
|
||||
function decorate(octokit, scope, methodName, defaults, decorations) {
|
||||
const requestWithDefaults = octokit.request.defaults(defaults);
|
||||
function withDecorations(...args) {
|
||||
let options = requestWithDefaults.endpoint.merge(...args);
|
||||
if (decorations.mapToData) {
|
||||
options = Object.assign({}, options, {
|
||||
data: options[decorations.mapToData],
|
||||
[decorations.mapToData]: void 0
|
||||
});
|
||||
return requestWithDefaults(options);
|
||||
}
|
||||
if (decorations.renamed) {
|
||||
const [newScope, newMethodName] = decorations.renamed;
|
||||
octokit.log.warn(
|
||||
`octokit.${scope}.${methodName}() has been renamed to octokit.${newScope}.${newMethodName}()`
|
||||
);
|
||||
}
|
||||
if (decorations.deprecated) {
|
||||
octokit.log.warn(decorations.deprecated);
|
||||
}
|
||||
if (decorations.renamedParameters) {
|
||||
const options2 = requestWithDefaults.endpoint.merge(...args);
|
||||
for (const [name, alias] of Object.entries(
|
||||
decorations.renamedParameters
|
||||
)) {
|
||||
if (name in options2) {
|
||||
octokit.log.warn(
|
||||
`"${name}" parameter is deprecated for "octokit.${scope}.${methodName}()". Use "${alias}" instead`
|
||||
);
|
||||
if (!(alias in options2)) {
|
||||
options2[alias] = options2[name];
|
||||
}
|
||||
delete options2[name];
|
||||
}
|
||||
}
|
||||
return requestWithDefaults(options2);
|
||||
}
|
||||
return requestWithDefaults(...args);
|
||||
}
|
||||
return Object.assign(withDecorations, requestWithDefaults);
|
||||
}
|
||||
export {
|
||||
endpointsToMethods
|
||||
};
|
||||
Generated
Executable
+1933
File diff suppressed because it is too large
Load Diff
Generated
Executable
Generated
Executable
Generated
Executable
+21
@@ -0,0 +1,21 @@
|
||||
import { VERSION } from "./version.js";
|
||||
import { endpointsToMethods } from "./endpoints-to-methods.js";
|
||||
function restEndpointMethods(octokit) {
|
||||
const api = endpointsToMethods(octokit);
|
||||
return {
|
||||
rest: api
|
||||
};
|
||||
}
|
||||
restEndpointMethods.VERSION = VERSION;
|
||||
function legacyRestEndpointMethods(octokit) {
|
||||
const api = endpointsToMethods(octokit);
|
||||
return {
|
||||
...api,
|
||||
rest: api
|
||||
};
|
||||
}
|
||||
legacyRestEndpointMethods.VERSION = VERSION;
|
||||
export {
|
||||
legacyRestEndpointMethods,
|
||||
restEndpointMethods
|
||||
};
|
||||
Generated
Executable
+4
@@ -0,0 +1,4 @@
|
||||
const VERSION = "10.2.0";
|
||||
export {
|
||||
VERSION
|
||||
};
|
||||
Generated
Executable
+3
@@ -0,0 +1,3 @@
|
||||
import type { Octokit } from "@octokit/core";
|
||||
import type { RestEndpointMethods } from "./generated/method-types.js";
|
||||
export declare function endpointsToMethods(octokit: Octokit): RestEndpointMethods;
|
||||
Generated
Executable
+3
@@ -0,0 +1,3 @@
|
||||
import type { EndpointsDefaultsAndDecorations } from "../types.js";
|
||||
declare const Endpoints: EndpointsDefaultsAndDecorations;
|
||||
export default Endpoints;
|
||||
Generated
Executable
+11454
File diff suppressed because it is too large
Load Diff
Generated
Executable
+3645
File diff suppressed because it is too large
Load Diff
Generated
Executable
+11
@@ -0,0 +1,11 @@
|
||||
import type { Octokit } from "@octokit/core";
|
||||
export type { RestEndpointMethodTypes } from "./generated/parameters-and-response-types.js";
|
||||
import type { Api } from "./types.js";
|
||||
export declare function restEndpointMethods(octokit: Octokit): Api;
|
||||
export declare namespace restEndpointMethods {
|
||||
var VERSION: string;
|
||||
}
|
||||
export declare function legacyRestEndpointMethods(octokit: Octokit): Api["rest"] & Api;
|
||||
export declare namespace legacyRestEndpointMethods {
|
||||
var VERSION: string;
|
||||
}
|
||||
Generated
Executable
+18
@@ -0,0 +1,18 @@
|
||||
import type { Route, RequestParameters } from "@octokit/types";
|
||||
import type { RestEndpointMethods } from "./generated/method-types.js";
|
||||
export type Api = {
|
||||
rest: RestEndpointMethods;
|
||||
};
|
||||
export type EndpointDecorations = {
|
||||
mapToData?: string;
|
||||
deprecated?: string;
|
||||
renamed?: [string, string];
|
||||
renamedParameters?: {
|
||||
[name: string]: string;
|
||||
};
|
||||
};
|
||||
export type EndpointsDefaultsAndDecorations = {
|
||||
[scope: string]: {
|
||||
[methodName: string]: [Route, RequestParameters?, EndpointDecorations?];
|
||||
};
|
||||
};
|
||||
Generated
Executable
+1
@@ -0,0 +1 @@
|
||||
export declare const VERSION = "10.2.0";
|
||||
Generated
Executable
+2078
File diff suppressed because it is too large
Load Diff
Generated
Executable
+7
File diff suppressed because one or more lines are too long
Generated
Executable
+60
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"name": "@octokit/plugin-rest-endpoint-methods",
|
||||
"version": "10.2.0",
|
||||
"description": "Octokit plugin adding one method for all of api.github.com REST API endpoints",
|
||||
"repository": "github:octokit/plugin-rest-endpoint-methods.js",
|
||||
"keywords": [
|
||||
"github",
|
||||
"api",
|
||||
"sdk",
|
||||
"toolkit"
|
||||
],
|
||||
"author": "Gregor Martynus (https://twitter.com/gr2m)",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/types": "^12.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@octokit/core": "^5.0.0",
|
||||
"@octokit/tsconfig": "^2.0.0",
|
||||
"@types/fetch-mock": "^7.3.1",
|
||||
"@types/jest": "^29.0.0",
|
||||
"@types/node": "^20.0.0",
|
||||
"@types/sinon": "^17.0.0",
|
||||
"esbuild": "^0.19.0",
|
||||
"fetch-mock": "npm:@gr2m/fetch-mock@^9.11.0-pull-request-644.1",
|
||||
"github-openapi-graphql-query": "^4.0.0",
|
||||
"glob": "^10.2.6",
|
||||
"jest": "^29.0.0",
|
||||
"lodash.camelcase": "^4.3.0",
|
||||
"lodash.set": "^4.3.2",
|
||||
"lodash.upperfirst": "^4.3.1",
|
||||
"mustache": "^4.0.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "3.1.0",
|
||||
"semantic-release-plugin-update-version-in-files": "^1.0.0",
|
||||
"sinon": "^17.0.0",
|
||||
"sort-keys": "^5.0.0",
|
||||
"string-to-jsdoc-comment": "^1.0.0",
|
||||
"ts-jest": "^29.0.0",
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@octokit/core": ">=5"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
},
|
||||
"files": [
|
||||
"dist-*/**",
|
||||
"bin/**"
|
||||
],
|
||||
"main": "dist-node/index.js",
|
||||
"browser": "dist-web/index.js",
|
||||
"types": "dist-types/index.d.ts",
|
||||
"module": "dist-src/index.js",
|
||||
"sideEffects": false
|
||||
}
|
||||
Reference in New Issue
Block a user