Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

1.1 KB
Raw Blame
import "dotenv/config";
import type { Octokit } from "@octokit/rest";
import dayjs from "dayjs";

import { sendBackportReminder } from "./slack";
import type { Issue } from "./types";

const RECENT_BACKPORT_THRESHOLD_HOURS = 25;

/** check open backports and send slack reminders about stale ones */
export const checkOpenBackports = async ({
  github,
  owner,
  repo,
  channelName,
}: {
  github: Octokit;
  owner: string;
  repo: string;
  channelName: string;
}) => {
  const openBackports = (await github.paginate(github.rest.issues.listForRepo, {
    owner,
    repo,
    labels: "was-backported",
    state: "open",
    per_page: 100,
  })) as Issue[];

  console.log(`Found ${openBackports.length} open backports`);

  const staleBackports = openBackports.filter(
    (issue) =>
      dayjs().diff(dayjs(issue.created_at), "hours") >
      RECENT_BACKPORT_THRESHOLD_HOURS,
  );

  if (!staleBackports.length) {
    console.log("No recent backports to remind about");
    return;
  }

  console.log(`Reminding about ${staleBackports.length} stale backports`);

  sendBackportReminder({
    channelName,
    backports: staleBackports,
  });
};