Skip to content

Commit

Permalink
fix: update repo ID in getMergedPullRequestsByGithubLogin function
Browse files Browse the repository at this point in the history
  • Loading branch information
RA9 committed Jun 3, 2024
1 parent 3e7c8a0 commit 91c6b85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/[githubLogin]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default async function ProfilePage({ params }) {
if (user) {
const userEnrollments = await getEnrolledRepositories(user?.id);

const repos = userEnrollments.length > 0 ? [...userEnrollments].map((repo) => repo.name) : null; // get repo names from userEnrollments
const repos = userEnrollments.length > 0 ? [...userEnrollments].map((repo) => repo.githubId) : null; // get repo names from userEnrollments
const [githubUserData, mergedIssues, openPRs] = await Promise.all([
getGithubUserByLogin(githubLogin).then(
(data) => data || { name: "Rick", avatar_url: Rick, bio: "is never gonna give you up 🕺" }
Expand Down
17 changes: 9 additions & 8 deletions lib/github/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { unstable_cache } from "next/cache";
import { GITHUB_APP_ACCESS_TOKEN, GITHUB_CACHE_REVALIDATION_INTERVAL, OSS_GG_LABEL } from "../constants";

export const getMergedPullRequestsByGithubLogin = async (
repos: Array<string> | null,
repos: Array<number> | null,
githubLogin: string
) => {
if (!repos || repos.length === 0) {
Expand All @@ -22,10 +22,10 @@ export const getMergedPullRequestsByGithubLogin = async (
isIssue: boolean;
}> = [];

for (const repoName of repos) {
for (const repoId of repos) {
await unstable_cache(
async () => {
const url = `https://api.github.com/search/issues?q=repo:${repoName}+is:pull-request+is:merged+author:${githubLogin}&per_page=10&sort=created&order=desc`;
const url = `https://api.github.com/search/issues?q=repository_id:${repoId}+is:pull-request+is:merged+author:${githubLogin}&per_page=10&sort=created&order=desc`;

const headers = {
Authorization: `Bearer ${GITHUB_APP_ACCESS_TOKEN}`,
Expand All @@ -47,9 +47,10 @@ export const getMergedPullRequestsByGithubLogin = async (
isIssue: false,
}))
);

return mergedPRs;
},
[`getMergedPullRequests-${repoName}-${githubLogin}`],
[`getMergedPullRequests-${repoId}-${githubLogin}`],
{
revalidate: GITHUB_CACHE_REVALIDATION_INTERVAL,
}
Expand All @@ -59,7 +60,7 @@ export const getMergedPullRequestsByGithubLogin = async (
return mergedPRs;
};

export const getOpenPullRequestsByGithubLogin = async(repos: Array<string> | null, githubLogin: string) => {
export const getOpenPullRequestsByGithubLogin = async(repos: Array<number> | null, githubLogin: string) => {
if (!repos || repos.length === 0) {
return Promise.resolve([]);
}
Expand All @@ -75,10 +76,10 @@ export const getOpenPullRequestsByGithubLogin = async(repos: Array<string> | nul
isIssue: boolean;
}> = [];

for (const repo of repos) {
for (const repoId of repos) {
await unstable_cache(
async () => {
const url = `https://api.github.com/search/issues?q=repo:${repo}+is:pull-request+is:open+author:${githubLogin}&sort=created&order=desc`;
const url = `https://api.github.com/search/issues?q=repository_id:${repoId}+is:pull-request+is:open+author:${githubLogin}&sort=created&order=desc`;

const headers = {
Authorization: `Bearer ${GITHUB_APP_ACCESS_TOKEN}`,
Expand All @@ -105,7 +106,7 @@ export const getOpenPullRequestsByGithubLogin = async(repos: Array<string> | nul

return openPRs;
},
[`getOpenPullRequests-${repo}-${githubLogin}`],
[`getOpenPullRequests-${repoId}-${githubLogin}`],
{
revalidate: GITHUB_CACHE_REVALIDATION_INTERVAL,
}
Expand Down

0 comments on commit 91c6b85

Please sign in to comment.