Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter repos in projects page by ucla-opensource tag #155

Merged
merged 5 commits into from
Mar 4, 2024
Merged
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
Binary file added public/ucla-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/fixtures/gfiProjects.json

Large diffs are not rendered by default.

38 changes: 26 additions & 12 deletions util/projectRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ import { Project, ACMCommitteeTopics, GitHubColors, GitHubRepo, GitHubIssue, GFI
export async function getProjects(): Promise<Project[]> {
const PaginatedOctokit = Octokit.plugin(paginateRest);
const octokit = new PaginatedOctokit();
const projectsResponse = await octokit.paginate('GET /orgs/{org}/repos', {
org: 'uclaacm',
const queryString = 'ucla-opensource in:topics';
const searchResponse = await octokit.paginate('GET /search/repositories', {
q: queryString,
per_page: 100,
});
}) as GitHubRepo[];

const projects = mapReposToProjects(projectsResponse);
const projects = mapReposToProjects(searchResponse);
return projects;
}

//search uclaacm org for good first issues, repos which contain gfis, and match them up
export async function getGoodFirstIssueProjects(): Promise<GFIProject[]> {
const PaginatedOctokit = Octokit.plugin(paginateRest);
const octokit = new PaginatedOctokit();
const gfiIssuesSearchQuery = 'org:uclaacm+label:"good+first+issue"+is:open';
const gfiIssuesSearchQuery = 'ucla-opensource in:topics+label:"good+first+issue"+is:open';
const gfiIssuesResponse = await octokit.paginate('GET /search/issues', {
q: gfiIssuesSearchQuery,
}) as GitHubIssue[];
const gfiReposSearchQuery = 'good-first-issues:>0+org:uclaacm';
const gfiReposSearchQuery = 'ucla-opensource in:topics+good-first-issues:>0';
const gfiReposResponse = await octokit.paginate('GET /search/repositories', {
q: gfiReposSearchQuery,
}) as GitHubRepo[];
Expand Down Expand Up @@ -59,10 +60,12 @@ function mapIssuesToProjects(issues: GitHubIssue[], repoMap: Map<string, GitHubR
while(!itVal.done){
const [repoUrl, repoIssues] = itVal.value;
const correspondingRepo = repoMap.get(repoUrl);

if(!correspondingRepo){
//console.error('Repo Map went wrong!');
// console.error('Repo Map went wrong!');
return gfis;
}

const correspondingProject = convertRepoToProject(correspondingRepo);
gfis.push({
issues: repoIssues,
Expand All @@ -83,17 +86,17 @@ function convertRepoToProject(repo: GitHubRepo): Project {
repo: repo.html_url,
lang: repo.language ?? '',
topics: repo.topics ?? [],
image: getImageFromTopics(repo.topics).image,
alt: getImageFromTopics(repo.topics).alt,
image: getImageFromRepo(repo).image,
alt: getImageFromRepo(repo).alt,
}
: {
name: repo.name,
description: repo.description ?? '',
repo: repo.html_url ?? '',
lang: repo.language ?? '',
topics: repo.topics ?? [],
image: getImageFromTopics(repo.topics).image,
alt: getImageFromTopics(repo.topics).alt,
image: getImageFromRepo(repo).image,
alt: getImageFromRepo(repo).alt,
};
}

Expand Down Expand Up @@ -169,7 +172,18 @@ function topicToImg(topic: string): ImageInfo | false {
}
}

export function getImageFromTopics(topics: string[] | undefined): ImageInfo {
export function getImageFromRepo(repo: GitHubRepo): ImageInfo {
if (repo.owner.login === 'uclaacm') {
return getACMImageFromTopics(repo.topics);
} else {
return {
image: '/ucla-logo.png',
alt: 'No logo shown',
} as ImageInfo;
}
}

function getACMImageFromTopics(topics: string[] | undefined): ImageInfo {
if (topics) {
for (const topic of topics) {
const committeeImg = topicToImg(topic);
Expand Down
Loading