Skip to content
Snippets Groups Projects
Select Git revision
21 results Searching

github.js

Blame
  • github.js 21.09 KiB
    let logger = require('../logger');
    const ghGot = require('gh-got');
    
    const config = {};
    
    module.exports = {
      // GitHub App
      getInstallations,
      getInstallationToken,
      getInstallationRepositories,
      // Initialization
      getRepos,
      initRepo,
      setBaseBranch,
      // Search
      findFilePaths,
      // Branch
      branchExists,
      getAllRenovateBranches,
      isBranchStale,
      getBranchPr,
      getBranchStatus,
      deleteBranch,
      mergeBranch,
      // issue
      addAssignees,
      addReviewers,
      addLabels,
      // PR
      findPr,
      checkForClosedPr,
      createPr,
      getPr,
      getAllPrs,
      updatePr,
      mergePr,
      // file
      getSubDirectories,
      commitFilesToBranch,
      getFile,
      getFileContent,
      getFileJson,
      // Commits
      getCommitMessages,
    };
    
    // Get all installations for a GitHub app
    async function getInstallations(appToken) {
      logger.debug('getInstallations(appToken)');
      try {
        const url = 'app/installations';
        const options = {
          headers: {
            accept: 'application/vnd.github.machine-man-preview+json',
            authorization: `Bearer ${appToken}`,
          },
        };
        const res = await ghGot(url, options);
        logger.debug(`Returning ${res.body.length} results`);
        return res.body;
      } catch (err) {
        logger.error({ err }, `GitHub getInstallations error`);
        throw err;
      }
    }
    
    // Get the user's installation token
    async function getInstallationToken(appToken, installationId) {
      logger.debug(`getInstallationToken(appToken, ${installationId})`);
      try {