Feature: Stats card: Show merged PRs count and percentage (#3003)

* Feature: Stats card: Show merged PRs count and percentage

* dev

* dev

* renames
This commit is contained in:
Alexandr Garbuzov 2023-08-14 02:18:57 +03:00 committed by GitHub
parent 135176f073
commit a258b29db5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 140 additions and 7 deletions

View file

@ -156,10 +156,10 @@ 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,discussions_started,discussions_answered`
> Options: `&show=reviews,discussions_started,discussions_answered,prs_merged,prs_merged_percentage`
```md
![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show=reviews)
![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show=reviews,discussions_started,discussions_answered,prs_merged,prs_merged_percentage)
```
### Showing icons
@ -548,7 +548,7 @@ Change the `?username=` value to your [Wakatime](https://wakatime.com) username.
* Showing additional stats
![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra\&show=reviews,discussions_started,discussions_answered)
![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra\&show=reviews,discussions_started,discussions_answered,prs_merged,prs_merged_percentage)
* Showing icons

View file

@ -28,6 +28,7 @@ const RANK_ONLY_CARD_DEFAULT_WIDTH = 290;
* @param {string} createTextNodeParams.label The label to display.
* @param {number} createTextNodeParams.value The value to display.
* @param {string} createTextNodeParams.id The id of the stat.
* @param {string=} createTextNodeParams.unitSymbol The unit symbol of the stat.
* @param {number} createTextNodeParams.index The index of the stat.
* @param {boolean} createTextNodeParams.showIcons Whether to show icons.
* @param {number} createTextNodeParams.shiftValuePos Number of pixels the value has to be shifted to the right.
@ -40,6 +41,7 @@ const createTextNode = ({
label,
value,
id,
unitSymbol,
index,
showIcons,
shiftValuePos,
@ -69,7 +71,7 @@ const createTextNode = ({
x="${(showIcons ? 140 : 120) + shiftValuePos}"
y="12.5"
data-testid="${id}"
>${kValue}</text>
>${kValue}${unitSymbol ? ` ${unitSymbol}` : ""}</text>
</g>
`;
};
@ -93,6 +95,8 @@ const renderStatsCard = (stats, options = {}) => {
totalCommits,
totalIssues,
totalPRs,
totalPRsMerged,
mergedPRsPercentage,
totalReviews,
totalDiscussionsStarted,
totalDiscussionsAnswered,
@ -171,6 +175,25 @@ const renderStatsCard = (stats, options = {}) => {
id: "prs",
};
if (show.includes("prs_merged")) {
STATS.prs_merged = {
icon: icons.prs_merged,
label: i18n.t("statcard.prs-merged"),
value: totalPRsMerged,
id: "prs_merged",
};
}
if (show.includes("prs_merged_percentage")) {
STATS.prs_merged_percentage = {
icon: icons.prs_merged_percentage,
label: i18n.t("statcard.prs-merged-percentage"),
value: mergedPRsPercentage.toFixed(2),
id: "prs_merged_percentage",
unitSymbol: "%",
};
}
if (show.includes("reviews")) {
STATS.reviews = {
icon: icons.reviews,
@ -235,7 +258,11 @@ const renderStatsCard = (stats, options = {}) => {
.map((key, index) =>
// create the text nodes, and pass index so that we can calculate the line spacing
createTextNode({
...STATS[key],
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: 79.01 + (isLongLocale ? 50 : 0),

View file

@ -2,6 +2,8 @@ const icons = {
star: `<path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"/>`,
commits: `<path fill-rule="evenodd" d="M1.643 3.143L.427 1.927A.25.25 0 000 2.104V5.75c0 .138.112.25.25.25h3.646a.25.25 0 00.177-.427L2.715 4.215a6.5 6.5 0 11-1.18 4.458.75.75 0 10-1.493.154 8.001 8.001 0 101.6-5.684zM7.75 4a.75.75 0 01.75.75v2.992l2.028.812a.75.75 0 01-.557 1.392l-2.5-1A.75.75 0 017 8.25v-3.5A.75.75 0 017.75 4z"/>`,
prs: `<path fill-rule="evenodd" d="M7.177 3.073L9.573.677A.25.25 0 0110 .854v4.792a.25.25 0 01-.427.177L7.177 3.427a.25.25 0 010-.354zM3.75 2.5a.75.75 0 100 1.5.75.75 0 000-1.5zm-2.25.75a2.25 2.25 0 113 2.122v5.256a2.251 2.251 0 11-1.5 0V5.372A2.25 2.25 0 011.5 3.25zM11 2.5h-1V4h1a1 1 0 011 1v5.628a2.251 2.251 0 101.5 0V5A2.5 2.5 0 0011 2.5zm1 10.25a.75.75 0 111.5 0 .75.75 0 01-1.5 0zM3.75 12a.75.75 0 100 1.5.75.75 0 000-1.5z"/>`,
prs_merged: `<path fill-rule="evenodd" d="M5.45 5.154A4.25 4.25 0 0 0 9.25 7.5h1.378a2.251 2.251 0 1 1 0 1.5H9.25A5.734 5.734 0 0 1 5 7.123v3.505a2.25 2.25 0 1 1-1.5 0V5.372a2.25 2.25 0 1 1 1.95-.218ZM4.25 13.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm8.5-4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5ZM5 3.25a.75.75 0 1 0 0 .005V3.25Z" />`,
prs_merged_percentage: `<path fill-rule="evenodd" d="M13.442 2.558a.625.625 0 0 1 0 .884l-10 10a.625.625 0 1 1-.884-.884l10-10a.625.625 0 0 1 .884 0zM4.5 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zm0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5zm7 6a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3zm0 1a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5z" />`,
issues: `<path fill-rule="evenodd" d="M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM0 8a8 8 0 1116 0A8 8 0 010 8zm9 3a1 1 0 11-2 0 1 1 0 012 0zm-.25-6.25a.75.75 0 00-1.5 0v3.5a.75.75 0 001.5 0v-3.5z"/>`,
icon: `<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"/>`,
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"/>`,

View file

@ -54,6 +54,9 @@ const GRAPHQL_STATS_QUERY = `
pullRequests(first: 1) {
totalCount
}
mergedPullRequests: pullRequests(states: MERGED) {
totalCount
}
openIssues: issues(states: OPEN) {
totalCount
}
@ -201,6 +204,8 @@ const fetchStats = async (
const stats = {
name: "",
totalPRs: 0,
totalPRsMerged: 0,
mergedPRsPercentage: 0,
totalReviews: 0,
totalCommits: 0,
totalIssues: 0,
@ -246,6 +251,9 @@ const fetchStats = async (
}
stats.totalPRs = user.pullRequests.totalCount;
stats.totalPRsMerged = user.mergedPullRequests.totalCount;
stats.mergedPRsPercentage =
(user.mergedPullRequests.totalCount / user.pullRequests.totalCount) * 100;
stats.totalReviews =
user.contributionsCollection.totalPullRequestReviewContributions;
stats.totalIssues = user.openIssues.totalCount + user.closedIssues.totalCount;

View file

@ -18,6 +18,8 @@ export type RepositoryData = {
export type StatsData = {
name: string;
totalPRs: number;
totalPRsMerged: number;
mergedPRsPercentage: number;
totalReviews: number;
totalCommits: number;
totalIssues: number;

View file

@ -325,6 +325,66 @@ const statCardLocales = ({ name, apostrophe }) => {
vi: "Tổng Số Thảo Luận Đã Trả Lời",
se: "Totalt antal diskussioner besvarade",
},
"statcard.prs-merged": {
ar: "مجموع الطلبات المدمجة",
cn: "合并的 PR 总数",
"zh-tw": "合併的 PR 總數",
cs: "Celkem sloučených PR",
de: "Insgesamt zusammengeführte PRs",
en: "Total PRs Merged",
bn: "সর্বমোট PR একত্রীকৃত",
es: "PR totales fusionados",
fr: "Nombre total de PR fusionnés",
hu: "Összes egyesített PR",
it: "PR totali uniti",
ja: "マージされた PR の総数",
kr: "병합된 총 PR",
nl: "Totaal samengevoegde PR's",
"pt-pt": "Total de PRs Fundidos",
"pt-br": "Total de PRs Fundidos",
np: "कुल PRs मर्ज गरिएको",
el: "Σύνολο Συγχωνευμένων PR",
ru: "Всего объединённых pull request`ов",
"uk-ua": "Всього об'єднаних pull request`iв",
id: "Total PR Digabungkan",
my: "Jumlah PR Digabungkan",
sk: "Celkový počet zlúčených PR",
tr: "Toplam Birleştirilmiş PR",
pl: "Łącznie połączonych PR",
uz: "Birlangan PR-lar soni",
vi: "Tổng Số PR Đã Hợp Nhất",
se: "Totalt antal sammanfogade PR",
},
"statcard.prs-merged-percentage": {
ar: "نسبة الطلبات المدمجة",
cn: "合并的 PR 百分比",
"zh-tw": "合併的 PR 百分比",
cs: "Sloučené PRs v procentech",
de: "Zusammengeführte PRs in Prozent",
en: "Merged PRs Percentage",
bn: "PR একত্রীকরণের শতাংশ",
es: "Porcentaje de PR fusionados",
fr: "Pourcentage de PR fusionnés",
hu: "Egyesített PR-k százaléka",
it: "Percentuale di PR uniti",
ja: "マージされた PR の割合",
kr: "병합된 PR의 비율",
nl: "Percentage samengevoegde PR's",
"pt-pt": "Percentagem de PRs Fundidos",
"pt-br": "Porcentagem de PRs Fundidos",
np: "PR मर्ज गरिएको प्रतिशत",
el: "Ποσοστό Συγχωνευμένων PR",
ru: "Процент объединённых pull request`ов",
"uk-ua": "Відсоток об'єднаних pull request`iв",
id: "Persentase PR Digabungkan",
my: "Peratus PR Digabungkan",
sk: "Percento zlúčených PR",
tr: "Birleştirilmiş PR Yüzdesi",
pl: "Procent połączonych PR",
uz: "Birlangan PR-lar foizi",
vi: "Tỷ Lệ PR Đã Hợp Nhất",
se: "Procent av sammanfogade PR",
},
};
};

View file

@ -13,6 +13,8 @@ const stats = {
totalCommits: 200,
totalIssues: 300,
totalPRs: 400,
totalPRsMerged: 320,
mergedPRsPercentage: 80,
totalReviews: 50,
totalDiscussionsStarted: 10,
totalDiscussionsAnswered: 40,
@ -41,6 +43,7 @@ const data_stats = {
totalPullRequestReviewContributions: stats.totalReviews,
},
pullRequests: { totalCount: stats.totalPRs },
mergedPullRequests: { totalCount: stats.totalPRsMerged },
openIssues: { totalCount: stats.totalIssues },
closedIssues: { totalCount: 0 },
followers: { totalCount: 0 },

View file

@ -16,6 +16,7 @@ const data_stats = {
totalPullRequestReviewContributions: 50,
},
pullRequests: { totalCount: 300 },
mergedPullRequests: { totalCount: 240 },
openIssues: { totalCount: 100 },
closedIssues: { totalCount: 100 },
followers: { totalCount: 100 },
@ -121,6 +122,8 @@ describe("Test fetchStats", () => {
totalCommits: 100,
totalIssues: 200,
totalPRs: 300,
totalPRsMerged: 240,
mergedPRsPercentage: 80,
totalReviews: 50,
totalStars: 300,
totalDiscussionsStarted: 10,
@ -155,6 +158,8 @@ describe("Test fetchStats", () => {
totalCommits: 100,
totalIssues: 200,
totalPRs: 300,
totalPRsMerged: 240,
mergedPRsPercentage: 80,
totalReviews: 50,
totalStars: 300,
totalDiscussionsStarted: 10,
@ -195,6 +200,8 @@ describe("Test fetchStats", () => {
totalCommits: 1000,
totalIssues: 200,
totalPRs: 300,
totalPRsMerged: 240,
mergedPRsPercentage: 80,
totalReviews: 50,
totalStars: 300,
totalDiscussionsStarted: 10,
@ -226,6 +233,8 @@ describe("Test fetchStats", () => {
totalCommits: 1000,
totalIssues: 200,
totalPRs: 300,
totalPRsMerged: 240,
mergedPRsPercentage: 80,
totalReviews: 50,
totalStars: 200,
totalDiscussionsStarted: 10,
@ -255,6 +264,8 @@ describe("Test fetchStats", () => {
totalCommits: 100,
totalIssues: 200,
totalPRs: 300,
totalPRsMerged: 240,
mergedPRsPercentage: 80,
totalReviews: 50,
totalStars: 400,
totalDiscussionsStarted: 10,
@ -284,6 +295,8 @@ describe("Test fetchStats", () => {
totalCommits: 100,
totalIssues: 200,
totalPRs: 300,
totalPRsMerged: 240,
mergedPRsPercentage: 80,
totalReviews: 50,
totalStars: 300,
totalDiscussionsStarted: 10,
@ -313,6 +326,8 @@ describe("Test fetchStats", () => {
totalCommits: 100,
totalIssues: 200,
totalPRs: 300,
totalPRsMerged: 240,
mergedPRsPercentage: 80,
totalReviews: 50,
totalStars: 300,
totalDiscussionsStarted: 10,

View file

@ -18,6 +18,8 @@ const stats = {
totalCommits: 200,
totalIssues: 300,
totalPRs: 400,
totalPRsMerged: 320,
mergedPRsPercentage: 80,
totalReviews: 50,
totalDiscussionsStarted: 10,
totalDiscussionsAnswered: 50,
@ -52,6 +54,10 @@ describe("Test renderStatsCard", () => {
expect(
queryByTestId(document.body, "discussions_answered"),
).not.toBeInTheDocument();
expect(queryByTestId(document.body, "prs_merged")).not.toBeInTheDocument();
expect(
queryByTestId(document.body, "prs_merged_percentage"),
).not.toBeInTheDocument();
});
it("should have proper name apostrophe", () => {
@ -85,16 +91,24 @@ describe("Test renderStatsCard", () => {
expect(queryByTestId(document.body, "reviews")).toBeNull();
expect(queryByTestId(document.body, "discussions_started")).toBeNull();
expect(queryByTestId(document.body, "discussions_answered")).toBeNull();
expect(queryByTestId(document.body, "prs_merged")).toBeNull();
expect(queryByTestId(document.body, "prs_merged_percentage")).toBeNull();
});
it("should show additional stats", () => {
document.body.innerHTML = renderStatsCard(stats, {
show: ["reviews", "discussions_started", "discussions_answered"],
show: [
"reviews",
"discussions_started",
"discussions_answered",
"prs_merged",
"prs_merged_percentage",
],
});
expect(
document.body.getElementsByTagName("svg")[0].getAttribute("height"),
).toBe("270");
).toBe("320");
expect(queryByTestId(document.body, "stars")).toBeDefined();
expect(queryByTestId(document.body, "commits")).toBeDefined();
@ -104,6 +118,8 @@ describe("Test renderStatsCard", () => {
expect(queryByTestId(document.body, "reviews")).toBeDefined();
expect(queryByTestId(document.body, "discussions_started")).toBeDefined();
expect(queryByTestId(document.body, "discussions_answered")).toBeDefined();
expect(queryByTestId(document.body, "prs_merged")).toBeDefined();
expect(queryByTestId(document.body, "prs_merged_percentage")).toBeDefined();
});
it("should hide_rank", () => {