From e1020ea09c570bc02ab545a113b5b43db3528c14 Mon Sep 17 00:00:00 2001 From: punyamsingh <89277920+punyamsingh@users.noreply.github.com> Date: Wed, 14 Jun 2023 21:19:40 +0530 Subject: [PATCH 01/13] issue#112 resolved. submitting for review --- src/popup/pages/profile.tsx | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/popup/pages/profile.tsx b/src/popup/pages/profile.tsx index dc8b8dfc..8fdb19ad 100644 --- a/src/popup/pages/profile.tsx +++ b/src/popup/pages/profile.tsx @@ -35,10 +35,34 @@ type InterestIconKeys = keyof typeof interestIcon; export const Profile = ({ username }: { username: string }) => { const [user, setUser] = useState(null); - const [userPR, setUserPR] = useState(null); + const [userPR, setUserPR] = useState(null); const [userHighlights, setUserHighlights] = useState(null); const [userPRVelocity, setUserPRVelocity] = useState(0); + interface PRResponse { + data: [{ + full_name: string; + }] + meta: { + itemCount: number; + }; + } + + function countUniqueFullNames(response: PRResponse | null): number { + if (!response || !response.data) { + return 0; + } + + const { data } = response; + const uniqueFullNames = new Set(); + + for (const obj of data) { + uniqueFullNames.add(obj.full_name); + } + + return uniqueFullNames.size; + } + useEffect(() => { const fetchUserData = async () => { const [userData, userPRData, userHighlightsData] = await Promise.all([getUserData(username), getUserPRData(username), getUserHighlightsData(username)]); @@ -82,7 +106,7 @@ export const Profile = ({ username }: { username: string }) => { }} > - Log Out + Log Out @@ -178,7 +202,9 @@ export const Profile = ({ username }: { username: string }) => {

Contributed Repos

-

-

+

+ {countUniqueFullNames(userPR)} +

From d37fb720ece7b61a96a1d4da3be54d325d57a27a Mon Sep 17 00:00:00 2001 From: punyamsingh <89277920+punyamsingh@users.noreply.github.com> Date: Wed, 14 Jun 2023 21:26:05 +0530 Subject: [PATCH 02/13] issue#112 resolved. submitting for review --- src/popup/pages/profile.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/popup/pages/profile.tsx b/src/popup/pages/profile.tsx index 8fdb19ad..24410d48 100644 --- a/src/popup/pages/profile.tsx +++ b/src/popup/pages/profile.tsx @@ -48,14 +48,15 @@ export const Profile = ({ username }: { username: string }) => { }; } - function countUniqueFullNames(response: PRResponse | null): number { + function countUniqueFullNames (response: PRResponse | null): number { if (!response || !response.data) { return 0; } const { data } = response; - const uniqueFullNames = new Set(); + const uniqueFullNames = (new Set); + // eslint-disable-next-line no-loops/no-loops for (const obj of data) { uniqueFullNames.add(obj.full_name); } From ef38dd8977edb6301e3ac4e6dc54766a7270c17a Mon Sep 17 00:00:00 2001 From: punyamsingh <89277920+punyamsingh@users.noreply.github.com> Date: Wed, 14 Jun 2023 22:57:42 +0530 Subject: [PATCH 03/13] profile.tsx added line 59 --- src/popup/pages/profile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/popup/pages/profile.tsx b/src/popup/pages/profile.tsx index 24410d48..3840d558 100644 --- a/src/popup/pages/profile.tsx +++ b/src/popup/pages/profile.tsx @@ -49,7 +49,7 @@ export const Profile = ({ username }: { username: string }) => { } function countUniqueFullNames (response: PRResponse | null): number { - if (!response || !response.data) { + if (!response?.data) { return 0; } From 67055352cf0ed49353f9dc8e1ce05fbb50c39bd7 Mon Sep 17 00:00:00 2001 From: punyamsingh <89277920+punyamsingh@users.noreply.github.com> Date: Wed, 14 Jun 2023 23:49:54 +0530 Subject: [PATCH 04/13] shifted the function & interface to dateUtils.ts --- src/popup/pages/profile.tsx | 28 ++-------------------------- src/utils/dateUtils.ts | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/popup/pages/profile.tsx b/src/popup/pages/profile.tsx index 3840d558..2c601533 100644 --- a/src/popup/pages/profile.tsx +++ b/src/popup/pages/profile.tsx @@ -7,7 +7,7 @@ import OpenSaucedLogo from "../../assets/opensauced-logo.svg"; import { getUserData, getUserPRData, getUserHighlightsData } from "../../utils/fetchOpenSaucedApiData"; import { emojify } from "node-emoji"; import { goBack, goTo } from "react-chrome-extension-router"; -import { getRelativeDays } from "../../utils/dateUtils"; +import { getRelativeDays, countUniqueFullNames } from "../../utils/dateUtils"; import { getUserPRVelocity } from "../../utils/getUserPRVelocity"; import { BiExit } from "react-icons/bi"; import Start from "./start"; @@ -39,31 +39,6 @@ export const Profile = ({ username }: { username: string }) => { const [userHighlights, setUserHighlights] = useState(null); const [userPRVelocity, setUserPRVelocity] = useState(0); - interface PRResponse { - data: [{ - full_name: string; - }] - meta: { - itemCount: number; - }; - } - - function countUniqueFullNames (response: PRResponse | null): number { - if (!response?.data) { - return 0; - } - - const { data } = response; - const uniqueFullNames = (new Set); - - // eslint-disable-next-line no-loops/no-loops - for (const obj of data) { - uniqueFullNames.add(obj.full_name); - } - - return uniqueFullNames.size; - } - useEffect(() => { const fetchUserData = async () => { const [userData, userPRData, userHighlightsData] = await Promise.all([getUserData(username), getUserPRData(username), getUserHighlightsData(username)]); @@ -204,6 +179,7 @@ export const Profile = ({ username }: { username: string }) => {

Contributed Repos

+ {/* eslint-disable-next-line @typescript-eslint/no-unsafe-call*/} {countUniqueFullNames(userPR)}

diff --git a/src/utils/dateUtils.ts b/src/utils/dateUtils.ts index c741ac5b..8368d47a 100644 --- a/src/utils/dateUtils.ts +++ b/src/utils/dateUtils.ts @@ -13,3 +13,28 @@ export const getRelativeDays = (days: number) => { return `${days}d`; }; + +interface PRResponse { + data: [{ + full_name: string; + }] + meta: { + itemCount: number; + }; +} + +export const countUniqueFullNames = (response: PRResponse | null) => { + if (!response?.data) { + return 0; + } + + const { data } = response; + const uniqueFullNames = (new Set); + + // eslint-disable-next-line no-loops/no-loops + for (const obj of data) { + uniqueFullNames.add(obj.full_name); + } + + return uniqueFullNames.size; +} From eb19ed4d67954a71c16188c0f3435337950be017 Mon Sep 17 00:00:00 2001 From: punyamsingh <89277920+punyamsingh@users.noreply.github.com> Date: Thu, 15 Jun 2023 00:10:21 +0530 Subject: [PATCH 05/13] shited the function to getContributedRepos.ts --- src/popup/pages/profile.tsx | 3 ++- src/utils/dateUtils.ts | 25 ------------------------- src/utils/getContributedRepos.ts | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 src/utils/getContributedRepos.ts diff --git a/src/popup/pages/profile.tsx b/src/popup/pages/profile.tsx index 2c601533..de81ac18 100644 --- a/src/popup/pages/profile.tsx +++ b/src/popup/pages/profile.tsx @@ -7,7 +7,8 @@ import OpenSaucedLogo from "../../assets/opensauced-logo.svg"; import { getUserData, getUserPRData, getUserHighlightsData } from "../../utils/fetchOpenSaucedApiData"; import { emojify } from "node-emoji"; import { goBack, goTo } from "react-chrome-extension-router"; -import { getRelativeDays, countUniqueFullNames } from "../../utils/dateUtils"; +import { getRelativeDays } from "../../utils/dateUtils"; +import { countUniqueFullNames } from "../../utils/getContributedRepos"; import { getUserPRVelocity } from "../../utils/getUserPRVelocity"; import { BiExit } from "react-icons/bi"; import Start from "./start"; diff --git a/src/utils/dateUtils.ts b/src/utils/dateUtils.ts index 8368d47a..c741ac5b 100644 --- a/src/utils/dateUtils.ts +++ b/src/utils/dateUtils.ts @@ -13,28 +13,3 @@ export const getRelativeDays = (days: number) => { return `${days}d`; }; - -interface PRResponse { - data: [{ - full_name: string; - }] - meta: { - itemCount: number; - }; -} - -export const countUniqueFullNames = (response: PRResponse | null) => { - if (!response?.data) { - return 0; - } - - const { data } = response; - const uniqueFullNames = (new Set); - - // eslint-disable-next-line no-loops/no-loops - for (const obj of data) { - uniqueFullNames.add(obj.full_name); - } - - return uniqueFullNames.size; -} diff --git a/src/utils/getContributedRepos.ts b/src/utils/getContributedRepos.ts new file mode 100644 index 00000000..2c6f6340 --- /dev/null +++ b/src/utils/getContributedRepos.ts @@ -0,0 +1,24 @@ +interface PRResponse { + data: [{ + full_name: string; + }] + meta: { + itemCount: number; + }; +} + +export const countUniqueFullNames = (response: PRResponse | null) => { + if (!response?.data) { + return 0; + } + + const { data } = response; + const uniqueFullNames = (new Set); + + // eslint-disable-next-line no-loops/no-loops + for (const obj of data) { + uniqueFullNames.add(obj.full_name); + } + + return uniqueFullNames.size; +} From e6b268769d258d730933f2a38124f10b44b84e9e Mon Sep 17 00:00:00 2001 From: Punyam Singh <89277920+punyamsingh@users.noreply.github.com> Date: Thu, 15 Jun 2023 00:39:25 +0530 Subject: [PATCH 06/13] Update src/popup/pages/profile.tsx Co-authored-by: Brian Douglas --- src/popup/pages/profile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/popup/pages/profile.tsx b/src/popup/pages/profile.tsx index de81ac18..da7edae2 100644 --- a/src/popup/pages/profile.tsx +++ b/src/popup/pages/profile.tsx @@ -8,7 +8,7 @@ import { getUserData, getUserPRData, getUserHighlightsData } from "../../utils/f import { emojify } from "node-emoji"; import { goBack, goTo } from "react-chrome-extension-router"; import { getRelativeDays } from "../../utils/dateUtils"; -import { countUniqueFullNames } from "../../utils/getContributedRepos"; +import { countUniqueRepos} from "../../utils/getContributedRepos"; import { getUserPRVelocity } from "../../utils/getUserPRVelocity"; import { BiExit } from "react-icons/bi"; import Start from "./start"; From 35c1d6059abe0fb99d24d30379e4669ec1084844 Mon Sep 17 00:00:00 2001 From: Punyam Singh <89277920+punyamsingh@users.noreply.github.com> Date: Thu, 15 Jun 2023 00:39:49 +0530 Subject: [PATCH 07/13] Update src/utils/getContributedRepos.ts Co-authored-by: Brian Douglas --- src/utils/getContributedRepos.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/getContributedRepos.ts b/src/utils/getContributedRepos.ts index 2c6f6340..2d263c7b 100644 --- a/src/utils/getContributedRepos.ts +++ b/src/utils/getContributedRepos.ts @@ -7,7 +7,7 @@ interface PRResponse { }; } -export const countUniqueFullNames = (response: PRResponse | null) => { +export const countUniqueRepos = (response: PRResponse | null) => { if (!response?.data) { return 0; } From b9a1264dbd3bcfda661768de841ab0ae5ebd5244 Mon Sep 17 00:00:00 2001 From: Punyam Singh <89277920+punyamsingh@users.noreply.github.com> Date: Thu, 15 Jun 2023 00:39:59 +0530 Subject: [PATCH 08/13] Update src/utils/getContributedRepos.ts Co-authored-by: Brian Douglas --- src/utils/getContributedRepos.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/getContributedRepos.ts b/src/utils/getContributedRepos.ts index 2d263c7b..c612cbd5 100644 --- a/src/utils/getContributedRepos.ts +++ b/src/utils/getContributedRepos.ts @@ -13,7 +13,7 @@ export const countUniqueRepos = (response: PRResponse | null) => { } const { data } = response; - const uniqueFullNames = (new Set); + const uniqueRepos = (new Set); // eslint-disable-next-line no-loops/no-loops for (const obj of data) { From 2fecf46af748771a025c54daa4cc8f9b31644729 Mon Sep 17 00:00:00 2001 From: Punyam Singh <89277920+punyamsingh@users.noreply.github.com> Date: Thu, 15 Jun 2023 00:40:07 +0530 Subject: [PATCH 09/13] Update src/utils/getContributedRepos.ts Co-authored-by: Brian Douglas --- src/utils/getContributedRepos.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/getContributedRepos.ts b/src/utils/getContributedRepos.ts index c612cbd5..1e6d055c 100644 --- a/src/utils/getContributedRepos.ts +++ b/src/utils/getContributedRepos.ts @@ -20,5 +20,5 @@ export const countUniqueRepos = (response: PRResponse | null) => { uniqueFullNames.add(obj.full_name); } - return uniqueFullNames.size; + return uniqueRepos.size; } From afefa93487cdc831bf599613660e51f467bf0474 Mon Sep 17 00:00:00 2001 From: Punyam Singh <89277920+punyamsingh@users.noreply.github.com> Date: Thu, 15 Jun 2023 00:40:16 +0530 Subject: [PATCH 10/13] Update src/popup/pages/profile.tsx Co-authored-by: Brian Douglas --- src/popup/pages/profile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/popup/pages/profile.tsx b/src/popup/pages/profile.tsx index da7edae2..be05d7e8 100644 --- a/src/popup/pages/profile.tsx +++ b/src/popup/pages/profile.tsx @@ -181,7 +181,7 @@ export const Profile = ({ username }: { username: string }) => {

{/* eslint-disable-next-line @typescript-eslint/no-unsafe-call*/} - {countUniqueFullNames(userPR)} + {countUniqueRepos(userPR)}

From 8c6ec1cca8bb1c5527eb7641640f8b91a5cb08f7 Mon Sep 17 00:00:00 2001 From: Punyam Singh <89277920+punyamsingh@users.noreply.github.com> Date: Thu, 15 Jun 2023 00:40:28 +0530 Subject: [PATCH 11/13] Update src/utils/getContributedRepos.ts Co-authored-by: Brian Douglas --- src/utils/getContributedRepos.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/getContributedRepos.ts b/src/utils/getContributedRepos.ts index 1e6d055c..e9af4b21 100644 --- a/src/utils/getContributedRepos.ts +++ b/src/utils/getContributedRepos.ts @@ -17,7 +17,7 @@ export const countUniqueRepos = (response: PRResponse | null) => { // eslint-disable-next-line no-loops/no-loops for (const obj of data) { - uniqueFullNames.add(obj.full_name); + uniqueRepos.add(obj.full_name); } return uniqueRepos.size; From 480ed410764412c5cbd0fa52af81b6ddbd3bf919 Mon Sep 17 00:00:00 2001 From: punyamsingh <89277920+punyamsingh@users.noreply.github.com> Date: Thu, 15 Jun 2023 02:22:08 +0530 Subject: [PATCH 12/13] removed eslint from the loop --- src/popup/pages/profile.tsx | 5 ++--- src/utils/getContributedRepos.ts | 15 +++++---------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/popup/pages/profile.tsx b/src/popup/pages/profile.tsx index be05d7e8..2c0a80e7 100644 --- a/src/popup/pages/profile.tsx +++ b/src/popup/pages/profile.tsx @@ -8,7 +8,7 @@ import { getUserData, getUserPRData, getUserHighlightsData } from "../../utils/f import { emojify } from "node-emoji"; import { goBack, goTo } from "react-chrome-extension-router"; import { getRelativeDays } from "../../utils/dateUtils"; -import { countUniqueRepos} from "../../utils/getContributedRepos"; +import { countUniqueRepos, PRResponse } from "../../utils/getContributedRepos"; import { getUserPRVelocity } from "../../utils/getUserPRVelocity"; import { BiExit } from "react-icons/bi"; import Start from "./start"; @@ -36,7 +36,7 @@ type InterestIconKeys = keyof typeof interestIcon; export const Profile = ({ username }: { username: string }) => { const [user, setUser] = useState(null); - const [userPR, setUserPR] = useState(null); + const [userPR, setUserPR] = useState(null); const [userHighlights, setUserHighlights] = useState(null); const [userPRVelocity, setUserPRVelocity] = useState(0); @@ -180,7 +180,6 @@ export const Profile = ({ username }: { username: string }) => {

Contributed Repos

- {/* eslint-disable-next-line @typescript-eslint/no-unsafe-call*/} {countUniqueRepos(userPR)}

diff --git a/src/utils/getContributedRepos.ts b/src/utils/getContributedRepos.ts index e9af4b21..71aca96e 100644 --- a/src/utils/getContributedRepos.ts +++ b/src/utils/getContributedRepos.ts @@ -1,24 +1,19 @@ -interface PRResponse { - data: [{ +export interface PRResponse { + data: { full_name: string; - }] + }[] meta: { itemCount: number; }; } -export const countUniqueRepos = (response: PRResponse | null) => { +export const countUniqueRepos = (response: PRResponse | null):number => { if (!response?.data) { return 0; } const { data } = response; - const uniqueRepos = (new Set); - - // eslint-disable-next-line no-loops/no-loops - for (const obj of data) { - uniqueRepos.add(obj.full_name); - } + const uniqueRepos = new Set(data.map(obj => obj.full_name)); return uniqueRepos.size; } From 154156cc134a4cc25967cfc5b8b3f28fd35cd82a Mon Sep 17 00:00:00 2001 From: Divyansh Singh Date: Thu, 15 Jun 2023 03:12:59 +0530 Subject: [PATCH 13/13] add semicolon to pass lint check --- src/utils/getContributedRepos.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/getContributedRepos.ts b/src/utils/getContributedRepos.ts index 71aca96e..48913ca6 100644 --- a/src/utils/getContributedRepos.ts +++ b/src/utils/getContributedRepos.ts @@ -16,4 +16,4 @@ export const countUniqueRepos = (response: PRResponse | null):number => { const uniqueRepos = new Set(data.map(obj => obj.full_name)); return uniqueRepos.size; -} +};