async manualInit()

in functions/src/plugins/triagePR.ts [21:72]


  async manualInit(): Promise<void> {
    this.log('init triage PR');
    const adminConfig = await this.admin.doc('config').get();
    if(adminConfig.exists && (<AdminConfig>adminConfig.data()).allowInit) {
      const github = await this.robot.auth();
      const installations = await github.paginate(github.apps.listInstallations({}), pages => (pages as any as Github.AnyResponse).data);
      await Promise.all(installations.map(async installation => {
        const authGithub = await this.robot.auth(installation.id);
        const repositories = await authGithub.apps.listRepos({});
        await Promise.all(repositories.data.repositories.map(async (repository: Github.AppsListReposResponseRepositoriesItem) => {
          const context = new Context({payload: {repository}}, authGithub, this.robot.log);
          const config = await this.getConfig(context);
          if(config.disabled) {
            return;
          }
          const {owner, repo} = context.repo();
          const issues = await authGithub.paginate(authGithub.issues.listForRepo({
            owner,
            repo,
            state: 'open',
            per_page: 100
          }), pages => (pages as any as Github.AnyResponse).data);

          issues.forEach(async (issue: Github.IssuesListForRepoResponseItem) => {
            // We only want the PRs, not the issues
            if(issue.pull_request) {
              const isL1Triaged = this.isTriaged(config.l1TriageLabels, issue.labels.map((label: Github.IssuesListForRepoResponseItemLabelsItem) => label.name));
              if(!isL1Triaged) {
                if(issue.milestone) {
                  await this.setMilestone(null, context.github, owner, repo, issue);
                }
              } else if(!issue.milestone || issue.milestone.number === config.defaultMilestone || issue.milestone.number === config.needsTriageMilestone) {
                const isL2Triaged = this.isTriaged(config.l2TriageLabels || config.triagedLabels, issue.labels.map((label: Github.IssuesListForRepoResponseItemLabelsItem) => label.name));
                if(isL2Triaged) {
                  if(!issue.milestone || issue.milestone.number !== config.defaultMilestone) {
                    await this.setMilestone(config.defaultMilestone, context.github, owner, repo, issue);
                  }
                } else {
                  // if it's not triaged, set the "needsTriage" milestone
                  if(!issue.milestone || issue.milestone.number !== config.needsTriageMilestone) {
                    await this.setMilestone(config.needsTriageMilestone, context.github, owner, repo, issue);
                  }
                }
              }
            }
          });
        }));
      }));
    } else {
      this.logError(`Manual init is disabled: the value of allowInit is set to false in the admin config database`);
    }
  }