-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.ts
66 lines (58 loc) · 1.37 KB
/
github.ts
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
// @deno-types="npm:@octokit/[email protected]"
import { Octokit } from "npm:@octokit/[email protected]";
import { repoInfo } from "./globals.ts";
const githubToken = Deno.env.get("GITHUB_AUTH_TOKEN");
if (githubToken == null) {
console.warn(
"GITHUB_AUTH_TOKEN not set, GitHub functions will be more strictly rate limited."
);
}
const octokit = new Octokit({ auth: githubToken });
export type Commit = {
sha: string;
commit: {
message: string;
};
html_url: string;
files: {
filename: string;
}[];
};
export async function getCommit(commitUrl: string): Promise<Commit> {
const response = await octokit.request(commitUrl);
return response.data;
}
export type Comparison = {
status: string;
ahead_by: number;
behind_by: number;
commits: {
sha: string;
html_url: string;
url: string;
commit: {
message: string;
};
}[];
files: {
filename: string;
};
};
export async function getComparison(
base: string,
head: string
): Promise<Comparison> {
const response = await octokit.request(
"GET /repos/{owner}/{repo}/compare/{base}...{head}",
{
owner: repoInfo.owner,
repo: repoInfo.repo,
base: base,
head: head,
}
);
return response.data;
}
export function getLinkForPullRequest(pullRequest: string): string {
return `https://github.com/${repoInfo.owner}/${repoInfo.repo}/pull/${pullRequest}`;
}