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

Add support for tracking commits pushed to branch (core) #601

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions scraper/src/github-scraper/fetchEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const AllowedEventTypes = [
"IssuesEvent",
"PullRequestEvent",
"PullRequestReviewEvent",
"PushEvent"
];

export const fetchEvents = async (org: string) => {
Expand Down
19 changes: 19 additions & 0 deletions scraper/src/github-scraper/parseEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,25 @@ export const parseEvents = async (events: IGitHubEvent[]) => {
}
}
break;
case "PushEvent":
if (event.payload?.commits?.length > 0) {
for (const commit of event.payload.commits) {
if (
commit.message.startsWith("Merge pull request") ||
commit.message.startsWith("Merge branch")
)
continue;
console.log(commit);
appendEvent(user, {
type: "pushed_commits",
title: `${event.repo.name}@${commit.sha.slice(0, 7)}`,
time: eventTime?.toISOString(),
link: `https://github.com/${event.repo.name}/commit/${commit.sha}`,
text: commit.message,
});
}
}
break;
case "PullRequestReviewEvent":
if (event.payload.pull_request.user.login !== user) {
appendEvent(user, {
Expand Down
26 changes: 25 additions & 1 deletion scraper/src/github-scraper/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,34 @@ export interface PullRequestEvent extends GitHubEvent {
};
}

interface PushEvent extends GitHubEvent {
type: "PushEvent";
payload: {
size: number;
ref: string;
head: string;
before: string;
commits: Commit[];
};
}

interface Commit {
sha: string;
author: {
name: string;
email: string;
};
message: string;
distinct: boolean;
url: string;
}

export type IGitHubEvent =
| PullRequestReviewEvent
| IssuesEvent
| IssueCommentEvent
| PullRequestEvent;
| PullRequestEvent
| PushEvent;

export interface ActivityData {
last_updated?: string;
Expand All @@ -140,6 +163,7 @@ export const ACTIVITY_TYPES = [
"pr_opened",
"pr_merged",
"pr_collaborated",
"pushed_commits",
] as const;

export interface Action {
Expand Down
Loading