How to use @octokit/app - 9 common examples

To help you get started, we’ve selected a few @octokit/app 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 probot / probot / src / index.ts View on Github external
options.secret = options.secret || 'development'
    this.options = options
    this.logger = logger
    this.apps = []
    this.webhook = new Webhooks({
      path: options.webhookPath,
      secret: options.secret
    })
    this.githubToken = options.githubToken
    this.Octokit = options.Octokit || ProbotOctokit
    if (this.options.id) {
      if (process.env.GHE_HOST && /^https?:\/\//.test(process.env.GHE_HOST)) {
        throw new Error('Your \`GHE_HOST\` environment variable should not begin with https:// or http://')
      }

      this.app = new OctokitApp({
        baseUrl: process.env.GHE_HOST && `https://${process.env.GHE_HOST}/api/v3`,
        id: options.id as number,
        privateKey: options.cert as string
      })
    }
    this.server = createServer({ webhook: (this.webhook as any).middleware, logger })

    // Log all received webhooks
    this.webhook.on('*', async (event: Webhooks.WebhookEvent) => {
      await this.receive(event)
    })

    // Log all webhook errors
    this.webhook.on('error', this.errorHandler)

    if (options.redisConfig || process.env.REDIS_URL) {
github kaisermann / pr-slack-bot / src / api / github.js View on Github external
const { App } = require('@octokit/app');
const { request } = require('@octokit/request');

const Logger = require('../includes/logger.js');
const db = require('../api/db.js');

const github_app = new App(
  process.env.NODE_ENV === 'production'
    ? {
        id: process.env.APP_ID,
        privateKey: process.env.APP_PRIVATE_KEY,
      }
    : {
        id: process.env.DEV_APP_ID,
        privateKey: process.env.DEV_APP_PRIVATE_KEY,
      },
);

let jwt_token = github_app.getSignedJsonWebToken();
// renew after 9:30 mins
setInterval(() => {
  jwt_token = github_app.getSignedJsonWebToken();
}, 1000 * (60 * 10 - 30));
github tibdex / autorebase / src / tests-utils.ts View on Github external
const createAuthenticatedOctokit = async ({
  appId,
  installationId,
  privateKey,
}: {
  appId: number;
  installationId: number;
  privateKey: string;
}) => {
  const app = new App({ id: appId, privateKey });
  const installationAccessToken = await app.getInstallationAccessToken({
    installationId,
  });
  const octokit = new Octokit({ auth: `token ${installationAccessToken}` });
  return octokit;
};
github smooth-code / bundle-analyzer / apps / server / src / modules / github / client.js View on Github external
import { App } from '@octokit/app'
import Octokit from '@octokit/rest'
import config from 'config'

const app = new App({
  id: config.get('github.appId'),
  privateKey: config.get('github.privateKey'),
})

export function getInstallationOctokit(installation) {
  return new Octokit({
    debug: config.get('env') === 'development',
    auth: async () => {
      const installationAccessToken = await app.getInstallationAccessToken({
        installationId: installation.githubId,
      })
      return `token ${installationAccessToken}`
    },
  })
}
github rolling-scopes / rsschool-app / server / src / routes / course / repository.ts View on Github external
import { App } from '@octokit/app';
import octokit from '@octokit/rest';
import { OK } from 'http-status-codes';
import Router from 'koa-router';
import { camelCase, toUpper } from 'lodash';
import { getRepository } from 'typeorm';
import { config } from '../../config';
import { ILogger } from '../../logger';
import { Course, Mentor, Student } from '../../models';
import { queryStudentByGithubId } from '../../services/courseService';
import { setResponse } from '../utils';

const teamsCache: Record = {};
const { appId, privateKey } = config.github;
const app = new App({ id: Number(appId), privateKey });

export const postRepositories = (logger: ILogger) => async (ctx: Router.RouterContext) => {
  const { courseId } = ctx.params as { courseId: number };
  const result: { repository: string }[] = [];
  const course = (await getRepository(Course).findOne(courseId))!;
  const githubIds = await queryStudentGithubIds(courseId);
  for await (const githubId of githubIds) {
    const { repository } = await createRepository(course, githubId, logger);
    result.push({ repository });
  }
  setResponse(ctx, OK, result);
};

export const postRepository = (logger: ILogger) => async (ctx: Router.RouterContext) => {
  const { courseId, githubId } = ctx.params as { courseId: number; githubId: string };
github danger / peril / api / source / api / github.ts View on Github external
import { PERIL_INTEGRATION_ID, PRIVATE_GITHUB_SIGNING_KEY } from "../globals"

import { App } from "@octokit/app"

export const GithubApp = new App({ id: PERIL_INTEGRATION_ID, privateKey: PRIVATE_GITHUB_SIGNING_KEY })

export async function getTemporaryAccessTokenForInstallation(installationId: number): Promise {
  return await GithubApp.getInstallationAccessToken({ installationId })
}
github eduardoboucas / staticman / lib / GitHub.js View on Github external
async _authenticate (username, repository) {
    const app = new App(
      {
        id: config.get('githubAppID'),
        privateKey: config.get('githubPrivateKey'),
        baseUrl: config.get('githubBaseUrl')
      }
    )

    const jwt = app.getSignedJsonWebToken()

    const {data} = await request('GET /repos/:owner/:repo/installation', {
      owner: username,
      repo: repository,
      headers: {
        authorization: `Bearer ${jwt}`,
        accept: 'application/vnd.github.machine-man-preview+json'
      }
github ktk-2005 / Feedbacker-Forum / server / src / githubapp.js View on Github external
export function initializeGitHubApp() {
  if (!config.github) {
    logger.warn('GitHub integration not initialized, missing config.')
    return
  }
  const { id, privateKey, clientId, clientSecret } = config.github
  if (!(id && privateKey && clientId && clientSecret)) {
    logger.warn('Invalid GitHub config, not initialized.')
    return
  }

  githubApp = new App({ id, privateKey })
  githubAuth = new ClientOAuth2({
    clientId,
    clientSecret,
    accessTokenUri: 'https://github.com/login/oauth/access_token',
    authorizationUri: 'https://github.com/login/oauth/authorize',
    redirectUri: `${config.siteUrl}/api/github/oauth2callback`,
  })
}

@octokit/app

GitHub Apps toolset for Node.js

MIT
Latest version published 10 days ago

Package Health Score

89 / 100
Full package analysis

Popular @octokit/app functions

Similar packages