Skip to content

Commit

Permalink
Merge branch 'feature/new-icons-to-card' into feature/private-reposit…
Browse files Browse the repository at this point in the history
…ories
  • Loading branch information
guistracini-outsurance-ie committed Jul 14, 2023
2 parents a460404 + 3ac209d commit b59d36a
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ body:
required: true
- type: textarea
attributes:
label: Expected behavior
label: Expected behaviour
description:
A clear and concise description of what you expected to happen.
- type: textarea
Expand Down
2 changes: 2 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default async (req, res) => {
card_width,
hide_rank,
show_icons,
count_private,
include_all_commits,
line_height,
title_color,
Expand Down Expand Up @@ -52,6 +53,7 @@ export default async (req, res) => {
try {
const stats = await fetchStats(
username,
parseBoolean(count_private),
parseBoolean(include_all_commits),
parseArray(exclude_repo),
);
Expand Down
18 changes: 15 additions & 3 deletions api/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export default async (req, res) => {
bg_color,
theme,
show_owner,
show_stars,
show_forks,
show_issues,
show_pull_requests,
cache_seconds,
locale,
border_radius,
Expand Down Expand Up @@ -55,9 +59,13 @@ export default async (req, res) => {
*/
const stars = repoData.starCount;
const forks = repoData.forkCount;
const isBothOver1K = stars > 1000 && forks > 1000;
const isBothUnder1 = stars < 1 && forks < 1;
if (!cache_seconds && (isBothOver1K || isBothUnder1)) {
const issues = repoData.issuesCount;
const pullRequests = repoData.pullRequestsCount;
const isAllOver1K =
stars > 1000 && forks > 1000 && issues > 1000 && pullRequests > 1000;
const isAllUnder1 =
stars < 1 && forks < 1 && issues < 1 && pullRequests < 1;
if (!cache_seconds && (isAllOver1K || isAllUnder1)) {
cacheSeconds = CONSTANTS.FOUR_HOURS;
}

Expand All @@ -79,6 +87,10 @@ export default async (req, res) => {
border_radius,
border_color,
show_owner: parseBoolean(show_owner),
show_stars: parseBoolean(show_stars),
show_forks: parseBoolean(show_forks),
show_issues: parseBoolean(show_issues),
show_pull_requests: parseBoolean(show_pull_requests),
locale: locale ? locale.toLowerCase() : null,
}),
);
Expand Down
37 changes: 31 additions & 6 deletions src/cards/repo-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ const renderRepoCard = (repo, options = {}) => {
isTemplate,
starCount,
forkCount,
issuesCount,
pullRequestsCount,
} = repo;
const {
hide_border = false,
Expand All @@ -108,6 +110,10 @@ const renderRepoCard = (repo, options = {}) => {
border_radius,
border_color,
locale,
show_stars = true,
show_forks = true,
show_issues = false,
show_pull_requests = false,
} = options;

const lineHeight = 10;
Expand Down Expand Up @@ -146,15 +152,34 @@ const renderRepoCard = (repo, options = {}) => {

const totalStars = kFormatter(starCount);
const totalForks = kFormatter(forkCount);
const totalIssues = kFormatter(issuesCount);
const totalPullRequests = kFormatter(pullRequestsCount);

const svgStars = iconWithLabel(icons.star, totalStars, "stargazers");
const svgForks = iconWithLabel(icons.fork, totalForks, "forkcount");

const starAndForkCount = flexLayout({
items: [svgLanguage, svgStars, svgForks],
const svgIssues = iconWithLabel(icons.issues, totalIssues, "issuescount");
const svgPullRequests = iconWithLabel(
icons.prs,
totalPullRequests,
"pullrequestscount",
);

const counters = flexLayout({
items: [
svgLanguage,
...(show_stars ? [svgStars] : []),
...(show_forks ? [svgForks] : []),
...(show_issues ? [svgIssues] : []),
...(show_pull_requests ? [svgPullRequests] : []),
],
sizes: [
measureText(langName, 12),
ICON_SIZE + measureText(`${totalStars}`, 12),
ICON_SIZE + measureText(`${totalForks}`, 12),
...(show_stars ? [ICON_SIZE + measureText(`${totalStars}`, 12)] : []),
...(show_forks ? [ICON_SIZE + measureText(`${totalForks}`, 12)] : []),
...(show_issues ? [ICON_SIZE + measureText(`${totalIssues}`, 12)] : []),
...(show_pull_requests
? [ICON_SIZE + measureText(`${totalPullRequests}`, 12)]
: []),
],
gap: 25,
}).join("");
Expand Down Expand Up @@ -195,7 +220,7 @@ const renderRepoCard = (repo, options = {}) => {
</text>
<g transform="translate(30, ${height - 75})">
${starAndForkCount}
${counters}
</g>
`);
};
Expand Down
12 changes: 11 additions & 1 deletion src/fetchers/repo-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ const fetcher = (variables, token) => {
id
name
}
forkCount
forkCount,
openIssues: issues(states: OPEN) {
totalCount
},
openPullRequests: pullRequests(states:OPEN) {
totalCount
}
}
query getRepo($login: String!, $repo: String!) {
user(login: $login) {
Expand Down Expand Up @@ -85,6 +91,8 @@ const fetchRepo = async (username, reponame) => {
return {
...data.user.repository,
starCount: data.user.repository.stargazers.totalCount,
issuesCount: data.user.repository.openIssues.totalCount,
pullRequestsCount: data.user.repository.openPullRequests.totalCount,
};
}

Expand All @@ -95,6 +103,8 @@ const fetchRepo = async (username, reponame) => {
return {
...data.organization.repository,
starCount: data.organization.repository.stargazers.totalCount,
issuesCount: data.organization.repository.openIssues.totalCount,
pullRequestsCount: data.organization.repository.openPullRequests.totalCount,
};
}
};
Expand Down
32 changes: 32 additions & 0 deletions tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,38 @@ describe("Test /api/", () => {
}
});

it("should add private contributions", async () => {
const { req, res } = faker(
{
username: "anuraghazra",
count_private: true,
},
data_stats,
);

await api(req, res);

expect(res.setHeader).toBeCalledWith("Content-Type", "image/svg+xml");
expect(res.send).toBeCalledWith(
renderStatsCard(
{
...stats,
totalCommits: stats.totalCommits + 100,
rank: calculateRank({
totalCommits: stats.totalCommits + 100,
totalRepos: 1,
followers: 0,
contributions: stats.contributedTo,
stargazers: stats.totalStars,
prs: stats.totalPRs,
issues: stats.totalIssues,
}),
},
{},
),
);
});

it("should allow changing ring_color", async () => {
const { req, res } = faker(
{
Expand Down
10 changes: 10 additions & 0 deletions tests/fetchRepo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const data_repo = {
name: "TypeScript",
},
forkCount: 100,
openIssues: {
totalCount: 45,
},
openPullRequests: {
totalCount: 10,
},
},
};

Expand Down Expand Up @@ -47,6 +53,8 @@ describe("Test fetchRepo", () => {
expect(repo).toStrictEqual({
...data_repo.repository,
starCount: data_repo.repository.stargazers.totalCount,
issuesCount: data_repo.repository.openIssues.totalCount,
pullRequestsCount: data_repo.repository.openPullRequests.totalCount,
});
});

Expand All @@ -57,6 +65,8 @@ describe("Test fetchRepo", () => {
expect(repo).toStrictEqual({
...data_repo.repository,
starCount: data_repo.repository.stargazers.totalCount,
issuesCount: data_repo.repository.openIssues.totalCount,
pullRequestsCount: data_repo.repository.openPullRequests.totalCount,
});
});

Expand Down
10 changes: 10 additions & 0 deletions tests/pin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const data_repo = {
name: "TypeScript",
},
forkCount: 100,
openIssues: {
totalCount: 45,
},
openPullRequests: {
totalCOunt: 10,
},
isTemplate: false,
},
};
Expand Down Expand Up @@ -59,6 +65,8 @@ describe("Test /api/pin", () => {
renderRepoCard({
...data_repo.repository,
starCount: data_repo.repository.stargazers.totalCount,
issuesCount: data_repo.repository.openIssues.totalCount,
pullRequestsCount: data_repo.repository.openPullRequests.totalCount,
}),
);
});
Expand Down Expand Up @@ -89,6 +97,8 @@ describe("Test /api/pin", () => {
{
...data_repo.repository,
starCount: data_repo.repository.stargazers.totalCount,
issuesCount: data_repo.repository.openIssues.totalCount,
pullRequestsCount: data_repo.repository.openPullRequests.totalCount,
},
{ ...req.query },
),
Expand Down
20 changes: 20 additions & 0 deletions tests/renderRepoCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const data_repo = {
},
starCount: 38000,
forkCount: 100,
issuesCount: 4500,
pullRequestsCount: 10,
},
};

Expand Down Expand Up @@ -52,6 +54,24 @@ describe("Test renderRepoCard", () => {
);
});

it("should display issues count", () => {
document.body.innerHTML = renderRepoCard(data_repo.repository, {
show_issues: true,
});
expect(queryByTestId(document.body, "issuescount")).toHaveTextContent(
"4.5k",
);
});

it("should display pull requests count", () => {
document.body.innerHTML = renderRepoCard(data_repo.repository, {
show_pull_requests: true,
});
expect(queryByTestId(document.body, "pullrequestscount")).toHaveTextContent(
"10",
);
});

it("should trim header", () => {
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
Expand Down

0 comments on commit b59d36a

Please sign in to comment.