Skip to content

Commit

Permalink
refactor: ⚡ change file name to adhere to the project's conventions a…
Browse files Browse the repository at this point in the history
…nd add comments for functions
  • Loading branch information
indralukmana committed Aug 30, 2024
1 parent 472d13c commit fc13730
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/nextjs/components/BuildersActivities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import Link from "next/link";
import { HiFire, HiOutlineFire } from "react-icons/hi2";
import { RiShareBoxLine } from "react-icons/ri";
import { getBuildersGitHubActivities } from "~~/components/github-activities/data-fetches";
import { getBuildersGitHubActivities } from "~~/components/github-activities/dataFetches";
import { Address } from "~~/components/scaffold-eth";

const BuildersActivities = async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { octokit } from "./octokit";
import fs from "fs/promises";
import path from "path";
import { prCountQuery, repoIssueQuery, userQuery } from "~~/components/github-activities/github-queries";
import { prCountQuery, repoIssueQuery, userQuery } from "~~/components/github-activities/githubQueries";
import {
BuilderData,
BuilderDataMap,
BuilderGitHubUsernameQueryResponse,
QueryPRCountResponse,
RepoIssueQueryResponse,
} from "~~/components/github-activities/github-queries-types";
} from "~~/components/github-activities/githubQueriesTypes";

const OWNER = "BuidlGuidl";
const REPO = "batch8.buidlguidl.com";

// Get the builders directory data
// Get the builders directory data from /app/builders
export const getBuildersPages = async (): Promise<string[]> => {
const buildersDirectory = path.join(process.cwd(), "/app/builders");
const files = await fs.readdir(buildersDirectory);
const addresses = files.filter(file => file.startsWith("0x"));
return addresses;
};

// Get GitHub username for a builder
// Get GitHub username for a builder' wallet by looking at the initial commit
// of their profile page under /app/builders/[address]/page.tsx
export const getBuilderGitHubUsername = async (builderAddress: string): Promise<string | null> => {
try {
const result = await octokit.graphql<BuilderGitHubUsernameQueryResponse>(userQuery, {
Expand All @@ -37,7 +38,8 @@ export const getBuilderGitHubUsername = async (builderAddress: string): Promise<
}
};

// Get PR data for all builders
// Get PR data for all builders using the GitHub GraphQL API
// The data includes the number of open, closed, and merged PRs
export const getBuildersPRData = async (builderDataMap: BuilderDataMap): Promise<BuilderDataMap> => {
const repoPRs = await octokit.graphql<QueryPRCountResponse>(prCountQuery, {
owner: OWNER,
Expand All @@ -62,6 +64,10 @@ export const getBuildersPRData = async (builderDataMap: BuilderDataMap): Promise
return newBuilderDataMap;
};

// Get issue activities for all builders using the GitHub GraphQL API
// the activities include:
// - commented issues
// - reacted issues
export const getBuildersIssueActivities = async (builderDataMap: BuilderDataMap): Promise<BuilderDataMap> => {
const repoIssues = await octokit.graphql<RepoIssueQueryResponse>(repoIssueQuery, {
owner: OWNER,
Expand Down Expand Up @@ -92,6 +98,8 @@ export const getBuildersIssueActivities = async (builderDataMap: BuilderDataMap)
return newBuilderDataMap;
};

// Calculate the GitHub score for a builder based on the number of PRs and issues.
// The numbers are weighted based on the importance of the activity.
const githubScore = (builderData: BuilderData) => {
const CLOSED_PR_WEIGHT = 1;
const OPEN_PR_WEIGHT = 0.5;
Expand All @@ -110,6 +118,7 @@ const githubScore = (builderData: BuilderData) => {
return prScore + issueScore;
};

// Calculate the GitHub score for all builders
const getBuildersGitHubScore = (builderDataMap: BuilderDataMap): BuilderDataMap => {
const newBuilderDataMap = new Map(builderDataMap);

Expand All @@ -122,6 +131,8 @@ const getBuildersGitHubScore = (builderDataMap: BuilderDataMap): BuilderDataMap

return newBuilderDataMap;
};

// Get all the builders' GitHub activities
export const getBuildersGitHubActivities = async (): Promise<BuilderDataMap> => {
const buildersAddresses = await getBuildersPages();
const builderDataMap = new Map<string, BuilderData>();
Expand Down

0 comments on commit fc13730

Please sign in to comment.