mirror of
https://github.com/actions/hello-world-javascript-action.git
synced 2025-12-16 15:19:19 +00:00
Update packages, change to node16
This commit is contained in:
111
node_modules/@octokit/request/README.md
generated
vendored
111
node_modules/@octokit/request/README.md
generated
vendored
@@ -3,8 +3,7 @@
|
||||
> Send parameterized requests to GitHub’s APIs with sensible defaults in browsers and Node
|
||||
|
||||
[](https://www.npmjs.com/package/@octokit/request)
|
||||
[](https://travis-ci.org/octokit/request.js)
|
||||
[](https://greenkeeper.io/)
|
||||
[](https://github.com/octokit/request.js/actions?query=workflow%3ATest+branch%3Amaster)
|
||||
|
||||
`@octokit/request` is a request library for browsers & node that makes it easier
|
||||
to interact with [GitHub’s REST API](https://developer.github.com/v3/) and
|
||||
@@ -23,6 +22,7 @@ the passed options and sends the request using [fetch](https://developer.mozilla
|
||||
- [REST API example](#rest-api-example)
|
||||
- [GraphQL example](#graphql-example)
|
||||
- [Alternative: pass `method` & `url` as part of options](#alternative-pass-method--url-as-part-of-options)
|
||||
- [Authentication](#authentication)
|
||||
- [request()](#request)
|
||||
- [`request.defaults()`](#requestdefaults)
|
||||
- [`request.endpoint`](#requestendpoint)
|
||||
@@ -38,14 +38,14 @@ the passed options and sends the request using [fetch](https://developer.mozilla
|
||||
🤩 1:1 mapping of REST API endpoint documentation, e.g. [Add labels to an issue](https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue) becomes
|
||||
|
||||
```js
|
||||
request("POST /repos/:owner/:repo/issues/:number/labels", {
|
||||
request("POST /repos/{owner}/{repo}/issues/{number}/labels", {
|
||||
mediaType: {
|
||||
previews: ["symmetra"]
|
||||
previews: ["symmetra"],
|
||||
},
|
||||
owner: "octokit",
|
||||
repo: "request.js",
|
||||
number: 1,
|
||||
labels: ["🐛 bug"]
|
||||
labels: ["🐛 bug"],
|
||||
});
|
||||
```
|
||||
|
||||
@@ -70,11 +70,11 @@ request("POST /repos/:owner/:repo/issues/:number/labels", {
|
||||
<tr><th>
|
||||
Browsers
|
||||
</th><td width=100%>
|
||||
Load <code>@octokit/request</code> directly from <a href="https://cdn.pika.dev">cdn.pika.dev</a>
|
||||
Load <code>@octokit/request</code> directly from <a href="https://cdn.skypack.dev">cdn.skypack.dev</a>
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import { request } from "https://cdn.pika.dev/@octokit/request";
|
||||
import { request } from "https://cdn.skypack.dev/@octokit/request";
|
||||
</script>
|
||||
```
|
||||
|
||||
@@ -99,12 +99,12 @@ const { request } = require("@octokit/request");
|
||||
```js
|
||||
// Following GitHub docs formatting:
|
||||
// https://developer.github.com/v3/repos/#list-organization-repositories
|
||||
const result = await request("GET /orgs/:org/repos", {
|
||||
const result = await request("GET /orgs/{org}/repos", {
|
||||
headers: {
|
||||
authorization: "token 0000000000000000000000000000000000000001"
|
||||
authorization: "token 0000000000000000000000000000000000000001",
|
||||
},
|
||||
org: "octokit",
|
||||
type: "private"
|
||||
type: "private",
|
||||
});
|
||||
|
||||
console.log(`${result.data.length} repos found.`);
|
||||
@@ -117,7 +117,7 @@ For GraphQL request we recommend using [`@octokit/graphql`](https://github.com/o
|
||||
```js
|
||||
const result = await request("POST /graphql", {
|
||||
headers: {
|
||||
authorization: "token 0000000000000000000000000000000000000001"
|
||||
authorization: "token 0000000000000000000000000000000000000001",
|
||||
},
|
||||
query: `query ($login: String!) {
|
||||
organization(login: $login) {
|
||||
@@ -127,8 +127,8 @@ const result = await request("POST /graphql", {
|
||||
}
|
||||
}`,
|
||||
variables: {
|
||||
login: "octokit"
|
||||
}
|
||||
login: "octokit",
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
@@ -139,12 +139,12 @@ Alternatively, pass in a method and a url
|
||||
```js
|
||||
const result = await request({
|
||||
method: "GET",
|
||||
url: "/orgs/:org/repos",
|
||||
url: "/orgs/{org}/repos",
|
||||
headers: {
|
||||
authorization: "token 0000000000000000000000000000000000000001"
|
||||
authorization: "token 0000000000000000000000000000000000000001",
|
||||
},
|
||||
org: "octokit",
|
||||
type: "private"
|
||||
type: "private",
|
||||
});
|
||||
```
|
||||
|
||||
@@ -155,10 +155,10 @@ The simplest way to authenticate a request is to set the `Authorization` header
|
||||
```js
|
||||
const requestWithAuth = request.defaults({
|
||||
headers: {
|
||||
authorization: "token 0000000000000000000000000000000000000001"
|
||||
}
|
||||
authorization: "token 0000000000000000000000000000000000000001",
|
||||
},
|
||||
});
|
||||
const result = await request("GET /user");
|
||||
const result = await requestWithAuth("GET /user");
|
||||
```
|
||||
|
||||
For more complex authentication strategies such as GitHub Apps or Basic, we recommend the according authentication library exported by [`@octokit/auth`](https://github.com/octokit/auth.js).
|
||||
@@ -166,25 +166,28 @@ For more complex authentication strategies such as GitHub Apps or Basic, we reco
|
||||
```js
|
||||
const { createAppAuth } = require("@octokit/auth-app");
|
||||
const auth = createAppAuth({
|
||||
id: process.env.APP_ID,
|
||||
appId: process.env.APP_ID,
|
||||
privateKey: process.env.PRIVATE_KEY,
|
||||
installationId: 123
|
||||
installationId: 123,
|
||||
});
|
||||
const requestWithAuth = request.defaults({
|
||||
request: {
|
||||
hook: auth.hook
|
||||
hook: auth.hook,
|
||||
},
|
||||
mediaType: {
|
||||
previews: ["machine-man"]
|
||||
}
|
||||
previews: ["machine-man"],
|
||||
},
|
||||
});
|
||||
|
||||
const { data: app } = await requestWithAuth("GET /app");
|
||||
const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
|
||||
owner: "octocat",
|
||||
repo: "hello-world",
|
||||
title: "Hello from the engine room"
|
||||
});
|
||||
const { data: app } = await requestWithAuth(
|
||||
"POST /repos/{owner}/{repo}/issues",
|
||||
{
|
||||
owner: "octocat",
|
||||
repo: "hello-world",
|
||||
title: "Hello from the engine room",
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
## request()
|
||||
@@ -215,7 +218,7 @@ const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
|
||||
String
|
||||
</td>
|
||||
<td>
|
||||
If <code>route</code> is set it has to be a string consisting of the request method and URL, e.g. <code>GET /orgs/:org</code>
|
||||
**Required**. If <code>route</code> is set it has to be a string consisting of the request method and URL, e.g. <code>GET /orgs/{org}</code>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -226,7 +229,7 @@ const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
|
||||
String
|
||||
</td>
|
||||
<td>
|
||||
<strong>Required.</strong> Any supported <a href="https://developer.github.com/v3/#http-verbs">http verb</a>, case insensitive. <em>Defaults to <code>https://api.github.com</code></em>.
|
||||
The base URL that <code>route</code> or <code>url</code> will be prefixed with, if they use relative paths. <em>Defaults to <code>https://api.github.com</code></em>.
|
||||
</td>
|
||||
</tr>
|
||||
<th align=left>
|
||||
@@ -271,7 +274,7 @@ const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
|
||||
String
|
||||
</td>
|
||||
<td>
|
||||
<strong>Required.</strong> Any supported <a href="https://developer.github.com/v3/#http-verbs">http verb</a>, case insensitive. <em>Defaults to <code>Get</code></em>.
|
||||
Any supported <a href="https://developer.github.com/v3/#http-verbs">http verb</a>, case insensitive. <em>Defaults to <code>Get</code></em>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -282,8 +285,8 @@ const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
|
||||
String
|
||||
</td>
|
||||
<td>
|
||||
<strong>Required.</strong> A path or full URL which may contain <code>:variable</code> or <code>{variable}</code> placeholders,
|
||||
e.g. <code>/orgs/:org/repos</code>. The <code>url</code> is parsed using <a href="https://github.com/bramstein/url-template">url-template</a>.
|
||||
**Required**. A path or full URL which may contain <code>:variable</code> or <code>{variable}</code> placeholders,
|
||||
e.g. <code>/orgs/{org}/repos</code>. The <code>url</code> is parsed using <a href="https://github.com/bramstein/url-template">url-template</a>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -340,6 +343,16 @@ const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
|
||||
<td>
|
||||
Use an <code>AbortController</code> instance to cancel a request. In node you can only cancel streamed requests.
|
||||
</td>
|
||||
</tr>
|
||||
<th align=left>
|
||||
<code>options.request.log</code>
|
||||
</th>
|
||||
<td>
|
||||
<code>object</code>
|
||||
</td>
|
||||
<td>
|
||||
Used for internal logging. Defaults to <a href="https://developer.mozilla.org/en-US/docs/Web/API/console"><code>console</code></a>.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align=left>
|
||||
@@ -356,7 +369,7 @@ const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
|
||||
|
||||
All other options except `options.request.*` will be passed depending on the `method` and `url` options.
|
||||
|
||||
1. If the option key is a placeholder in the `url`, it will be used as replacement. For example, if the passed options are `{url: '/orgs/:org/repos', org: 'foo'}` the returned `options.url` is `https://api.github.com/orgs/foo/repos`
|
||||
1. If the option key is a placeholder in the `url`, it will be used as replacement. For example, if the passed options are `{url: '/orgs/{org}/repos', org: 'foo'}` the returned `options.url` is `https://api.github.com/orgs/foo/repos`
|
||||
2. If the `method` is `GET` or `HEAD`, the option is passed as query parameter
|
||||
3. Otherwise the parameter is passed in the request body as JSON key.
|
||||
|
||||
@@ -403,8 +416,8 @@ All other options except `options.request.*` will be passed depending on the `me
|
||||
If an error occurs, the `error` instance has additional properties to help with debugging
|
||||
|
||||
- `error.status` The http response status code
|
||||
- `error.headers` The http response headers as an object
|
||||
- `error.request` The request options such as `method`, `url` and `data`
|
||||
- `error.response` The http response object with `url`, `headers`, and `data`
|
||||
|
||||
## `request.defaults()`
|
||||
|
||||
@@ -415,13 +428,13 @@ const myrequest = require("@octokit/request").defaults({
|
||||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3",
|
||||
headers: {
|
||||
"user-agent": "myApp/1.2.3",
|
||||
authorization: `token 0000000000000000000000000000000000000001`
|
||||
authorization: `token 0000000000000000000000000000000000000001`,
|
||||
},
|
||||
org: "my-project",
|
||||
per_page: 100
|
||||
per_page: 100,
|
||||
});
|
||||
|
||||
myrequest(`GET /orgs/:org/repos`);
|
||||
myrequest(`GET /orgs/{org}/repos`);
|
||||
```
|
||||
|
||||
You can call `.defaults()` again on the returned method, the defaults will cascade.
|
||||
@@ -430,14 +443,14 @@ You can call `.defaults()` again on the returned method, the defaults will casca
|
||||
const myProjectRequest = request.defaults({
|
||||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3",
|
||||
headers: {
|
||||
"user-agent": "myApp/1.2.3"
|
||||
"user-agent": "myApp/1.2.3",
|
||||
},
|
||||
org: "my-project"
|
||||
org: "my-project",
|
||||
});
|
||||
const myProjectRequestWithAuth = myProjectRequest.defaults({
|
||||
headers: {
|
||||
authorization: `token 0000000000000000000000000000000000000001`
|
||||
}
|
||||
authorization: `token 0000000000000000000000000000000000000001`,
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
@@ -450,9 +463,9 @@ by the global default.
|
||||
See https://github.com/octokit/endpoint.js. Example
|
||||
|
||||
```js
|
||||
const options = request.endpoint("GET /orgs/:org/repos", {
|
||||
const options = request.endpoint("GET /orgs/{org}/repos", {
|
||||
org: "my-project",
|
||||
type: "private"
|
||||
type: "private",
|
||||
});
|
||||
|
||||
// {
|
||||
@@ -486,8 +499,8 @@ const response = await request("POST /markdown/raw", {
|
||||
data: "Hello world github/linguist#1 **cool**, and #1!",
|
||||
headers: {
|
||||
accept: "text/html;charset=utf-8",
|
||||
"content-type": "text/plain"
|
||||
}
|
||||
"content-type": "text/plain",
|
||||
},
|
||||
});
|
||||
|
||||
// Request is sent as
|
||||
@@ -526,9 +539,9 @@ request(
|
||||
headers: {
|
||||
"content-type": "text/plain",
|
||||
"content-length": 14,
|
||||
authorization: `token 0000000000000000000000000000000000000001`
|
||||
authorization: `token 0000000000000000000000000000000000000001`,
|
||||
},
|
||||
data: "Hello, world!"
|
||||
data: "Hello, world!",
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user