~james/core

ref: 452f17b75181d62d1d92016edecd38e1d70fecab core/web/src/lib/github.ts -rw-r--r-- 1.8 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 17 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
export interface GitHubKey {
	id: number;
	key: string;
	title: string;
}

type GitHubRepoVisibility = "public" | "private" | "internal";

export interface GitHubRepo {
	id: number;
	name: string;
	fullName: string;
	description: string | null;
	cloneUrl: string;
	htmlUrl: string;
	defaultBranch: string;
	visibility?: GitHubRepoVisibility;
	private?: boolean;
	installationId?: number;
	language?: string | null;
	stars?: number | null;
	issues?: number | null;
	forks?: number | null;
	updatedAt?: string | null;
	// github reports repo size in kb
	sizeKb?: number | null;
}

interface GitHubEmail {
	address: string;
	primary: boolean;
	verified: boolean;
}

export interface GitHubAccount {
	login: string;
	avatarUrl: string;
	email: string | null;
	bio: string | null;
	blog: string | null;
	emails?: GitHubEmail[];
	keys: GitHubKey[];
	repos: GitHubRepo[];
	// localinfra stub runs on its own host instead of github.com
	publicOrigin: string;
}

export const GITHUB_ERRORS = {
	unavailable: "GitHub connections aren't available on this server.",
	signed_out: "Sign in to Tangled, then connect your GitHub account.",
	sign_in_expired: "The GitHub sign-in expired. Connect your GitHub account again.",
	install_expired: "The GitHub app installation expired. Connect your GitHub account again.",
	denied: "GitHub access wasn't granted. Connect your GitHub account to continue.",
	failed: "Unable to connect to GitHub. Try connecting again.",
	return_unexpected:
		"Unable to return to the page you started from. Connect your GitHub account again."
} as const;

export type GitHubError = keyof typeof GITHUB_ERRORS;

export const githubErrorMessage = (code: string | null): string | null =>
	code === null
		? null
		: Object.hasOwn(GITHUB_ERRORS, code)
			? GITHUB_ERRORS[code as GitHubError]
			: GITHUB_ERRORS.failed;