How to use @octokit/request - 10 common examples

To help you get started, we’ve selected a few @octokit/request examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github octokit / webhooks / lib / create-pr-on-change.js View on Github external
// push changes back to GitHub
  await execa('git', ['checkout', '-b', branchName])
  await execa('git', ['add', 'cache'])
  await execa('git', ['commit', '-m', 'build: cache'])
  await execa('git', ['add', '.'])
  await execa('git', ['commit', '-m', 'build: webhooks'])
  await execa('git', [
    'push',
    `https://${process.env.GH_TOKEN}@github.com/${owner}/${repo}.git`,
    `HEAD:${branchName}`
  ])
  await execa('git', ['checkout', '-'])

  // start pullrequest
  const { body } = await request('POST /repos/:owner/:repo/pulls', {
    owner,
    repo,
    headers: {
      authorization: `token ${process.env.GH_TOKEN}`
    },
    title: `🤖🚨 ${changesSummary}`,
    head: branchName,
    base: 'master',
    body: `Dearest humans,

My friend Travis asked me to let you know that they found webhook changes in their daily routine check.`
  })

  console.log(`🤖  Pull request created: ${body.html_url}`)
}
github googleapis / release-please / src / github.ts View on Github external
this.apiUrl = options.apiUrl || 'https://api.github.com';
    this.proxyKey = options.proxyKey;

    if (options.octokitAPIs === undefined) {
      this.octokit = new Octokit({ baseUrl: options.apiUrl });
      const defaults: { [key: string]: string | object } = {
        baseUrl: this.apiUrl,
        headers: {
          'user-agent': `release-please/${
            require('../../package.json').version
          }`,
          // some proxies do not require the token prefix.
          Authorization: `${this.proxyKey ? '' : 'token '}${this.token}`,
        },
      };
      this.request = request.defaults(defaults);
      this.graphql = graphql;
    } else {
      // for the benefit of probot applications, we allow a configured instance
      // of octokit to be passed in as a parameter.
      probotMode = true;
      this.octokit = options.octokitAPIs.octokit;
      this.request = options.octokitAPIs.request;
      this.graphql = options.octokitAPIs.graphql;
    }
  }
github newrelic / newrelic-ruby-agent / .github / actions / build-ruby / node_modules / @octokit / core / dist-src / index.js View on Github external
requestDefaults.headers["user-agent"] = [
            options.userAgent,
            `octokit-core.js/${VERSION} ${getUserAgent()}`,
        ]
            .filter(Boolean)
            .join(" ");
        if (options.baseUrl) {
            requestDefaults.baseUrl = options.baseUrl;
        }
        if (options.previews) {
            requestDefaults.mediaType.previews = options.previews;
        }
        if (options.timeZone) {
            requestDefaults.headers["time-zone"] = options.timeZone;
        }
        this.request = request.defaults(requestDefaults);
        this.graphql = withCustomRequest(this.request).defaults({
            ...requestDefaults,
            baseUrl: requestDefaults.baseUrl.replace(/\/api\/v3$/, "/api"),
        });
        this.log = Object.assign({
            debug: () => { },
            info: () => { },
            warn: console.warn.bind(console),
            error: console.error.bind(console),
        }, options.log);
        this.hook = hook;
        // (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance
        //     is unauthenticated. The `this.auth()` method is a no-op and no request hook is registred.
        // (2) If only `options.auth` is set, use the default token authentication strategy.
        // (3) If `options.authStrategy` is set then use it and pass in `options.auth`. Always pass own request as many strategies accept a custom request instance.
        // TODO: type `options.auth` based on `options.authStrategy`.
github newrelic / newrelic-ruby-agent / .github / actions / build-ruby / node_modules / @octokit / core / dist-web / index.js View on Github external
requestDefaults.headers["user-agent"] = [
            options.userAgent,
            `octokit-core.js/${VERSION} ${getUserAgent()}`,
        ]
            .filter(Boolean)
            .join(" ");
        if (options.baseUrl) {
            requestDefaults.baseUrl = options.baseUrl;
        }
        if (options.previews) {
            requestDefaults.mediaType.previews = options.previews;
        }
        if (options.timeZone) {
            requestDefaults.headers["time-zone"] = options.timeZone;
        }
        this.request = request.defaults(requestDefaults);
        this.graphql = withCustomRequest(this.request).defaults({
            ...requestDefaults,
            baseUrl: requestDefaults.baseUrl.replace(/\/api\/v3$/, "/api"),
        });
        this.log = Object.assign({
            debug: () => { },
            info: () => { },
            warn: console.warn.bind(console),
            error: console.error.bind(console),
        }, options.log);
        this.hook = hook;
        // (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance
        //     is unauthenticated. The `this.auth()` method is a no-op and no request hook is registred.
        // (2) If only `options.auth` is set, use the default token authentication strategy.
        // (3) If `options.authStrategy` is set then use it and pass in `options.auth`. Always pass own request as many strategies accept a custom request instance.
        // TODO: type `options.auth` based on `options.authStrategy`.
github newrelic / newrelic-ruby-agent / .github / actions / build-ruby / node_modules / @octokit / core / dist-src / index.js View on Github external
constructor(options = {}) {
        const hook = new Collection();
        const requestDefaults = {
            baseUrl: request.endpoint.DEFAULTS.baseUrl,
            headers: {},
            request: Object.assign({}, options.request, {
                hook: hook.bind(null, "request"),
            }),
            mediaType: {
                previews: [],
                format: "",
            },
        };
        // prepend default user agent with `options.userAgent` if set
        requestDefaults.headers["user-agent"] = [
            options.userAgent,
            `octokit-core.js/${VERSION} ${getUserAgent()}`,
        ]
            .filter(Boolean)
            .join(" ");
github newrelic / newrelic-ruby-agent / .github / actions / build-ruby / node_modules / @octokit / core / dist-web / index.js View on Github external
constructor(options = {}) {
        const hook = new Collection();
        const requestDefaults = {
            baseUrl: request.endpoint.DEFAULTS.baseUrl,
            headers: {},
            request: Object.assign({}, options.request, {
                hook: hook.bind(null, "request"),
            }),
            mediaType: {
                previews: [],
                format: "",
            },
        };
        // prepend default user agent with `options.userAgent` if set
        requestDefaults.headers["user-agent"] = [
            options.userAgent,
            `octokit-core.js/${VERSION} ${getUserAgent()}`,
        ]
            .filter(Boolean)
            .join(" ");
github octokit / rest.js / test / util.js View on Github external
function loadFixture(scenario) {
  return request("POST http://localhost:3000/fixtures", {
    data: JSON.stringify({ scenario })
  })
    .then(response => response.data)

    .catch(error => {
      if (error.status === "ECONNREFUSED") {
        throw new Error(
          'Fixtures server could not be reached. Make sure to start it with "npm run start-fixtures-server"'
        );
      }

      throw error;
    });
}
github octokit / rest.js / lib / constructor.js View on Github external
function Octokit(plugins, options) {
  options = options || {};
  const hook = new Hook.Collection();
  const log = Object.assign(
    {
      debug: () => {},
      info: () => {},
      warn: console.warn,
      error: console.error
    },
    options && options.log
  );
  const api = {
    hook,
    log,
    request: request.defaults(parseClientOptions(options, log, hook))
  };

  plugins.forEach(pluginFunction => pluginFunction(api, options));

  return api;
}
github octokit / webhooks / lib / get-html.js View on Github external
async function getHtml (state) {
  const cacheFilePath = 'event-types-and-payloads.html'

  if (state.cached && await cache.exists(cacheFilePath)) {
    return cache.read(cacheFilePath)
  }

  console.log(`⌛  fetching ${WEBHOOKS_DOCS_URL}`)

  const { data: html } = await request(WEBHOOKS_DOCS_URL)
  await cache.writeHtml(cacheFilePath, html)
  return html
}
github HewlettPackard / yoda / nodejs / yoda-webhook / github-app.js View on Github external
function init() {
	logger.info("Initializing GitHub App ...");

	var pem = fs.readFileSync(configuration.getOption("app-pemfile"));
	
	auth = createAppAuth({
		  id: configuration.getOption('app-appid'),
		  privateKey: pem,
		  clientId: configuration.getOption('app-clientid'),
		  clientSecret: configuration.getOption('app-clientsecret'),
		  request: request.defaults({
			  baseUrl: configuration.getOption('baseurl')
		  })  
	});
	
	logger.debug(auth);
}

@octokit/request

Send parameterized requests to GitHub's APIs with sensible defaults in browsers and Node

MIT
Latest version published 4 months ago

Package Health Score

90 / 100
Full package analysis