Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: octokit/request.js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bc060b070c2e40d488ade12bdb525db3cf896dea
Choose a base ref
...
head repository: octokit/request.js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2fb77a86d61734558e724b4fbeffaaaed76c2334
Choose a head ref
  • 14 commits
  • 9 files changed
  • 7 contributors

Commits on Jul 8, 2022

  1. fix(deps): update dependency @octokit/request-error to v3 (#480)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jul 8, 2022
    Copy the full SHA
    b5acf87 View commit details

Commits on Jul 11, 2022

  1. build(deps): lock file maintenance (#484)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jul 11, 2022
    Copy the full SHA
    b18514a View commit details
  2. feat: failover from native fetch to node-fetch (#481)

    Co-authored-by: wolfy1339 <4595477+wolfy1339@users.noreply.github.com>
    baoshan and wolfy1339 authored Jul 11, 2022
    Copy the full SHA
    d000a0a View commit details
  3. Copy the full SHA
    9a8765c View commit details
  4. ci(action): update actions/setup-node digest to 5b949b5 (#487)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jul 11, 2022
    Copy the full SHA
    8cdd770 View commit details
  5. docs(readme): use native fetch API first (#488)

    docs(readme): use native `fetch` api first
    baoshan authored Jul 11, 2022
    Copy the full SHA
    b517ae0 View commit details
  6. ci(test): use test_matrix and test jobs (#483)

    Co-authored-by: wolfy1339 <4595477+wolfy1339@users.noreply.github.com>
    oscard0m and wolfy1339 authored Jul 11, 2022
    Copy the full SHA
    fe7da7b View commit details

Commits on Jul 12, 2022

  1. Copy the full SHA
    2f899ab View commit details

Commits on Jul 13, 2022

  1. ci(action): update github/codeql-action digest to 3e7e3b3 (#490)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jul 13, 2022
    Copy the full SHA
    f845b7c View commit details
  2. Copy the full SHA
    db79164 View commit details

Commits on Jul 14, 2022

  1. ci(action): update actions/setup-node digest to 2fddd88 (#491)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jul 14, 2022
    Copy the full SHA
    57327e7 View commit details

Commits on Jul 18, 2022

  1. build(deps): lock file maintenance (#493)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jul 18, 2022
    Copy the full SHA
    39d8b11 View commit details

Commits on Aug 15, 2022

  1. Copy the full SHA
    41808ab View commit details
  2. fix(deps): update dependency @octokit/types to v7 (#508)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Aug 15, 2022
    Copy the full SHA
    2fb77a8 View commit details
Showing with 4,831 additions and 8,587 deletions.
  1. +4 −9 .github/workflows/codeql-analysis.yml
  2. +1 −1 .github/workflows/release.yml
  3. +10 −3 .github/workflows/test.yml
  4. +1 −1 .github/workflows/update-prettier.yml
  5. +3 −1 README.md
  6. +4,749 −8,564 package-lock.json
  7. +3 −3 package.json
  8. +4 −3 src/fetch-wrapper.ts
  9. +56 −2 test/request.test.ts
13 changes: 4 additions & 9 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -23,23 +23,18 @@ jobs:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}


# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@3f62b754e23e0dd60f91b744033e1dc1654c0ec6 # tag=v2
uses: github/codeql-action/init@3e7e3b32d0fb8283594bb0a76cc60a00918b0969 # tag=v2
# Override language selection by uncommenting this and choosing your languages
# with:
# languages: go, javascript, csharp, python, cpp, java

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@3f62b754e23e0dd60f91b744033e1dc1654c0ec6 # tag=v2
uses: github/codeql-action/autobuild@3e7e3b32d0fb8283594bb0a76cc60a00918b0969 # tag=v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
@@ -53,4 +48,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@3f62b754e23e0dd60f91b744033e1dc1654c0ec6 # tag=v2
uses: github/codeql-action/analyze@3e7e3b32d0fb8283594bb0a76cc60a00918b0969 # tag=v2
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
- uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # tag=v3
- uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
with:
node-version: 16
cache: npm
13 changes: 10 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ name: Test
- opened
- synchronize
jobs:
test:
test_matrix:
runs-on: ubuntu-latest
strategy:
matrix:
@@ -20,11 +20,18 @@ jobs:
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
- name: "Use Node.js ${{ matrix.node_version }}"
uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # tag=v3
uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
with:
node-version: "${{ matrix.node_version }}"
cache: npm
- name: Install
run: npm ci
- name: Test
run: npm test
run: npm test --ignore-scripts # run lint only once
test:
runs-on: ubuntu-latest
needs: test_matrix
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
- run: npm ci
- run: npm run lint
2 changes: 1 addition & 1 deletion .github/workflows/update-prettier.yml
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # tag=v3
- uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
with:
node-version: 16
cache: npm
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ to interact with [GitHub’s REST API](https://developer.github.com/v3/) and

It uses [`@octokit/endpoint`](https://github.com/octokit/endpoint.js) to parse
the passed options and sends the request using [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
([node-fetch](https://github.com/bitinn/node-fetch) in Node).
([node-fetch](https://github.com/bitinn/node-fetch) when the runtime has no native `fetch` API).

<!-- update table of contents by running `npx markdown-toc README.md -i` -->

@@ -419,6 +419,8 @@ If an error occurs, the promise is rejected with an `error` object containing 3
- `error.request` The request options such as `method`, `url` and `data`
- `error.response` The http response object with `url`, `headers`, and `data`

If the error is due to an `AbortSignal` being used, the resulting `AbortError` is bubbled up to the caller.

## `request.defaults()`

Override or set default options. Example:
13,313 changes: 4,749 additions & 8,564 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -23,15 +23,15 @@
"license": "MIT",
"dependencies": {
"@octokit/endpoint": "^7.0.0",
"@octokit/request-error": "^2.1.0",
"@octokit/types": "^6.16.1",
"@octokit/request-error": "^3.0.0",
"@octokit/types": "^7.0.0",
"is-plain-object": "^5.0.0",
"node-fetch": "^2.6.7",
"universal-user-agent": "^6.0.0"
},
"devDependencies": {
"@octokit/auth-app": "^4.0.0",
"@pika/pack": "^0.5.0",
"@pika/pack": "^0.3.7",
"@pika/plugin-build-node": "^0.9.0",
"@pika/plugin-build-web": "^0.9.0",
"@pika/plugin-ts-standard-pkg": "^0.9.0",
7 changes: 4 additions & 3 deletions src/fetch-wrapper.ts
Original file line number Diff line number Diff line change
@@ -27,7 +27,9 @@ export default function fetchWrapper(
let url: string;

const fetch: typeof nodeFetch =
(requestOptions.request && requestOptions.request.fetch) || nodeFetch;
(requestOptions.request && requestOptions.request.fetch) ||
globalThis.fetch ||
/* istanbul ignore next */ nodeFetch;

return fetch(
requestOptions.url,
@@ -115,7 +117,6 @@ export default function fetchWrapper(

return getResponseData(response);
})

.then((data) => {
return {
status,
@@ -124,9 +125,9 @@ export default function fetchWrapper(
data,
};
})

.catch((error) => {
if (error instanceof RequestError) throw error;
else if (error.name === "AbortError") throw error;

throw new RequestError(error.message, 500, {
request: requestOptions,
58 changes: 56 additions & 2 deletions test/request.test.ts
Original file line number Diff line number Diff line change
@@ -578,6 +578,8 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
it("options.request.signal is passed as option to fetch", function () {
return request("/", {
request: {
// We pass a value that is not an `AbortSignal`, and expect `fetch` to
// throw an exception complaining about the value
signal: "funk",
},
})
@@ -586,8 +588,13 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
})

.catch((error) => {
expect(error.message).toMatch(/\bsignal\b/i);
expect(error.message).toMatch(/\bAbortSignal\b/i);
// We can't match on the entire string because the message differs between
// Node versions.
//
// In v14 and v16, the message just mentions "signal" and has `instanceof`
// as one word, whereas in v18 it contains the stringified signal and uses
// proper English ("instance of").
expect(error.message).toMatch(/to be an instance ?of AbortSignal/);
});
});

@@ -1011,4 +1018,51 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
expect(mock.done()).toBe(true);
});
});

it("bubbles up AbortError if the request is aborted", () => {
// AbortSignal and AbortController do not exist on
// Node < 15. The main parts of their API have been
// reproduced in the mocks below.
class AbortSignal {
abort = () => {
const e = new Error("");
e.name = "AbortError";
throw e;
};

addEventListener = () => {};
}

class AbortController {
abort = () => {
this.signal.abort();
};
signal = new AbortSignal();
}
const abortController = new AbortController();
const mock = fetchMock.sandbox().post(
"https://api.github.com/repos/octokit-fixture-org/release-assets/releases/tags/v1.0.0",
new Promise(() => {
abortController.abort();
})
);

return request("POST /repos/{owner}/{repo}/releases/tags/{tag}", {
owner: "octokit-fixture-org",
repo: "release-assets",
tag: "v1.0.0",
request: {
fetch: mock,
signal: abortController.signal,
},
headers: {
"content-type": "text/plain",
},
data: stringToArrayBuffer("Hello, world!\n"),
name: "test-upload.txt",
label: "test",
}).catch((error) => {
expect(error.name).toEqual("AbortError");
});
});
});