mirror of
https://github.com/tiennm99/github-readme-stats.git
synced 2026-05-14 08:58:28 +00:00
Stats card: show started and answered discussions stats (#2849)
* Stats card: show started and answered discussions stats * trans * dev
This commit is contained in:
committed by
GitHub
parent
a5260cb38a
commit
92518e375f
@@ -151,7 +151,7 @@ You can pass a query parameter `&hide=` to hide any specific stats with comma-se
|
||||
|
||||
You can pass a query parameter `&show=` to show any specific additional stats with comma-separated values.
|
||||
|
||||
> Options: `&show=reviews`
|
||||
> Options: `&show=reviews,discussions_started,discussions_answered`
|
||||
|
||||
```md
|
||||

|
||||
@@ -314,7 +314,7 @@ You can provide multiple comma-separated values in the bg\_color option to rende
|
||||
* `disable_animations` - Disables all animations in the card *(boolean)*. Default: `false`.
|
||||
* `ring_color` - Color of the rank circle *(hex color)*. Defaults to the theme ring color if it exists and otherwise the title color.
|
||||
* `number_format` - Switch between two available formats for displaying the card values `short` (i.e. `6.6k`) and `long` (i.e. `6626`). Default: `short`.
|
||||
* `show` - Show [additional items](#showing-additional-individual-stats) on stats card (i.e. `reviews`) *(Comma-separated values)*. Default: `[] (blank array)`.
|
||||
* `show` - Show [additional items](#showing-additional-individual-stats) on stats card (i.e. `reviews`, `discussions_started` or `discussions_answered`) *(Comma-separated values)*. Default: `[] (blank array)`.
|
||||
|
||||
> **Note**
|
||||
> When hide\_rank=`true`, the minimum card width is 270 px + the title length and padding.
|
||||
@@ -541,9 +541,9 @@ Change the `?username=` value to your [Wakatime](https://wakatime.com) username.
|
||||
|
||||

|
||||
|
||||
* Showing addition stats
|
||||
* Showing additional stats
|
||||
|
||||

|
||||

|
||||
|
||||
* Showing icons
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ const renderStatsCard = (stats = {}, options = {}) => {
|
||||
totalIssues,
|
||||
totalPRs,
|
||||
totalReviews,
|
||||
totalDiscussionsStarted,
|
||||
totalDiscussionsAnswered,
|
||||
contributedTo,
|
||||
rank,
|
||||
} = stats;
|
||||
@@ -176,6 +178,24 @@ const renderStatsCard = (stats = {}, options = {}) => {
|
||||
value: totalIssues,
|
||||
id: "issues",
|
||||
};
|
||||
|
||||
if (show.includes("discussions_started")) {
|
||||
STATS.discussions_started = {
|
||||
icon: icons.discussions_started,
|
||||
label: i18n.t("statcard.discussions-started"),
|
||||
value: totalDiscussionsStarted,
|
||||
id: "discussions_started",
|
||||
};
|
||||
}
|
||||
if (show.includes("discussions_answered")) {
|
||||
STATS.discussions_answered = {
|
||||
icon: icons.discussions_answered,
|
||||
label: i18n.t("statcard.discussions-answered"),
|
||||
value: totalDiscussionsAnswered,
|
||||
id: "discussions_answered",
|
||||
};
|
||||
}
|
||||
|
||||
STATS.contribs = {
|
||||
icon: icons.contribs,
|
||||
label: i18n.t("statcard.contribs"),
|
||||
|
||||
@@ -7,6 +7,8 @@ const icons = {
|
||||
contribs: `<path fill-rule="evenodd" d="M2 2.5A2.5 2.5 0 014.5 0h8.75a.75.75 0 01.75.75v12.5a.75.75 0 01-.75.75h-2.5a.75.75 0 110-1.5h1.75v-2h-8a1 1 0 00-.714 1.7.75.75 0 01-1.072 1.05A2.495 2.495 0 012 11.5v-9zm10.5-1V9h-8c-.356 0-.694.074-1 .208V2.5a1 1 0 011-1h8zM5 12.25v3.25a.25.25 0 00.4.2l1.45-1.087a.25.25 0 01.3 0L8.6 15.7a.25.25 0 00.4-.2v-3.25a.25.25 0 00-.25-.25h-3.5a.25.25 0 00-.25.25z"/>`,
|
||||
fork: `<path fill-rule="evenodd" d="M5 3.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm0 2.122a2.25 2.25 0 10-1.5 0v.878A2.25 2.25 0 005.75 8.5h1.5v2.128a2.251 2.251 0 101.5 0V8.5h1.5a2.25 2.25 0 002.25-2.25v-.878a2.25 2.25 0 10-1.5 0v.878a.75.75 0 01-.75.75h-4.5A.75.75 0 015 6.25v-.878zm3.75 7.378a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm3-8.75a.75.75 0 100-1.5.75.75 0 000 1.5z"></path>`,
|
||||
reviews: `<path fill-rule="evenodd" d="M8 2c1.981 0 3.671.992 4.933 2.078 1.27 1.091 2.187 2.345 2.637 3.023a1.62 1.62 0 0 1 0 1.798c-.45.678-1.367 1.932-2.637 3.023C11.67 13.008 9.981 14 8 14c-1.981 0-3.671-.992-4.933-2.078C1.797 10.83.88 9.576.43 8.898a1.62 1.62 0 0 1 0-1.798c.45-.677 1.367-1.931 2.637-3.022C4.33 2.992 6.019 2 8 2ZM1.679 7.932a.12.12 0 0 0 0 .136c.411.622 1.241 1.75 2.366 2.717C5.176 11.758 6.527 12.5 8 12.5c1.473 0 2.825-.742 3.955-1.715 1.124-.967 1.954-2.096 2.366-2.717a.12.12 0 0 0 0-.136c-.412-.621-1.242-1.75-2.366-2.717C10.824 4.242 9.473 3.5 8 3.5c-1.473 0-2.825.742-3.955 1.715-1.124.967-1.954 2.096-2.366 2.717ZM8 10a2 2 0 1 1-.001-3.999A2 2 0 0 1 8 10Z"/>`,
|
||||
discussions_started: `<path fill-rule="evenodd" d="M1.75 1h8.5c.966 0 1.75.784 1.75 1.75v5.5A1.75 1.75 0 0 1 10.25 10H7.061l-2.574 2.573A1.458 1.458 0 0 1 2 11.543V10h-.25A1.75 1.75 0 0 1 0 8.25v-5.5C0 1.784.784 1 1.75 1ZM1.5 2.75v5.5c0 .138.112.25.25.25h1a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h3.5a.25.25 0 0 0 .25-.25v-5.5a.25.25 0 0 0-.25-.25h-8.5a.25.25 0 0 0-.25.25Zm13 2a.25.25 0 0 0-.25-.25h-.5a.75.75 0 0 1 0-1.5h.5c.966 0 1.75.784 1.75 1.75v5.5A1.75 1.75 0 0 1 14.25 12H14v1.543a1.458 1.458 0 0 1-2.487 1.03L9.22 12.28a.749.749 0 0 1 .326-1.275.749.749 0 0 1 .734.215l2.22 2.22v-2.19a.75.75 0 0 1 .75-.75h1a.25.25 0 0 0 .25-.25Z" />`,
|
||||
discussions_answered: `<path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z" />`,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -63,6 +63,12 @@ const GRAPHQL_STATS_QUERY = `
|
||||
followers {
|
||||
totalCount
|
||||
}
|
||||
repositoryDiscussions {
|
||||
totalCount
|
||||
}
|
||||
repositoryDiscussionComments(onlyAnswers: true) {
|
||||
totalCount
|
||||
}
|
||||
${GRAPHQL_REPOS_FIELD}
|
||||
}
|
||||
}
|
||||
@@ -190,6 +196,8 @@ const fetchStats = async (
|
||||
totalCommits: 0,
|
||||
totalIssues: 0,
|
||||
totalStars: 0,
|
||||
totalDiscussionsStarted: 0,
|
||||
totalDiscussionsAnswered: 0,
|
||||
contributedTo: 0,
|
||||
rank: { level: "C", percentile: 100 },
|
||||
};
|
||||
@@ -232,6 +240,8 @@ const fetchStats = async (
|
||||
stats.totalReviews =
|
||||
user.contributionsCollection.totalPullRequestReviewContributions;
|
||||
stats.totalIssues = user.openIssues.totalCount + user.closedIssues.totalCount;
|
||||
stats.totalDiscussionsStarted = user.repositoryDiscussions.totalCount;
|
||||
stats.totalDiscussionsAnswered = user.repositoryDiscussionComments.totalCount;
|
||||
stats.contributedTo = user.repositoriesContributedTo.totalCount;
|
||||
|
||||
// Retrieve stars while filtering out repositories to be hidden.
|
||||
|
||||
Vendored
+2
@@ -22,6 +22,8 @@ export type StatsData = {
|
||||
totalCommits: number;
|
||||
totalIssues: number;
|
||||
totalStars: number;
|
||||
totalDiscussionsStarted: number;
|
||||
totalDiscussionsAnswered: number;
|
||||
contributedTo: number;
|
||||
rank: { level: string; percentile: number };
|
||||
};
|
||||
|
||||
@@ -228,6 +228,66 @@ const statCardLocales = ({ name, apostrophe }) => {
|
||||
vi: "Tổng Số PR Đã Xem Xét",
|
||||
se: "Totalt antal granskade PR",
|
||||
},
|
||||
"statcard.discussions-started": {
|
||||
ar: "مجموع بدء المناقشات",
|
||||
cn: "发起的讨论总数",
|
||||
"zh-tw": "發起的討論總數",
|
||||
cs: "Celkem zahájených diskusí",
|
||||
de: "Gesamt gestartete Diskussionen",
|
||||
en: "Total Discussions Started",
|
||||
bn: "সর্বমোট আলোচনা শুরু",
|
||||
es: "Discusiones totales iniciadas",
|
||||
fr: "Nombre total de discussions lancées",
|
||||
hu: "Összes megkezdett megbeszélés",
|
||||
it: "Discussioni totali avviate",
|
||||
ja: "開始されたディスカッションの総数",
|
||||
kr: "시작된 토론 총 수",
|
||||
nl: "Totaal gestarte discussies",
|
||||
"pt-pt": "Total de Discussões Iniciadas",
|
||||
"pt-br": "Total de Discussões Iniciadas",
|
||||
np: "कुल चर्चा सुरु",
|
||||
el: "Σύνολο Συζητήσεων που Ξεκίνησαν",
|
||||
ru: "Всего начатых дискуссий",
|
||||
"uk-ua": "Всього розпочатих дискусій",
|
||||
id: "Total Diskusi Dimulai",
|
||||
my: "Jumlah Perbincangan Bermula",
|
||||
sk: "Celkový počet začatých diskusií",
|
||||
tr: "Başlatılan Toplam Tartışma",
|
||||
pl: "Łącznie rozpoczętych dyskusji",
|
||||
uz: "Boshlangan muzokaralar soni",
|
||||
vi: "Tổng Số Thảo Luận Bắt Đầu",
|
||||
se: "Totalt antal diskussioner startade",
|
||||
},
|
||||
"statcard.discussions-answered": {
|
||||
ar: "مجموع الردود على المناقشات",
|
||||
cn: "回复的讨论总数",
|
||||
"zh-tw": "回覆的討論總數",
|
||||
cs: "Celkem zodpovězených diskusí",
|
||||
de: "Gesamt beantwortete Diskussionen",
|
||||
en: "Total Discussions Answered",
|
||||
bn: "সর্বমোট আলোচনা উত্তর",
|
||||
es: "Discusiones totales respondidas",
|
||||
fr: "Nombre total de discussions répondues",
|
||||
hu: "Összes megválaszolt megbeszélés",
|
||||
it: "Discussioni totali risposte",
|
||||
ja: "回答されたディスカッションの総数",
|
||||
kr: "답변된 토론 총 수",
|
||||
nl: "Totaal beantwoorde discussies",
|
||||
"pt-pt": "Total de Discussões Respondidas",
|
||||
"pt-br": "Total de Discussões Respondidas",
|
||||
np: "कुल चर्चा उत्तर",
|
||||
el: "Σύνολο Συζητήσεων που Απαντήθηκαν",
|
||||
ru: "Всего отвеченных дискуссий",
|
||||
"uk-ua": "Всього відповідей на дискусії",
|
||||
id: "Total Diskusi Dibalas",
|
||||
my: "Jumlah Perbincangan Dijawab",
|
||||
sk: "Celkový počet zodpovedaných diskusií",
|
||||
tr: "Toplam Cevaplanan Tartışma",
|
||||
pl: "Łącznie odpowiedzianych dyskusji",
|
||||
uz: "Javob berilgan muzokaralar soni",
|
||||
vi: "Tổng Số Thảo Luận Đã Trả Lời",
|
||||
se: "Totalt antal diskussioner besvarade",
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@ const stats = {
|
||||
totalCommits: 200,
|
||||
totalIssues: 300,
|
||||
totalPRs: 400,
|
||||
totalReviews: 50,
|
||||
totalDiscussionsStarted: 10,
|
||||
totalDiscussionsAnswered: 40,
|
||||
contributedTo: 50,
|
||||
rank: null,
|
||||
};
|
||||
@@ -33,11 +36,16 @@ const data_stats = {
|
||||
repositoriesContributedTo: { totalCount: stats.contributedTo },
|
||||
contributionsCollection: {
|
||||
totalCommitContributions: stats.totalCommits,
|
||||
totalPullRequestReviewContributions: stats.totalReviews,
|
||||
},
|
||||
pullRequests: { totalCount: stats.totalPRs },
|
||||
openIssues: { totalCount: stats.totalIssues },
|
||||
closedIssues: { totalCount: 0 },
|
||||
followers: { totalCount: 0 },
|
||||
repositoryDiscussions: { totalCount: stats.totalDiscussionsStarted },
|
||||
repositoryDiscussionComments: {
|
||||
totalCount: stats.totalDiscussionsAnswered,
|
||||
},
|
||||
repositories: {
|
||||
totalCount: 1,
|
||||
nodes: [{ stargazers: { totalCount: 100 } }],
|
||||
|
||||
@@ -18,6 +18,8 @@ const data_stats = {
|
||||
openIssues: { totalCount: 100 },
|
||||
closedIssues: { totalCount: 100 },
|
||||
followers: { totalCount: 100 },
|
||||
repositoryDiscussions: { totalCount: 10 },
|
||||
repositoryDiscussionComments: { totalCount: 40 },
|
||||
repositories: {
|
||||
totalCount: 5,
|
||||
nodes: [
|
||||
@@ -119,6 +121,8 @@ describe("Test fetchStats", () => {
|
||||
totalPRs: 300,
|
||||
totalReviews: 50,
|
||||
totalStars: 300,
|
||||
totalDiscussionsStarted: 10,
|
||||
totalDiscussionsAnswered: 40,
|
||||
rank,
|
||||
});
|
||||
});
|
||||
@@ -150,6 +154,8 @@ describe("Test fetchStats", () => {
|
||||
totalPRs: 300,
|
||||
totalReviews: 50,
|
||||
totalStars: 300,
|
||||
totalDiscussionsStarted: 10,
|
||||
totalDiscussionsAnswered: 40,
|
||||
rank,
|
||||
});
|
||||
});
|
||||
@@ -187,6 +193,8 @@ describe("Test fetchStats", () => {
|
||||
totalPRs: 300,
|
||||
totalReviews: 50,
|
||||
totalStars: 300,
|
||||
totalDiscussionsStarted: 10,
|
||||
totalDiscussionsAnswered: 40,
|
||||
rank,
|
||||
});
|
||||
});
|
||||
@@ -215,6 +223,8 @@ describe("Test fetchStats", () => {
|
||||
totalPRs: 300,
|
||||
totalReviews: 50,
|
||||
totalStars: 200,
|
||||
totalDiscussionsStarted: 10,
|
||||
totalDiscussionsAnswered: 40,
|
||||
rank,
|
||||
});
|
||||
});
|
||||
@@ -241,6 +251,8 @@ describe("Test fetchStats", () => {
|
||||
totalPRs: 300,
|
||||
totalReviews: 50,
|
||||
totalStars: 400,
|
||||
totalDiscussionsStarted: 10,
|
||||
totalDiscussionsAnswered: 40,
|
||||
rank,
|
||||
});
|
||||
});
|
||||
@@ -267,6 +279,8 @@ describe("Test fetchStats", () => {
|
||||
totalPRs: 300,
|
||||
totalReviews: 50,
|
||||
totalStars: 300,
|
||||
totalDiscussionsStarted: 10,
|
||||
totalDiscussionsAnswered: 40,
|
||||
rank,
|
||||
});
|
||||
});
|
||||
@@ -293,6 +307,8 @@ describe("Test fetchStats", () => {
|
||||
totalPRs: 300,
|
||||
totalReviews: 50,
|
||||
totalStars: 300,
|
||||
totalDiscussionsStarted: 10,
|
||||
totalDiscussionsAnswered: 40,
|
||||
rank,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,6 +17,8 @@ const stats = {
|
||||
totalIssues: 300,
|
||||
totalPRs: 400,
|
||||
totalReviews: 50,
|
||||
totalDiscussionsStarted: 10,
|
||||
totalDiscussionsAnswered: 50,
|
||||
contributedTo: 500,
|
||||
rank: { level: "A+", score: 40 },
|
||||
};
|
||||
@@ -42,6 +44,12 @@ describe("Test renderStatsCard", () => {
|
||||
|
||||
// Default hidden stats
|
||||
expect(queryByTestId(document.body, "reviews")).not.toBeInTheDocument();
|
||||
expect(
|
||||
queryByTestId(document.body, "discussions_started"),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
queryByTestId(document.body, "discussions_answered"),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should have proper name apostrophe", () => {
|
||||
@@ -73,16 +81,18 @@ describe("Test renderStatsCard", () => {
|
||||
expect(queryByTestId(document.body, "prs")).toBeNull();
|
||||
expect(queryByTestId(document.body, "contribs")).toBeNull();
|
||||
expect(queryByTestId(document.body, "reviews")).toBeNull();
|
||||
expect(queryByTestId(document.body, "discussions_started")).toBeNull();
|
||||
expect(queryByTestId(document.body, "discussions_answered")).toBeNull();
|
||||
});
|
||||
|
||||
it("should show total reviews", () => {
|
||||
it("should show additional stats", () => {
|
||||
document.body.innerHTML = renderStatsCard(stats, {
|
||||
show: ["reviews"],
|
||||
show: ["reviews", "discussions_started", "discussions_answered"],
|
||||
});
|
||||
|
||||
expect(
|
||||
document.body.getElementsByTagName("svg")[0].getAttribute("height"),
|
||||
).toBe("220");
|
||||
).toBe("270");
|
||||
|
||||
expect(queryByTestId(document.body, "stars")).toBeDefined();
|
||||
expect(queryByTestId(document.body, "commits")).toBeDefined();
|
||||
@@ -90,6 +100,8 @@ describe("Test renderStatsCard", () => {
|
||||
expect(queryByTestId(document.body, "prs")).toBeDefined();
|
||||
expect(queryByTestId(document.body, "contribs")).toBeDefined();
|
||||
expect(queryByTestId(document.body, "reviews")).toBeDefined();
|
||||
expect(queryByTestId(document.body, "discussions_started")).toBeDefined();
|
||||
expect(queryByTestId(document.body, "discussions_answered")).toBeDefined();
|
||||
});
|
||||
|
||||
it("should hide_rank", () => {
|
||||
|
||||
Reference in New Issue
Block a user