Skip to content

Commit

Permalink
feat: release 0.0.8 (#3)
Browse files Browse the repository at this point in the history
* feat: release 0.0.8

* chore: update query

* chore: add contribution distribution and latest resource contribution
  • Loading branch information
Sachin-chaurasiya authored Mar 19, 2023
1 parent d1dc082 commit 6f9aee8
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 1 deletion.
48 changes: 48 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,48 @@ export const GITHUB_USER_RESOURCE_QUERY = `query GetUserResourceInfo {
}
totalRepositoryContributions
totalPullRequestReviewContributions
pullRequestContributions(first: 10) {
totalCount
nodes {
pullRequest {
url
title
repository {
nameWithOwner
url
isPrivate
}
}
}
}
pullRequestReviewContributions(first: 10) {
totalCount
nodes {
pullRequest {
url
title
repository {
nameWithOwner
url
isPrivate
}
}
}
}
issueContributions(first: 10) {
totalCount
nodes {
issue {
url
title
repository {
nameWithOwner
url
isPrivate
}
}
}
}
}
pinnedItems(first: 10) {
totalCount
Expand All @@ -25,6 +67,8 @@ export const GITHUB_USER_RESOURCE_QUERY = `query GetUserResourceInfo {
description
nameWithOwner
url
stargazerCount
forkCount
primaryLanguage {
name
color
Expand Down Expand Up @@ -72,6 +116,10 @@ export const GITHUB_USER_RESOURCE_QUERY = `query GetUserResourceInfo {
}
}
}
avatarUrl
bio
websiteUrl
twitterUsername
}
}`;

Expand Down
70 changes: 69 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,35 @@ export interface ContributionCalendar {
weeks: ContributionWeeks[];
}

enum ContributionResource {
PULL_REQUEST = 'pullRequest',
ISSUE = 'issue',
}

export interface ContributionsNodeResource {
url: string;
title: string;
repository: {
nameWithOwner: string;
url: string;
isPrivate: boolean;
};
}

interface Contributions<T extends ContributionResource> {
totalCount: number;
nodes: {
[K in T]: ContributionsNodeResource;
}[];
}

export interface ContributionsCollection {
contributionCalendar: ContributionCalendar;
totalRepositoryContributions: number;
totalPullRequestReviewContributions: number;
pullRequestContributions: Contributions<ContributionResource.PULL_REQUEST>;
pullRequestReviewContributions: Contributions<ContributionResource.PULL_REQUEST>;
issueContributions: Contributions<ContributionResource.ISSUE>;
}

export interface LanguageEdgeNode {
Expand All @@ -53,6 +78,8 @@ export interface PinnedItemNode {
description: string;
nameWithOwner: string;
url: string;
stargazerCount: number;
forkCount: number;
languages: Language;
visibility: string;
primaryLanguage: {
Expand Down Expand Up @@ -82,7 +109,6 @@ export interface UserOrganizations {
node: OrganizationNode;
}[];
}

export interface GithubUserResource {
data: {
user: {
Expand All @@ -96,6 +122,10 @@ export interface GithubUserResource {
gists: TotalCount;
followers: TotalCount;
organizations: UserOrganizations;
avatarUrl: string;
bio: string;
websiteUrl: string;
twitterUsername: string;
};
};
}
Expand All @@ -111,6 +141,20 @@ export interface SummaryOverview {
totalPullRequestReviewed: number;
popularRepositories: PinnedItemNode[];
contributedOrganizations: OrganizationNode[];
personalInfo: {
avatarUrl: string;
bio: string;
websiteUrl: string;
twitterUsername: string;
};
contributionDistribution: {
pullRequest: number;
pullRequestReview: number;
issue: number;
};
latestPullRequestContributions: ContributionsNodeResource[];
latestPullRequestReviewContributions: ContributionsNodeResource[];
latestIssueContributions: ContributionsNodeResource[];
}

export interface UserContribution
Expand Down Expand Up @@ -201,6 +245,13 @@ export const getContributionSummary = async (
const contributionsCollection = userResource.contributionsCollection;
const contributionCalendar = contributionsCollection.contributionCalendar;

const pullRequestContribution =
contributionsCollection.pullRequestContributions;
const pullRequestReviewContribution =
contributionsCollection.pullRequestReviewContributions;

const issueContribution = contributionsCollection.issueContributions;

const contributionDays: ContributionDays[] =
contributionCalendar.weeks.reduce((prev, curr) => {
return [...prev, ...curr.contributionDays];
Expand All @@ -223,6 +274,23 @@ export const getContributionSummary = async (
contributedOrganizations: userResource.organizations.edges.map(
(edge) => edge.node
),
personalInfo: {
bio: userResource.bio,
avatarUrl: userResource.avatarUrl,
websiteUrl: userResource.websiteUrl,
twitterUsername: userResource.twitterUsername,
},
contributionDistribution: {
pullRequest: pullRequestContribution.totalCount,
pullRequestReview: pullRequestReviewContribution.totalCount,
issue: issueContribution.totalCount,
},
latestPullRequestContributions: pullRequestContribution.nodes.map(
(node) => node.pullRequest
),
latestPullRequestReviewContributions:
pullRequestReviewContribution.nodes.map((node) => node.pullRequest),
latestIssueContributions: issueContribution.nodes.map((node) => node.issue),
};
};

Expand Down

0 comments on commit 6f9aee8

Please sign in to comment.