async checkNewIssueTemplate()

in functions/src/issues.ts [552:612]


  async checkNewIssueTemplate(
    repo: types.internal.Repository,
    issue: types.internal.Issue
  ): Promise<types.Action[]> {
    const actions: types.Action[] = [];
    const org = repo.owner.login;
    const name = repo.name;
    const number = issue.number;

    const res = await this.checkMatchesTemplate(org, name, issue);
    log.debug(`Check template result: ${JSON.stringify(res)}`);

    const validationConfig = this.config.getRepoTemplateValidationConfig(
      repo.owner.login,
      repo.name,
      res.templatePath
    );

    if (!res.matches) {
      // If it does not match:
      //  * Add a comment explaining the probblems.
      //  * If configured, add a label for template validation failure.
      let reason: string;
      if (res.failure && res.failure.emptySections) {
        reason = `Required sections of "${
          res.templatePath
        }" were left empty: ${JSON.stringify(res.failure.emptySections)}`;
      } else if (res.failure && res.failure.missingSections) {
        reason = `Sections of "${
          res.templatePath
        }" were missing: ${JSON.stringify(res.failure.missingSections)}`;
      } else {
        reason =
          "There was an unknown error when trying to match the issue template";
      }

      const template_action = new types.GitHubCommentAction(
        org,
        name,
        number,
        res.message,
        true,
        reason
      );
      actions.push(template_action);

      if (validationConfig && validationConfig.validation_failed_label) {
        const label = validationConfig.validation_failed_label;
        const label_action = new types.GitHubAddLabelAction(
          repo.owner.login,
          repo.name,
          issue.number,
          label,
          "Template validation failed, adding specified label."
        );
        actions.push(label_action);
      }
    }

    return actions;
  }