Skip to content

Commit

Permalink
Fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dgparmar14 committed Jul 1, 2024
1 parent 2dc5b94 commit 7ea2a3f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
Binary file added public/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 scraper/src/github-scraper/fetchUserData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const fetchOpenPulls = async (user: string, org: string) => {
link: pr.html_url,
title: pr.title,
stale_for: staleFor,
labels: pr.labels.map((label: { name: string }) => label.name),
labels: pr.labels.map((label: { name?: string }) => label.name),
};
});

Expand Down
5 changes: 2 additions & 3 deletions scraper/src/github-scraper/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatISO, parseISO, startOfDay, subDays } from "date-fns";
import { ProcessData } from "./types.js";
import { IGitHubEvent, ProcessData } from "./types.js";
import { fetchMergeEvents, fetchOpenPulls } from "./fetchUserData.js";
import { fetchEvents } from "./fetchEvents.js";
import { parseEvents } from "./parseEvents.js";
Expand All @@ -19,9 +19,8 @@ const scrapeGitHub = async (
console.log(
`Scraping GitHub data for ${org} from ${formatISO(startDate)} to ${formatISO(endDate)}`,
);

const events = await fetchEvents(org, startDate, endDate);
processedData = await parseEvents(events);
processedData = await parseEvents(events as IGitHubEvent[]);
for (const user of Object.keys(processedData)) {
if (!processedData[user]) {
processedData[user] = {
Expand Down
9 changes: 4 additions & 5 deletions scraper/src/github-scraper/parseEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { calculateTurnaroundTime } from "./utils.js";
import { parseISO } from "date-fns";
import { isBlacklisted } from "./utils.js";
import { octokit } from "./config.js";

const processedData: ProcessData = {};

function appendEvent(user: string, event: Activity) {
Expand Down Expand Up @@ -136,7 +135,7 @@ export const parseEvents = async (events: IGitHubEvent[]) => {
appendEvent(user, {
type: "comment_created",
title: `${event.repo.name}#${event.payload.issue.number}`,
time: eventTime.toISOString(),
time: eventTime?.toISOString(),
link: event.payload.comment.html_url,
text: event.payload.comment.body,
});
Expand All @@ -146,7 +145,7 @@ export const parseEvents = async (events: IGitHubEvent[]) => {
if (["opened", "assigned", "closed"].includes(event.payload.action)) {
appendEvent(user, {
type: `issue_${event.payload.action}`,
title: `${event.repo.name}#${event.payload.issue?.number}`,
title: `${event.repo.name}#${event.payload.issue.number}`,
time: eventTime.toISOString(),
link: event.payload.issue.html_url,
text: event.payload.issue.title,
Expand All @@ -170,7 +169,7 @@ export const parseEvents = async (events: IGitHubEvent[]) => {
appendEvent(user, {
type: "pr_merged",
title: `${event.repo.name}#${event.payload.pull_request.number}`,
time: eventTime.toISOString(),
time: eventTime?.toISOString(),
link: event.payload.pull_request.html_url,
text: event.payload.pull_request.title,
turnaround_time: turnaroundTime,
Expand All @@ -181,7 +180,7 @@ export const parseEvents = async (events: IGitHubEvent[]) => {
case "PullRequestReviewEvent":
appendEvent(user, {
type: "pr_reviewed",
time: eventTime.toISOString(),
time: eventTime?.toISOString(),
title: `${event.repo.name}#${event.payload.pull_request.number}`,
link: event.payload.review.html_url,
text: event.payload.pull_request.title,
Expand Down
2 changes: 1 addition & 1 deletion scraper/src/github-scraper/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export interface OpenPr {
link: string;
title: string;
stale_for: number;
labels: string[];
labels: (string | undefined)[];
}

export interface AuthoredIssueAndPr {
Expand Down
8 changes: 3 additions & 5 deletions scraper/src/github-scraper/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ export async function calculateTurnaroundTime(event: PullRequestEvent) {
`GET ${event.payload?.pull_request?.issue_url}`,
);
// Fetch url all linked issues url from the response
// What if the issue was cross-referenced from another repository than the repository of the PR made also add this feature
linkedIssues.push([event.repo.name, `#${linkedIssuesResponse.data.number}`]);

// Fetch issue events to find cross-referenced issues
const issueEventsUrl = linkedIssuesResponse.data.events_url;
const issueEventsUrl = await linkedIssuesResponse.data.events_url;
const issueEventsResponse = await octokit.request(`GET ${issueEventsUrl}`);

type issueEvent = typeof issueEventsResponse.data;
Expand Down Expand Up @@ -97,9 +96,8 @@ export async function calculateTurnaroundTime(event: PullRequestEvent) {
issue_number: issueNumber,
},
);

const issueTimeline = issueTimelineResponse.data;
issueTimeline.forEach((action: Action) => {
type Action = (typeof issueTimelineResponse.data)[0];
issueTimelineResponse.data.forEach((action: Action) => {
if (action.event === "assigned" && action.assignee.login === user) {
assignedAts.push({
issue: `${org}/${repo}#${issueNumber}`,
Expand Down

0 comments on commit 7ea2a3f

Please sign in to comment.