async handleClosedIssue()

in functions/src/cron.ts [103:144]


  async handleClosedIssue(
    org: string,
    name: string,
    issue: types.internal.Issue,
    issueConfig: types.IssueCleanupConfig
  ): Promise<types.Action[]> {
    const actions: types.Action[] = [];

    // Skip already-locked issues
    if (issue.locked) {
      return actions;
    }

    // We have already verified before calling this function that lock_days is defined, but
    // we default to MAX_NUMBER (aka never lock) just in case.
    const nowMs = new Date().getTime();
    const lockDays = issueConfig.lock_days || Number.MAX_VALUE;
    const lockMillis = lockDays * 24 * 60 * 60 * 1000;

    // This is a "this should never happen" case but the GitHub API
    // is not type-safe enough to ignore the possibility.
    if (!issue.closed_at) {
      log.warn(`Closed issue ${org}/${name}/${issue.number} has no closed_at.`);
      return actions;
    }

    const closedAtStr = "" + issue.closed_at;
    const closedAtMs = new Date(closedAtStr).getTime();

    if (nowMs - closedAtMs > lockMillis) {
      actions.push(
        new types.GitHubLockAction(
          org,
          name,
          issue.number,
          `Issue was closed at ${closedAtStr} which is more than ${lockDays} ago`
        )
      );
    }

    return actions;
  }