Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

1.1 KB
Raw Blame
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono";
import { HttpError } from "@/lib/http-error";

export type ImportGithubIssuesRequest = InferRequestType<
  (typeof client)["github-integration"]["import-issues"]["$post"]
>["json"];

async function importGithubIssues(data: ImportGithubIssuesRequest) {
  let runId = data.runId;
  let busyRetries = 0;
  for (;;) {
    const response = await client["github-integration"]["import-issues"].$post({
      json: { ...data, runId },
    });
    if (response.status === 429 && busyRetries < 5) {
      busyRetries++;
      await new Promise((resolve) => setTimeout(resolve, 1000));
      continue;
    }
    if (!response.ok) throw await HttpError.fromResponse(response);
    const result = await response.json();
    if (response.status !== 202) return result;
    runId = result.runId;
    busyRetries = 0;
    // The server persists each page. A later call can resume even after the
    // browser closes; retries of a completed run do not start another import.
  }
}
export default importGithubIssues;