Skip to content

Commit 0b28edb

Browse files
authored
Remove octokit dependency (#681)
1 parent be8bf83 commit 0b28edb

File tree

6 files changed

+9514
-191
lines changed

6 files changed

+9514
-191
lines changed

.github/workflows/playwright.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
pull_request:
66
branches: [main, master]
77
env:
8-
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99
jobs:
1010
test:
1111
timeout-minutes: 60

package-lock.json

Lines changed: 0 additions & 158 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"@ai-sdk/azure": "^1.0.7",
2121
"@googlemaps/react-wrapper": "^1.1.35",
2222
"@googlemaps/typescript-guards": "^2.0.1",
23-
"@octokit/rest": "^21.0.2",
2423
"@playwright/test": "^1.49.0",
2524
"@radix-ui/react-dialog": "^1.1.4",
2625
"@radix-ui/react-icons": "^1.3.0",

src/lib/github.ts

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { Octokit } from "@octokit/rest";
2-
import { VWCContributor, GithubRepo, GithubContributor } from "@utils/types";
1+
import { VWCContributor, GithubRepo, GithubContributor, GithubUser } from "@utils/types";
2+
import axios from "axios";
33

4-
const token = process.env.GITHUB_ACCESS_TOKEN || "";
5-
const octokit = new Octokit({ auth: token });
4+
const token = process.env.GITHUB_TOKEN || "";
5+
const git_api = axios.create({
6+
baseURL: "https://api.github.com",
7+
headers: {
8+
Authorization: `Bearer ${token}`,
9+
},
10+
});
611

712
export const getProjectContributors = async (
813
owner: string,
@@ -12,48 +17,60 @@ export const getProjectContributors = async (
1217
const topContributors = await getGithubRepoContributors(owner, repo, top);
1318
const projectContributors = Promise.all(
1419
topContributors.map(async (contributor) => {
15-
const user = await octokit.rest.users.getByUsername({
16-
username: contributor.login,
17-
});
18-
if (user.data.name) {
20+
const response = await git_api.get(`/users/${contributor.login}`);
21+
if (response.status == 200) {
22+
const user = response.data as GithubUser;
1923
return {
2024
...contributor,
21-
...user.data,
22-
name: user.data.name!,
25+
...user,
2326
};
27+
} else {
28+
if ("error" in response) {
29+
throw new Error(
30+
`Error fetching user data for ${contributor.login}\nStatus code: ${response.status}\nError: ${response.error}`
31+
);
32+
}
33+
throw new Error(
34+
`Error fetching user data for ${contributor.login}\nStatus code: ${response.status}`
35+
);
2436
}
25-
return;
2637
})
2738
);
28-
return (await projectContributors).filter((contributor) => contributor !== undefined);
39+
return await projectContributors;
2940
};
3041

3142
export const getGithubRepo = async (owner: string, repo: string): Promise<GithubRepo> => {
32-
const response = await octokit.rest.repos.get({
33-
owner: owner,
34-
repo: repo,
35-
});
36-
return response.data;
43+
const response = await git_api.get(`/repos/${owner}/${repo}`);
44+
if (response.status == 200) {
45+
return response.data as GithubRepo;
46+
} else {
47+
if ("error" in response) {
48+
throw new Error(
49+
`Error fetching repo data for ${owner}/${repo}\nStatus code: ${response.status}\nError: ${response.error}`
50+
);
51+
}
52+
throw new Error(
53+
`Error fetching repo data for ${owner}/${repo}\nStatus code: ${response.status}`
54+
);
55+
}
3756
};
3857

3958
export const getGithubRepoContributors = async (
4059
owner: string,
4160
repo: string,
4261
top: number = 4
4362
): Promise<GithubContributor[]> => {
44-
const response = await octokit.rest.repos.listContributors({
45-
owner: owner,
46-
repo: repo,
47-
per_page: top,
48-
});
49-
const contributors = response.data.map((contributor) => {
50-
if (contributor.login) {
51-
return {
52-
...contributor,
53-
login: contributor.login!,
54-
};
63+
const response = await git_api.get(`/repos/${owner}/${repo}/contributors`);
64+
if (response.status == 200) {
65+
return (response.data as GithubContributor[]).slice(0, top);
66+
} else {
67+
if ("error" in response) {
68+
throw new Error(
69+
`Error fetching contributor data for ${owner}/${repo}\nStatus code: ${response.status}\nError: ${response.error}`
70+
);
5571
}
56-
return;
57-
});
58-
return contributors.filter((contributor) => contributor !== undefined);
72+
throw new Error(
73+
`Error fetching contributor data for ${owner}/${repo}\nStatus code: ${response.status}`
74+
);
75+
}
5976
};

0 commit comments

Comments
 (0)