Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💄Add download quantity statistics for the latest release. #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions common/configHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const getOptionalConfig = (repository: RepoQueryResponse['repository']) => {
const languages = repository.languages?.nodes || []
const language =
languages.length > 0 ? languages[0]?.name || 'unknown' : 'unknown'
const latestRelease = repository.latestRelease?.releaseAssets?.nodes || []
const totalDownloadCount = latestRelease.reduce(
(acc, cur) => acc + (cur?.downloadCount || 0),
0
)
const newConfig: OptionalConfigs = {
owner: { state: false, value: repository.owner.login },
name: { state: true, value: repository.name },
Expand All @@ -32,6 +37,7 @@ const getOptionalConfig = (repository: RepoQueryResponse['repository']) => {
},
language: { state: false, value: language },
stargazers: { state: false, value: repository.stargazerCount },
downloads: { state: false, value: totalDownloadCount },
forks: { state: false, value: repository.forkCount },
pulls: { state: false, value: repository.pullRequests.totalCount },
issues: { state: false, value: repository.issues.totalCount }
Expand Down
16 changes: 16 additions & 0 deletions common/github/repoQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export const getRepoDetails = async (owner: string, name: string) => {
tagName
}
}
latestRelease {
releaseAssets(last: 100) {
nodes {
name,
downloadCount
}
}
}
owner {
login
}
Expand Down Expand Up @@ -77,6 +85,14 @@ export type RepoQueryResponse = {
readonly tagName: string
} | null> | null
}
readonly latestRelease: {
readonly releaseAssets: {
readonly nodes: ReadonlyArray<{
readonly name: string
readonly downloadCount: number
} | null> | null
}
}
readonly owner: {
readonly login: string
}
Expand Down
1 change: 1 addition & 0 deletions common/types/configType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const OptionalConfigKeyStrings = {

const OptionalConfigKeyNumbers = {
stargazers: true,
downloads: true,
forks: true,
issues: true,
pulls: true
Expand Down
1 change: 1 addition & 0 deletions common/types/queryType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type QueryType = {

language: string
stargazers: string
downloads: string
forks: string
issues: string
pulls: string
Expand Down
2 changes: 1 addition & 1 deletion src/components/configuration/checkBoxWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const CheckBoxWrapper = ({
handleChange({ state: e.target.checked }, keyName)
}}
/>
<span className="label-text">{title}</span>
<span className="label-text whitespace-nowrap">{title}</span>
</label>
</div>
)
Expand Down
6 changes: 6 additions & 0 deletions src/components/configuration/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ const Config = ({ repository }: ConfigProp) => {
checked={config.stargazers?.state}
handleChange={handleChange}
/>
<CheckBoxWrapper
title="Latest Downloads"
keyName="downloads"
checked={config.downloads?.state}
handleChange={handleChange}
/>
<CheckBoxWrapper
title="Forks"
keyName="forks"
Expand Down
2 changes: 1 addition & 1 deletion src/components/hooks/use-autofocus.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from 'react'

const useAutoFocus = () => {
const inputRef = useCallback((inputElement) => {
const inputRef = useCallback((inputElement: HTMLInputElement) => {
if (inputElement) {
inputElement.focus()
}
Expand Down
7 changes: 7 additions & 0 deletions src/components/preview/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ export const Card = (config: Configuration) => {
color="#007ec6"
/>
)}
{config.downloads?.state && (
<Badge
name="lastest downloads"
value={`${config.downloads.value}`}
color="#4ec920"
/>
)}
{config.pulls?.state && (
<Badge
name="pulls"
Expand Down
Loading