Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

quickstart.py

Blame
  • github.js 22.98 KiB
    let logger = require('../logger');
    const ghGot = require('gh-got');
    
    // istanbul ignore next
    function sleep(ms) {
      // eslint-disable-next-line promise/avoid-new
      return new Promise(resolve => setTimeout(resolve, ms));
    }
    
    async function ghGotRetry(path, opts, retries = 5) {
      try {
        const res = await ghGot(path, opts);
        return res;
      } catch (err) {
        if (err.statusCode >= 500 && err.statusCode < 600 && retries > 0) {
          logger.debug(`Retrying statusCode ${err.statusCode}`);
          // istanbul ignore if
          if (process.env.NODE_ENV !== 'test') {
            await sleep(5000 / retries);
          }
          return ghGotRetry(path, opts, retries - 1);
        }
        throw err;
      }
    }
    
    const helpers = ['get', 'post', 'put', 'patch', 'head', 'delete'];
    
    for (const x of helpers) {
      ghGotRetry[x] = async (path, opts, retries = 3) => {
        try {
          const res = await ghGot[x](path, opts);
          return res;
        } catch (err) {
          if (err.statusCode === 502 && retries > 0) {
            return ghGotRetry[x](path, opts, retries - 1);
          }
          throw err;
        }
      };
    }
    
    const config = {};
    
    module.exports = {
      // GitHub App
      getInstallations,
      getInstallationToken,
      getInstallationRepositories,
      // Initialization
      getRepos,
      initRepo,
      setBaseBranch,
      // Search
      findFilePaths,
      // Branch
      branchExists,
      getAllRenovateBranches,
      isBranchStale,
      getBranchPr,
      getBranchStatus,
      setBranchStatus,
      deleteBranch,
      mergeBranch,
      // issue
      addAssignees,
      addReviewers,
      addLabels,
      // PR
      findPr,