diff --git a/api/pin.js b/api/pin.js index 5ab745a2..42dcac41 100644 --- a/api/pin.js +++ b/api/pin.js @@ -2,7 +2,8 @@ import { renderRepoCard } from "../src/cards/repo-card.js"; import { blacklist } from "../src/common/blacklist.js"; import { clampValue, - CONSTANTS, parseArray, + CONSTANTS, + parseArray, parseBoolean, renderError, } from "../src/common/utils.js"; @@ -61,16 +62,20 @@ export default async (req, res) => { const safePattern = /^[\w\/.]+$/; if ( (username && !safePattern.test(username)) || - (repos && !safePattern.test(repo)) + (repo && !safePattern.test(repo)) ) { return res.send( - renderError("Something went wrong", "Username or repository contains unsafe characters", { - title_color, - text_color, - bg_color, - border_color, - theme, - }), + renderError( + "Something went wrong", + "Username or repository contains unsafe characters", + { + title_color, + text_color, + bg_color, + border_color, + theme, + }, + ), ); } diff --git a/src/cards/repo-card.js b/src/cards/repo-card.js index fa7212a6..174e2575 100644 --- a/src/cards/repo-card.js +++ b/src/cards/repo-card.js @@ -12,10 +12,11 @@ import { wrapTextMultiline, iconWithLabel, createLanguageNode, - clampValue, buildSearchFilter, + clampValue, + buildSearchFilter, } from "../common/utils.js"; import { repoCardLocales } from "../translations.js"; -import {createTextNode} from "./stats-card.js"; +import { createTextNode } from "./stats-card.js"; const ICON_SIZE = 16; const DESCRIPTION_LINE_WIDTH = 59; @@ -91,6 +92,11 @@ const renderRepoCard = (repo, options = {}) => { description_lines_count, } = options; + const i18n = new I18n({ + locale, + translations: repoCardLocales, + }); + let repoFilter = buildSearchFilter([nameWithOwner], []); const STATS = {}; if (show.includes("prs_authored")) { @@ -139,23 +145,22 @@ const renderRepoCard = (repo, options = {}) => { }; } - const statItems = Object.keys(STATS) - .map((key, index) => - // create the text nodes, and pass index so that we can calculate the line spacing - createTextNode({ - icon: STATS[key].icon, - label: STATS[key].label, - value: STATS[key].value, - id: STATS[key].id, - unitSymbol: STATS[key].unitSymbol, - index, - showIcons: show_icons, - shiftValuePos: 29.01, - bold: text_bold, - number_format, - link: STATS[key].link, - }), - ); + const statItems = Object.keys(STATS).map((key, index) => + // create the text nodes, and pass index so that we can calculate the line spacing + createTextNode({ + icon: STATS[key].icon, + label: STATS[key].label, + value: STATS[key].value, + id: STATS[key].id, + unitSymbol: STATS[key].unitSymbol, + index, + showIcons: show_icons, + shiftValuePos: 29.01, + bold: text_bold, + number_format, + link: STATS[key].link, + }), + ); const extraLHeight = parseInt(String(line_height), 10); const lineHeight = 10; @@ -180,16 +185,13 @@ const renderRepoCard = (repo, options = {}) => { .map((line) => `${encodeHTML(line)}`) .join(""); - const extraHeight=45 + (statItems.length + 1) * extraLHeight; + const extraHeight = Object.keys(STATS).length + ? 45 + (statItems.length + 1) * extraLHeight + : 0; const height = (descriptionLinesCount > 1 ? 120 : 110) + - descriptionLinesCount * lineHeight - + extraHeight; - - const i18n = new I18n({ - locale, - translations: repoCardLocales, - }); + descriptionLinesCount * lineHeight + + extraHeight; // returns theme based colors with proper overrides and defaults const colors = getCardColors({ @@ -230,6 +232,16 @@ const renderRepoCard = (repo, options = {}) => { gap: 25, }).join(""); + const extraItems = ` + + ${flexLayout({ + items: statItems, + gap: extraLHeight, + direction: "column", + }).join("")} + + `; + const card = new Card({ defaultTitle: header.length > 35 ? `${header.slice(0, 35)}...` : header, titlePrefixIcon: icons.contribs, @@ -268,14 +280,7 @@ const renderRepoCard = (repo, options = {}) => { ${starAndForkCount} - - - ${flexLayout({ - items: statItems, - gap: extraLHeight, - direction: "column", - }).join("")} - + ${extraItems} `); }; diff --git a/src/fetchers/types.d.ts b/src/fetchers/types.d.ts index 942e3af3..1588c921 100644 --- a/src/fetchers/types.d.ts +++ b/src/fetchers/types.d.ts @@ -22,6 +22,11 @@ export type RepositoryData = { }; forkCount: number; starCount: number; + totalPRsAuthored: number; + totalPRsCommented: number; + totalPRsReviewed: number; + totalIssuesAuthored: number; + totalIssuesCommented: number; }; export type StatsData = {