From 24bfb159bbe9c43e631432c69189f0ffba0c7c11 Mon Sep 17 00:00:00 2001 From: TED Vortex Date: Tue, 4 Apr 2023 10:12:06 +0200 Subject: [PATCH] fix: correct top repositories distribution and name concatenation --- src/github/github.service.ts | 2 + src/github/gql/get-user.ts | 122 +++++++++--------- src/social-card/social-card.service.ts | 2 +- .../templates/user-profile-repos.ts | 5 +- 4 files changed, 70 insertions(+), 61 deletions(-) diff --git a/src/github/github.service.ts b/src/github/github.service.ts index b21d5a4..88087e7 100644 --- a/src/github/github.service.ts +++ b/src/github/github.service.ts @@ -39,6 +39,8 @@ export class GithubService { } }`); + this.logger.debug(`Rate limit: ${JSON.stringify(rateLimit)}`); + return rateLimit; } } diff --git a/src/github/gql/get-user.ts b/src/github/gql/get-user.ts index fa9c225..342d2c1 100644 --- a/src/github/gql/get-user.ts +++ b/src/github/gql/get-user.ts @@ -17,93 +17,99 @@ const getUser = (username: string, dateSince: string) => ({ query ($username: String!, $dateSince: DateTime) { user(login: $username) { - id, - avatarUrl, - bio, - bioHTML, - company, - companyHTML, - createdAt, - email, - hasSponsorsListing, - isBountyHunter, - isCampusExpert, - isDeveloperProgramMember, - isEmployee, - isGitHubStar, - isHireable, - isSiteAdmin, - location, - login, - monthlyEstimatedSponsorsIncomeInCents, - name, - url, - pronouns, - resourcePath, - totalSponsorshipAmountAsSponsorInCents, - websiteUrl, - twitterUsername, + id + avatarUrl + bio + bioHTML + company + companyHTML + createdAt + email + hasSponsorsListing + isBountyHunter + isCampusExpert + isDeveloperProgramMember + isEmployee + isGitHubStar + isHireable + isSiteAdmin + location + login + monthlyEstimatedSponsorsIncomeInCents + name + url + pronouns + resourcePath + totalSponsorshipAmountAsSponsorInCents + websiteUrl + twitterUsername organization(login: "open-sauced") { - id, - avatarUrl, - name, - url, + id + avatarUrl + name + url updatedAt - }, - organizations(first: 10, orderBy: {field: CREATED_AT, direction: ASC}) { + } + organizations(first: 10, orderBy: { field: CREATED_AT, direction: ASC }) { nodes { - id, - avatarUrl, - name, - url, + id + avatarUrl + name + url updatedAt } - }, + } socialAccounts(first: 10) { nodes { - displayName, - provider, + displayName + provider url } - }, + } status { - id, - emoji, - message, + id + emoji + message organization { id } - }, - repositories(first: 100, orderBy: {field: PUSHED_AT, direction: DESC}) { + } + repositories(first: 100, orderBy: { field: PUSHED_AT, direction: DESC }) { nodes { name primaryLanguage { name - }, - languages(first: 10, orderBy: {field: SIZE, direction: DESC}) { + } + languages(first: 10, orderBy: { field: SIZE, direction: DESC }) { edges { node { - id, - name, + id + name color - }, + } size - }, - totalSize, + } + totalSize totalCount - }, + } pushedAt } - }, - topRepositories(first: 10, orderBy: {field: PUSHED_AT, direction: DESC}, since: $dateSince) { + } + topRepositories( + first: 100 + orderBy: { field: PUSHED_AT, direction: DESC } + since: $dateSince + ) { nodes { - name, + name owner { + login avatarUrl - }, + } + isPrivate primaryLanguage { name - }, + } pushedAt } } diff --git a/src/social-card/social-card.service.ts b/src/social-card/social-card.service.ts index ef13041..e5909a0 100644 --- a/src/social-card/social-card.service.ts +++ b/src/social-card/social-card.service.ts @@ -30,7 +30,7 @@ export class SocialCardService { return { langs: [], - repos: user.topRepositories.nodes as Repository[], + repos: user.topRepositories.nodes?.filter(repo => !repo?.isPrivate && repo?.owner.login !== username) as Repository[], avatarUrl: `${String(user.avatarUrl)}&size=150`, }; } diff --git a/src/social-card/templates/user-profile-repos.ts b/src/social-card/templates/user-profile-repos.ts index 294e9c6..bbc3a17 100644 --- a/src/social-card/templates/user-profile-repos.ts +++ b/src/social-card/templates/user-profile-repos.ts @@ -2,9 +2,10 @@ import repoIconWithName from "./repo-icon-with-name"; import { Repository } from "@octokit/graphql-schema"; const userProfileRepos = (repos: Repository[]): string => { - const repoList = repos.map(({ name, owner: { avatarUrl } }) => repoIconWithName(`${name.substring(0, 15)}${name.length > 15 ? "..." : ""}`, `${String(avatarUrl)}&size=40`)); + const repoList = repos.map(({ name, owner: { avatarUrl } }) => + repoIconWithName(`${name.substring(0, 15).replace(/\.+$/, "")}${name.length > 15 ? "..." : ""}`, `${String(avatarUrl)}&size=40`)); - return `${repoList.slice(0, 3).join("")}${repoList.length > 3 + return `${repoList.slice(0, 4).join("")}${repoList.length > 4 ? `