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 { statusContext } from "./policy.mjs";

export function checkPublisher(github) {
  const ids = new Map();
  return async (sha, result) => {
    const body = {
      name: statusContext,
      status: result.state === "pending" ? "in_progress" : "completed",
      ...(result.state === "pending"
        ? {}
        : { conclusion: result.state === "success" ? "success" : "failure" }),
      details_url: `https://github.com/${github.repository}/blob/main/CONTRIBUTING.md#contribution-eligibility`,
      output: {
        title: result.description,
        summary: `${result.description}\n\n[Contribution rules](https://github.com/${github.repository}/blob/main/CONTRIBUTING.md#contribution-eligibility).`,
      },
    };
    const id = ids.get(sha);
    const check = await github.request(
      `repos/${github.repository}/check-runs${id ? `/${id}` : ""}`,
      {
        method: id ? "PATCH" : "POST",
        body: id ? body : { ...body, head_sha: sha },
      },
    );
    if (!Number.isSafeInteger(check.id) || check.id <= 0) {
      throw new Error("GitHub did not return a check run ID.");
    }
    ids.set(sha, check.id);
  };
}