-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test-d.ts
More file actions
56 lines (44 loc) · 1.49 KB
/
Copy pathindex.test-d.ts
File metadata and controls
56 lines (44 loc) · 1.49 KB
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
import { expectError, expectType } from "tsd";
import {
parseGitHubUrl,
type GitHubIssueInfo,
type ParsedGitHubUrl,
} from ".";
const parsed = parseGitHubUrl("https://github.com/user/repo/issues/123");
expectType<ParsedGitHubUrl | null>(parsed);
if (parsed?.kind === "issue") {
expectType<GitHubIssueInfo>(parsed);
expectType<number>(parsed.number);
expectType<null>(parsed.committish);
expectType<string>(parsed.apiUrl);
expectError(parsed.sha);
}
const blob = parseGitHubUrl("https://github.com/user/repo/blob/main/src/index.js");
if (blob?.kind === "blob") {
expectType<string>(blob.ref);
expectType<string>(blob.path);
expectType<string>(blob.rawUrl);
expectType<string>(blob.committish);
expectError(blob.number);
}
const tree = parseGitHubUrl("https://github.com/user/repo/tree/main/src");
if (tree?.kind === "tree") {
expectType<string>(tree.ref);
expectType<string>(tree.path);
expectType<null>(tree.rawUrl);
}
const compare = parseGitHubUrl("https://github.com/user/repo/compare/main...dev");
if (compare?.kind === "compare") {
expectType<string>(compare.range);
expectType<string>(compare.baseRef);
expectType<string>(compare.headRef);
}
const workflowRun = parseGitHubUrl(
"https://github.com/user/repo/actions/runs/123456789"
);
if (workflowRun?.kind === "workflow-run") {
expectType<number>(workflowRun.runId);
expectType<string>(workflowRun.apiUrl);
expectError(workflowRun.number);
}
expectType<ParsedGitHubUrl | null>(parseGitHubUrl("not a github url"));