275 lines · 10.0 KB
import { all, first } from "./db";
import { repoDb } from "./scoped-db";
import { NOT_TAKEN_DOWN_SQL, repoReadableSql } from "./repos";
import { activityRepoIds, filterRepoIds } from "./activity-index";

const DAY_MS = 24 * 60 * 60 * 1000;
const GRAPH_WEEKS = 52;
const WEEK_DAYS = 7;
const MAX_DAY_REPOS = 3;
const MIN_GRAPH_YEAR = 1970;

/**
 * What a viewer may see of private repositories: `full` for the account itself, `counts` for visitors
 * when the user opted in (numbers only, never repo names or titles), `none` otherwise.
 */
export type PrivateMode = "full" | "counts" | "none";

export type ContributionBreakdown = {
  commits: number;
  pulls: number;
  issues: number;
  reviews: number;
  other: number;
  /** Anonymized contributions to private repositories (`counts` mode only). */
  private: number;
};

export type ContributionDay = {
  date: string;
  count: number;
  breakdown: ContributionBreakdown | null;
  repos: string[];
};

type Category = Exclude<keyof ContributionBreakdown, "private">;

/** Verified addresses of a user (bound as ?1); commits authored with any of them count as theirs. */
export const VERIFIED_EMAILS = `SELECT email FROM users WHERE account_id = ?1 AND email_verified_at IS NOT NULL
  UNION SELECT email FROM user_emails WHERE user_id = ?1 AND verified_at IS NOT NULL`;