Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@octokit/request

Package Overview
Dependencies
Maintainers
3
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@octokit/request - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

lib/fetch.js

18

index.js
const endpoint = require('@octokit/endpoint')
const fetch = require('node-fetch').default
const getUserAgent = require('universal-user-agent')
const request = require('./lib/request')
const version = require('./package.json').version
const userAgent = `octokit-request.js/${version} ${getUserAgent()}`
const withDefaults = require('./lib/with-defaults')
function octokitRequest (endpoint, route, options) {
return request(module.exports.fetch, endpoint(route, options))
}
function withDefaults (oldEndpoint, newDefaults) {
const endpoint = oldEndpoint.defaults(newDefaults)
const request = octokitRequest.bind(null, endpoint)
request.endpoint = endpoint
request.defaults = withDefaults.bind(null, endpoint)
return request
}
module.exports = withDefaults(endpoint, {

@@ -26,4 +13,1 @@ headers: {

})
// expose internally used `fetch` method for testing/mocking only
module.exports.fetch = fetch

@@ -7,6 +7,9 @@ 'use strict'

const mockable = require('./fetch')
const getBuffer = require('./get-buffer-response')
const HttpError = require('./http-error')
function request (fetch, requestOptions) {
function request (endpoint, route, options) {
const requestOptions = endpoint(route, options)
if (isPlainObject(requestOptions.body) || Array.isArray(requestOptions.body)) {

@@ -19,3 +22,3 @@ requestOptions.body = JSON.stringify(requestOptions.body)

return fetch(requestOptions.url, Object.assign({
return mockable.fetch(requestOptions.url, Object.assign({
method: requestOptions.method,

@@ -22,0 +25,0 @@ body: requestOptions.body,

{
"name": "@octokit/request",
"version": "1.2.0",
"version": "1.2.1",
"publishConfig": {

@@ -5,0 +5,0 @@ "access": "public"

@@ -156,14 +156,2 @@ # request.js

<th align=left>
<code>url</code>
</th>
<td>
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>.
</td>
</tr>
<tr>
<th align=left>
<code>data</code>

@@ -226,7 +214,2 @@ </th>

<tr>
<th align=left><code>redirect</code></th>
<td>String</td>
<td>Set to <code>"manual"</code> to extract redirect headers, <code>"error"</code> to reject redirect. Defaults to <code>"follow"</code></td>
</tr>
<tr>
<th align=left><code>data</code></th>

@@ -236,7 +219,2 @@ <td>Any</td>

</tr>
<tr>
<th align=left><code>agent</code></th>
<td>Node http(s).Agent</td>
<td>For advanced request options in node you can pass in a node Agent (<a href="https://nodejs.org/api/http.html#http_class_http_agent">http</a>, <a href="https://nodejs.org/api/https.html#https_class_https_agent">https</a>)</td>
</tr>
</table>

@@ -243,0 +221,0 @@

@@ -6,2 +6,3 @@ const chai = require('chai')

const octokitRequest = require('..')
const mockable = require('../lib/fetch')

@@ -17,3 +18,3 @@ const expect = chai.expect

it('README example', () => {
octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.mock('https://github-enterprise.acme-inc.com/api/v3/orgs/my-project/repos?per_page=100', [], {

@@ -45,3 +46,3 @@ headers: {

it('repeated defaults', () => {
octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.get('https://github-enterprise.acme-inc.com/api/v3/orgs/my-project/repos', [], {

@@ -48,0 +49,0 @@ headers: {

@@ -7,6 +7,7 @@ const chai = require('chai')

const octokitRequest = require('..')
const mockable = require('../lib/fetch')
chai.use(sinonChai)
const expect = chai.expect
const originalFetch = octokitRequest.fetch
const originalFetch = mockable.fetch

@@ -18,3 +19,3 @@ const pkg = require('../package.json')

afterEach(() => {
octokitRequest.fetch = originalFetch
mockable.fetch = originalFetch
})

@@ -26,3 +27,3 @@ it('is a function', () => {

it('README example', () => {
octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.mock('https://api.github.com/orgs/octokit/repos?type=private', [], {

@@ -50,3 +51,3 @@ headers: {

it('README example alternative', () => {
octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.mock('https://api.github.com/orgs/octokit/repos?type=private', [], {

@@ -60,3 +61,3 @@ headers: {

octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.mock('https://api.github.com/orgs/octokit/repos?type=private', [])

@@ -80,3 +81,3 @@

it('Request with body', () => {
octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.mock('https://api.github.com/repos/octocat/hello-world/issues', 201, {

@@ -111,3 +112,3 @@ headers: {

it('Put without request body', () => {
octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.mock('https://api.github.com/user/starred/octocat/hello-world', 204, {

@@ -133,3 +134,3 @@ headers: {

it('HEAD requests (octokit/rest.js#841)', () => {
octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.head('https://api.github.com/repos/whatwg/html/pulls/1', {

@@ -174,3 +175,3 @@ status: 200,

it.skip('Binary response with redirect (🤔 unclear how to mock fetch redirect properly)', () => {
octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.get('https://codeload.github.com/octokit-fixture-org/get-archive/legacy.tar.gz/master', {

@@ -200,3 +201,3 @@ status: 200,

it('Binary response', () => {
octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.get('https://codeload.github.com/octokit-fixture-org/get-archive/legacy.tar.gz/master', {

@@ -219,3 +220,3 @@ status: 200,

it('304 etag', () => {
octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.get((url, { headers }) => {

@@ -241,3 +242,3 @@ return url === 'https://api.github.com/orgs/myorg' &&

it('Not found', () => {
octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.get('path:/orgs/nope', 404)

@@ -259,3 +260,3 @@

it('non-JSON response', () => {
octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.get('path:/repos/octokit-fixture-org/hello-world/contents/README.md', {

@@ -300,3 +301,3 @@ status: 200,

it('custom user-agent', () => {
octokitRequest.fetch = fetchMock.sandbox()
mockable.fetch = fetchMock.sandbox()
.get((url, { headers }) => headers['user-agent'] === 'funky boom boom pow', 200)

@@ -312,3 +313,3 @@

it('passes node-fetch options to fetch only', () => {
octokitRequest.fetch = (url, options) => {
mockable.fetch = (url, options) => {
expect(url).to.equal('https://api.github.com/')

@@ -315,0 +316,0 @@ expect(options.timeout).to.equal(100)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc