Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/hooks/useGitHubData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ interface FetchFilters {
state?: string;
}

type PaginatedSearchResult = {
items: GitHubItem[];
total: number;
};

export const useGitHubData = (
getOctokit: () => Octokit | null
) => {
Expand All @@ -43,36 +48,44 @@ export const useGitHubData = (
perPage = 10,
filters: FetchFilters = {}
) => {
let q = `author:${username} is:${type}`;
const queryParts: string[] = [
`author:${username}`,
`is:${type}`,
];

if (filters.search) {
q += ` ${filters.search} in:title`;
const escapedSearch =
filters.search.trim().replace(/"/g, '\\"');
queryParts.push(`in:title:"${escapedSearch}"`);
}

if (filters.repo) {
q += ` repo:${filters.repo}`;
queryParts.push(`repo:${filters.repo}`);
}

if (filters.startDate) {
q += ` created:>=${filters.startDate}`;
queryParts.push(`created:>=${filters.startDate}`);
}

if (filters.endDate) {
q += ` created:<=${filters.endDate}`;
queryParts.push(`created:<=${filters.endDate}`);
}

if (filters.state === 'open' || filters.state === 'closed') {
q += ` is:${filters.state}`;
queryParts.push(`is:${filters.state}`);
}

if (filters.state === 'merged' && type === 'pr') {
q += ` is:merged`;
queryParts.push('is:merged');
}

const q = queryParts.join(' AND ');

const response = await octokit.request(
'GET /search/issues',
{
q,
advanced_search: true,
sort: 'created',
order: 'desc',
per_page: perPage,
Expand Down Expand Up @@ -112,7 +125,7 @@ export const useGitHubData = (
const shouldFetchPrs =
activeTab === 'pr' || activeTab === 'both';

const requests: Promise<any>[] = [];
const requests: Promise<PaginatedSearchResult>[] = [];

if (shouldFetchIssues) {
requests.push(
Expand Down
15 changes: 13 additions & 2 deletions src/pages/ContributorProfile/ContributorProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ export default function ContributorProfile() {
const userData = await userRes.json();
setProfile(userData);

const searchParams = new URLSearchParams({
q: `author:${username} AND is:pr`,
advanced_search: "true",
});

const prsRes = await fetch(
`https://api.github.com/search/issues?q=author:${username}+type:pr`
`https://api.github.com/search/issues?${searchParams.toString()}`
);

if (!prsRes.ok) {
setPRs([]);
return;
}

const prsData = await prsRes.json();
setPRs(prsData.items);
setPRs(prsData.items || []);
} catch {
toast.error("Failed to fetch user data.");
} finally {
Expand Down