Skip to content

g1t/packages/contracts/src/about.ts

122 lines3,706 bytesCodeBlame
1/**
2 * A repository's About, as its Files page shows it beside the files: its
3 * license, security policy and languages, its contributors, its stars and
4 * its releases. Mirrors `crates/contracts/src/about.rs`.
5 *
6 * What is read from files and history is worked out in the background for
7 * the default branch's head and kept by commit: an answer can be for an
8 * older commit (`commit` is not `head`) while the newer one is worked out,
9 * or `pending` when nothing has been worked out yet.
10 */
11import type { Repo } from "./repos";
12
13export type LanguageShare = {
14 name: string;
15 /** `#rrggbb`, the color it is known by. */
16 color: string | null;
17 bytes: number;
18 /** Of the bytes counted, to one decimal place. */
19 percent: number;
20};
21
22export type License = {
23 /** `MIT`, `Apache-2.0`; null when the text is not one g1t recognizes. */
24 spdxId: string | null;
25 /** "MIT License", or "Other". */
26 name: string;
27 /** The file it was read from: `LICENSE`. */
28 path: string;
29};
30
31/** `user`: matched to an account. `g1t`: g1t itself. `author`: the name on the commits. */
32export type ContributorKind = "user" | "g1t" | "author";
33
34/** Commits in the week starting on Monday `week` (`YYYY-MM-DD`, UTC). */
35export type WeekCommits = { week: string; commits: number };
36
37export type Contributor = {
38 kind: ContributorKind;
39 name: string;
40 username?: string | null;
41 avatar?: string | null;
42 commits: number;
43 firstAt: string;
44 lastAt: string;
45 /** Only for the most active contributors, on the Contributors page. */
46 weeks: WeekCommits[];
47};
48
49export type Freshness = {
50 /** The default branch's head; null for an empty repository. */
51 head: string | null;
52 /** The commit the answer was worked out for. */
53 commit: string | null;
54 computedAt: string | null;
55 /** Nothing worked out yet: ask again shortly. */
56 pending: boolean;
57 /** Too large to read in full: counts what was read. */
58 partial: boolean;
59};
60
61export type Languages = Freshness & { languages: LanguageShare[] };
62
63export type Contributors = Freshness & {
64 total: number;
65 /** The commits read. */
66 commits: number;
67 contributors: Contributor[];
68 /** Every commit read, by week, oldest first, empty weeks included. */
69 weeks: WeekCommits[];
70};
71
72export type Release = {
73 id: string;
74 tagName: string;
75 /** The commit the tag named. */
76 target: string;
77 name: string | null;
78 /** Markdown. */
79 body: string;
80 draft: boolean;
81 prerelease: boolean;
82 author: string | null;
83 createdAt: string;
84 /** Null while it is a draft. */
85 publishedAt: string | null;
86 latest: boolean;
87};
88
89export const MAX_RELEASE_NAME_CHARS = 200;
90export const MAX_RELEASE_BODY_CHARS = 125_000;
91
92export type Stargazer = { username: string; avatar: string | null; starredAt: string };
93export type StarredRepo = { repo: Repo; starredAt: string; stars: number };
94export type Stars = { starred: boolean; stars: number };
95
96export type RepoAbout = Freshness & {
97 license: License | null;
98 /** Path of SECURITY.md, when it has one. */
99 securityPolicy: string | null;
100 languages: LanguageShare[];
101 /** How many contributors there are. */
102 contributors: number;
103 /** The most active, without their weeks. */
104 topContributors: Contributor[];
105 stars: number;
106 starred: boolean;
107 /** Releases the viewer can see. */
108 releases: number;
109 latestRelease: Release | null;
110};
111
112export type NewRelease = {
113 tagName: string;
114 /** A branch or commit for a tag that does not exist yet; the default branch when absent. */
115 target?: string | null;
116 name?: string | null;
117 body?: string | null;
118 draft?: boolean;
119 prerelease?: boolean;
120};
121
122export type ReleaseChange = { name?: string; body?: string; draft?: boolean; prerelease?: boolean };