Skip to content

Commit

Permalink
Update scrapper to track direct commits to branch and show in contrbu…
Browse files Browse the repository at this point in the history
…tor's page
  • Loading branch information
dgparmar14 committed Apr 9, 2024
1 parent 7c0bbf1 commit 114ba05
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 28 deletions.
33 changes: 18 additions & 15 deletions components/contributors/GithubActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { usePathname, useRouter, useSearchParams } from "next/navigation";
import RelativeTime from "../RelativeTime";
import DateRangePicker from "../DateRangePicker";
import { format } from "date-fns";
import Link from "next/link";

let commentTypes = (activityEvent: string[]) => {
switch (activityEvent[0]) {
Expand Down Expand Up @@ -161,33 +162,34 @@ let renderText = (activity: Activity) => {
</div>
</div>
);
case "commit_direct":
case "pushed_commits":
return (
<div className="min-w-0 flex-1">
<div>
<p className="font-bold">
{"Direct Commit to "}
{activity["branch"]}
{" in "}
<span className="text-primary-400 dark:text-primary-300">
{activity["link"].split("/").slice(3, 5).join("/")}
</span>

{activity.title}
<span className="text-foreground">
{" "}
<RelativeTime time={timestamp} />
<RelativeTime time={activity.time} />
</span>
</p>
</div>
<div className="mt-2 rounded-lg border border-secondary-600 p-2 md:p-4">
<a href={activity["link"]} target="_blank">
<span className="cursor-pointer break-words text-sm font-medium text-foreground hover:text-primary-500">
{activity["text"]}
</span>
</a>
{activity?.commits?.map((commit, index) => (
<div key={index} className="mb-2 flex items-center">
<Link href={commit.link} target="_blank" className="flex gap-1">
<span className="text-sm font-medium text-foreground">
{index + 1}.
</span>{" "}
<span className="cursor-pointer break-words text-sm font-medium text-foreground hover:text-primary-500">
{commit.text}
</span>
</Link>
</div>
))}
</div>
</div>
);

default:
return (
<div className="min-w-0 flex-1 py-1.5">
Expand Down Expand Up @@ -508,6 +510,7 @@ export const ActivityCheckbox = (props: {
pr_opened: "PR opened",
pr_reviewed: "Code Review",
commit_direct: "Direct Commit",
pushed_commits: "Pushed Commits",
}[props.type]
}
<span className="text-xs text-secondary-500 dark:text-secondary-400">
Expand Down
4 changes: 2 additions & 2 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ const points = {
pr_merged: 7,
pr_collaborated: 2,
issue_closed: 0,
commit_direct: 2,
pushed_commits: 0,
};
// Comments will get a single point
// Picking up an issue would get a point
// Reviewing a PR would get 4 points
// Finding a bug would add up to 4 points
// Opening a PR would give a single point and merging it would give you the other 7 points, making 8 per PR
// Updating the EOD would get 2 points per day and additional 20 for regular daily updates plus 10 for just missing one
// Push direct commmmit have two points
// pushed commits directly to the repository would not be counted as of now
function formatSlug(slug: string) {
return slug.replace(/\.md$/, "");
}
Expand Down
9 changes: 7 additions & 2 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,21 @@ export const ACTIVITY_TYPES = [
"pr_opened",
"pr_merged",
"pr_collaborated",
"commit_direct",
"pushed_commits",
] as const;

export interface commit {
link: string;
text: string;
}

export interface Activity {
type: (typeof ACTIVITY_TYPES)[number];
title: string;
time: string;
link: string;
text: string;
branch?: string;
commits?: commit[];
collaborated_with?: string[];
turnaround_time?: number;
}
Expand Down
25 changes: 16 additions & 9 deletions scraper/src/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,30 +172,37 @@ def parse_event(self, event, event_time):
)

elif event["type"] == "PushEvent":
repoOwner = "coronasafe"
reponame = event["repo"]["name"].split('/')[-1]
branch = event["payload"]["ref"].split('/')[-1]
commits = event["payload"]["commits"]
# defaultBranchName = self.get_default_banch(repoOwner, reponame)
all_commits = []

# Iterate through each commit
for commit in commits:
# Fetch full commit details
commit_details = requests.get(commit["url"], headers=self.headers).json()

if len(commit_details.get("parents", [])) in [0, 1]:
# Prepare commit data
commit_data = {
"title": f'{event["repo"]["name"]}#{commit["sha"]}',
"link": commit["url"],
"link": commit_details["html_url"],
"text": commit["message"],
}
all_commits.append(commit_data) # Append commit data to the array
print(all_commits)
# Append commit data to the array
all_commits.append(commit_data)

# Append pushed commits event
self.append(
user,
{
"type": "commit_direct",
"type": "pushed_commits",
"time": event_time,
"title": f'Pushed({len(commits)}) to {event["repo"]["name"]}({branch})',
"title": f'Pushed({len(all_commits)}) commits to {event["repo"]["name"]}({branch})',
"commits": all_commits,
},
)



def add_collaborations(self, event, event_time):
collaborators = set()

Expand Down

0 comments on commit 114ba05

Please sign in to comment.