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

Track commit directly to branch without pr #428

1 change: 1 addition & 0 deletions app/feed/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default async function FeedPage({ searchParams }: Props) {
if (!Object.entries(events).length) {
return <LoadingText text="Fetching latest events" />;
}

return (
<div className="relative mx-auto my-8 flow-root max-w-4xl p-4">
<h1 className="text-4xl text-primary-500 dark:text-white">Feed</h1>
Expand Down
31 changes: 31 additions & 0 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,6 +162,34 @@ let renderText = (activity: Activity) => {
</div>
</div>
);
case "pushed_commits":
return (
<div className="min-w-0 flex-1">
<div>
<p className="font-bold">
{activity.title}
<span className="text-foreground">
<RelativeTime time={activity.time} />
</span>
</p>
</div>
<div className="mt-2 rounded-lg border border-secondary-600 p-2 md:p-4">
{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 @@ -480,6 +509,8 @@ export const ActivityCheckbox = (props: {
pr_merged: "PR merged",
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
3 changes: 2 additions & 1 deletion lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ const points = {
pr_merged: 7,
pr_collaborated: 2,
issue_closed: 0,
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

// pushed commits directly to the repository would not be counted as of now
function formatSlug(slug: string) {
return slug.replace(/\.md$/, "");
}
Expand Down
7 changes: 7 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,21 @@ export const ACTIVITY_TYPES = [
"pr_opened",
"pr_merged",
"pr_collaborated",
"pushed_commits",
] as const;

export interface commit {
dgparmar14 marked this conversation as resolved.
Show resolved Hide resolved
link: string;
text: string;
}

export interface Activity {
type: (typeof ACTIVITY_TYPES)[number];
title: string;
time: string;
link: string;
text: string;
commits?: commit[];
collaborated_with?: string[];
turnaround_time?: number;
}
Expand Down
46 changes: 45 additions & 1 deletion scraper/src/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"codecov-commenter",
}

default_branch_repos = {}

def is_blacklisted(login: str):
return "[bot]" in login or login in user_blacklist
Expand Down Expand Up @@ -70,7 +71,18 @@ def append(self, user, event):
"open_prs": [],
"authored_issue_and_pr": [],
}


def get_default_banch(self, repoOwner, reponame):
if reponame in default_branch_repos:
return default_branch_repos[reponame]

response = requests.get(f"https://api.github.com/repos/{repoOwner}/{reponame}")
response_json = response.json()
defaultBranchName = response_json["default_branch"]
default_branch_repos[reponame] = defaultBranchName

return defaultBranchName

def parse_event(self, event, event_time):
user = event["actor"]["login"]
try:
Expand Down Expand Up @@ -159,6 +171,38 @@ def parse_event(self, event, event_time):
},
)

elif event["type"] == "PushEvent":
branch = event["payload"]["ref"].split('/')[-1]
commits = event["payload"]["commits"]
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]:
dgparmar14 marked this conversation as resolved.
Show resolved Hide resolved
# Prepare commit data
commit_data = {
"link": commit_details["html_url"],
"text": commit["message"],
}
# Append commit data to the array
all_commits.append(commit_data)

# Append pushed commits event
self.append(
user,
{
"type": "pushed_commits",
"time": event_time,
"title": f'Pushed({len(all_commits)}) commits to {event["repo"]["name"]}({branch})',
dgparmar14 marked this conversation as resolved.
Show resolved Hide resolved
"commits": all_commits,
},
)



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

Expand Down
Loading