Skip to content

Commit

Permalink
Remove octokit dependency (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonulak authored Jan 8, 2025
1 parent be8bf83 commit 0b28edb
Show file tree
Hide file tree
Showing 6 changed files with 9,514 additions and 191 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:
branches: [main, master]
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
test:
timeout-minutes: 60
Expand Down
158 changes: 0 additions & 158 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@ai-sdk/azure": "^1.0.7",
"@googlemaps/react-wrapper": "^1.1.35",
"@googlemaps/typescript-guards": "^2.0.1",
"@octokit/rest": "^21.0.2",
"@playwright/test": "^1.49.0",
"@radix-ui/react-dialog": "^1.1.4",
"@radix-ui/react-icons": "^1.3.0",
Expand Down
79 changes: 48 additions & 31 deletions src/lib/github.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Octokit } from "@octokit/rest";
import { VWCContributor, GithubRepo, GithubContributor } from "@utils/types";
import { VWCContributor, GithubRepo, GithubContributor, GithubUser } from "@utils/types";
import axios from "axios";

const token = process.env.GITHUB_ACCESS_TOKEN || "";
const octokit = new Octokit({ auth: token });
const token = process.env.GITHUB_TOKEN || "";
const git_api = axios.create({
baseURL: "https://api.github.com",
headers: {
Authorization: `Bearer ${token}`,
},
});

export const getProjectContributors = async (
owner: string,
Expand All @@ -12,48 +17,60 @@ export const getProjectContributors = async (
const topContributors = await getGithubRepoContributors(owner, repo, top);
const projectContributors = Promise.all(
topContributors.map(async (contributor) => {
const user = await octokit.rest.users.getByUsername({
username: contributor.login,
});
if (user.data.name) {
const response = await git_api.get(`/users/${contributor.login}`);
if (response.status == 200) {
const user = response.data as GithubUser;
return {
...contributor,
...user.data,
name: user.data.name!,
...user,
};
} else {
if ("error" in response) {
throw new Error(
`Error fetching user data for ${contributor.login}\nStatus code: ${response.status}\nError: ${response.error}`
);
}
throw new Error(
`Error fetching user data for ${contributor.login}\nStatus code: ${response.status}`
);
}
return;
})
);
return (await projectContributors).filter((contributor) => contributor !== undefined);
return await projectContributors;
};

export const getGithubRepo = async (owner: string, repo: string): Promise<GithubRepo> => {
const response = await octokit.rest.repos.get({
owner: owner,
repo: repo,
});
return response.data;
const response = await git_api.get(`/repos/${owner}/${repo}`);
if (response.status == 200) {
return response.data as GithubRepo;
} else {
if ("error" in response) {
throw new Error(
`Error fetching repo data for ${owner}/${repo}\nStatus code: ${response.status}\nError: ${response.error}`
);
}
throw new Error(
`Error fetching repo data for ${owner}/${repo}\nStatus code: ${response.status}`
);
}
};

export const getGithubRepoContributors = async (
owner: string,
repo: string,
top: number = 4
): Promise<GithubContributor[]> => {
const response = await octokit.rest.repos.listContributors({
owner: owner,
repo: repo,
per_page: top,
});
const contributors = response.data.map((contributor) => {
if (contributor.login) {
return {
...contributor,
login: contributor.login!,
};
const response = await git_api.get(`/repos/${owner}/${repo}/contributors`);
if (response.status == 200) {
return (response.data as GithubContributor[]).slice(0, top);
} else {
if ("error" in response) {
throw new Error(
`Error fetching contributor data for ${owner}/${repo}\nStatus code: ${response.status}\nError: ${response.error}`
);
}
return;
});
return contributors.filter((contributor) => contributor !== undefined);
throw new Error(
`Error fetching contributor data for ${owner}/${repo}\nStatus code: ${response.status}`
);
}
};
Loading

0 comments on commit 0b28edb

Please sign in to comment.