diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index 3228983..81f17ab 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -28,8 +28,8 @@ body: id: steps attributes: label: Steps to Reproduce - description: To help us recreate the bug, provide a numbered list of the exact steps taken to trigger the buggy behavior. - value: | + description: To help us recreate the bug, provide a numbered list of the exact steps taken to trigger the buggy behavior. + value: | If you know the steps, follow the below format and provide steps to reproduce For example: diff --git a/.husky/pre-commit b/.husky/pre-commit index 3867a0f..f9c572c 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1,4 @@ npm run lint +# npm test + +npm run format:check \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..222861c --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "tabWidth": 2, + "useTabs": false +} diff --git a/README.md b/README.md index b351953..fdaf71d 100644 --- a/README.md +++ b/README.md @@ -88,8 +88,8 @@ The default badge is "flat" but there are other styles if you prefer. This is do Here are the options with examples: -| style | badge | -| :------------ | :-------------------------------------------------------------------------------------------------------------------- | +| style | badge | +| :------------ | :--------------------------------------------------------------------------------------------------------------------- | | flat | ![flat](https://repo-rater.eddiehub.org/api/badge?owner=EddieHubCommunity&name=RepoRater&style=flat) | | flat-square | ![flat-square](https://repo-rater.eddiehub.org/api/badge?owner=EddieHubCommunity&name=RepoRater&style=flat-square) | | for-the-badge | ![for-the-badge](https://repo-rater.eddiehub.org/api/badge?owner=EddieHubCommunity&name=RepoRater&style=for-the-badge) | @@ -106,8 +106,8 @@ The default badge format is to show the average rating out of `5`. You can also [![RepoRater](https://repo-rater.eddiehub.org/api/badge?owner=EddieHubCommunity&name=RepoRater)](https://repo-rater.eddiehub.org/rate?owner=EddieHubCommunity&name=RepoRater&format=percentage) ``` -| format | badge | -| :--------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| format | badge | +| :--------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | number | [![RepoRater](https://repo-rater.eddiehub.org/api/badge?owner=EddieHubCommunity&name=RepoRater&format=number)](https://repo-rater.eddiehub.org/rate?owner=EddieHubCommunity&name=RepoRater) | | percentage | [![RepoRater](https://repo-rater.eddiehub.org/api/badge?owner=EddieHubCommunity&name=RepoRater&format=percentage)](https://repo-rater.eddiehub.org/rate?owner=EddieHubCommunity&name=RepoRater) | diff --git a/package-lock.json b/package-lock.json index 0354ebc..80676f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "repo-rater4", - "version": "0.2.1", + "version": "0.6.0", "dependencies": { "@headlessui/react": "^1.7.17", "@heroicons/react": "^2.1.1", @@ -29,6 +29,7 @@ "eslint-config-next": "14.0.4", "husky": "^9.0.11", "postcss": "^8", + "prettier": "3.3.3", "tailwindcss": "^3.3.0" } }, @@ -4126,6 +4127,22 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/prop-types": { "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", diff --git a/package.json b/package.json index fff5b50..c03f4c9 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "build": "next build", "start": "next start", "lint": "next lint", - "prepare": "husky" + "prepare": "husky", + "format:write": "prettier . --write", + "format:check": "prettier . --check" }, "dependencies": { "@headlessui/react": "^1.7.17", @@ -31,6 +33,7 @@ "eslint-config-next": "14.0.4", "husky": "^9.0.11", "postcss": "^8", + "prettier": "3.3.3", "tailwindcss": "^3.3.0" } } diff --git a/postcss.config.js b/postcss.config.js index 33ad091..12a703d 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -3,4 +3,4 @@ module.exports = { tailwindcss: {}, autoprefixer: {}, }, -} +}; diff --git a/src/app/api/activity/route.js b/src/app/api/activity/route.js index 9568100..b108554 100644 --- a/src/app/api/activity/route.js +++ b/src/app/api/activity/route.js @@ -15,7 +15,7 @@ export async function GET() { let ratings = await new Databases(clientAdmin()).listDocuments( process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID, process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_RATINGS_ID, - [Query.orderDesc("$updatedAt"), Query.limit(25)] + [Query.orderDesc("$updatedAt"), Query.limit(25)], ); ratings = ratings.documents.map((rating) => { @@ -26,7 +26,7 @@ export async function GET() { owner: path.owner, name: path.name, timeAgo: timeAgo.format( - Math.floor(new Date(rating.$updatedAt).getTime()) + Math.floor(new Date(rating.$updatedAt).getTime()), ), updatedAt: rating.$updatedAt, }; diff --git a/src/app/api/badge/route.js b/src/app/api/badge/route.js index 9d2ad7e..958522d 100644 --- a/src/app/api/badge/route.js +++ b/src/app/api/badge/route.js @@ -17,7 +17,11 @@ export async function GET(request) { const repos = await new sdk.Databases(clientAdmin()).listDocuments( process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID, process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_REPOS_ID, - [Query.equal("owner", [owner]), Query.equal("name", [name]), Query.limit(1)] + [ + Query.equal("owner", [owner]), + Query.equal("name", [name]), + Query.limit(1), + ], ); const data = repos.documents[0]; @@ -29,7 +33,7 @@ export async function GET(request) { data.$id, { badgeViews: data.badgeViews + 1, - } + }, ); } diff --git a/src/app/api/leaderboard/route.js b/src/app/api/leaderboard/route.js index edb7308..db3f632 100644 --- a/src/app/api/leaderboard/route.js +++ b/src/app/api/leaderboard/route.js @@ -8,7 +8,7 @@ export async function GET() { const ratings = await new Databases(clientAdmin()).listDocuments( process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID, process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_RATINGS_ID, - [Query.limit(1000)] + [Query.limit(1000)], ); const users = ratings.documents.reduce((acc, rating) => { if (!acc[rating.username]) { diff --git a/src/app/api/popular/route.js b/src/app/api/popular/route.js index 055e852..6b620e1 100644 --- a/src/app/api/popular/route.js +++ b/src/app/api/popular/route.js @@ -26,11 +26,11 @@ export async function GET(request) { Query.orderDesc("votes"), Query.greaterThanEqual("votes", parseInt(minimumVotes) || 5), Query.limit(100), - ] + ], ); const data = repos.documents.map((repo) => - Object.fromEntries(fields.map((field) => [[field], repo[field]])) + Object.fromEntries(fields.map((field) => [[field], repo[field]])), ); return Response.json(data); diff --git a/src/app/api/rate/route.js b/src/app/api/rate/route.js index 23a0bf4..a0ae304 100644 --- a/src/app/api/rate/route.js +++ b/src/app/api/rate/route.js @@ -50,7 +50,7 @@ export async function POST(request) { await new sdk.Databases(clientAdmin()).listDocuments( process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID, process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_APP_ID, - [Query.limit(1)] + [Query.limit(1)], ) ).documents[0]; @@ -58,7 +58,7 @@ export async function POST(request) { const userRepoRating = await new sdk.Databases(clientAdmin()).listDocuments( process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID, process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_RATINGS_ID, - [Query.equal("url", [urlClean]), Query.equal("username", [username])] + [Query.equal("url", [urlClean]), Query.equal("username", [username])], ); // 2a. update in ratings collection @@ -72,7 +72,7 @@ export async function POST(request) { username: username, url: urlClean, rating: rating, - } + }, ); } else { // 2b. create in ratings collection @@ -85,7 +85,7 @@ export async function POST(request) { username: username, url: urlClean, rating: rating, - } + }, ); } @@ -98,7 +98,7 @@ export async function POST(request) { { ratings: appTotal.ratings + 1, stars: appTotal.stars + rating, - } + }, ); // 3. check if repo exists @@ -106,7 +106,7 @@ export async function POST(request) { const repos = await new sdk.Databases(clientAdmin()).listDocuments( process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID, process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_REPOS_ID, - [Query.equal("url", [urlClean])] + [Query.equal("url", [urlClean])], ); // 4a. update in repos collection + calculate new rating @@ -116,7 +116,7 @@ export async function POST(request) { const ratings = await new sdk.Databases(clientAdmin()).listDocuments( process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID, process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_RATINGS_ID, - [Query.equal("url", [urlClean])] + [Query.equal("url", [urlClean])], ); // save new repo rating @@ -131,12 +131,12 @@ export async function POST(request) { ...githubRepo, rating: averageRating, votes: ratings.total, - } + }, ); } else { // 4a. create in repos collection console.info( - `Repo ${urlClean} not found in database create repo and ratings` + `Repo ${urlClean} not found in database create repo and ratings`, ); await new sdk.Databases(clientAdmin()).createDocument( process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID, @@ -147,7 +147,7 @@ export async function POST(request) { url: urlClean, rating: rating, votes: 1, - } + }, ); // 4b. update app repo count console.info("Increment app total repos"); @@ -157,7 +157,7 @@ export async function POST(request) { appTotal.$id, { repos: appTotal.repos + 1, - } + }, ); } diff --git a/src/app/api/repos/route.js b/src/app/api/repos/route.js index b901f01..91e90b4 100644 --- a/src/app/api/repos/route.js +++ b/src/app/api/repos/route.js @@ -47,11 +47,11 @@ export async function GET(request) { minimumVotes && Query.greaterThanEqual("votes", parseInt(minimumVotes)), Query.limit(100), keyword && Query.search("url", keyword), - ] + ], ); const data = repos.documents.map((repo) => - Object.fromEntries(fields.map((field) => [[field], repo[field]])) + Object.fromEntries(fields.map((field) => [[field], repo[field]])), ); return Response.json(data); diff --git a/src/app/api/stats/route.js b/src/app/api/stats/route.js index 1ddc934..13d8c24 100644 --- a/src/app/api/stats/route.js +++ b/src/app/api/stats/route.js @@ -9,7 +9,7 @@ export async function GET() { await new Databases(clientAdmin()).listDocuments( process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID, process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_APP_ID, - [Query.limit(1)] + [Query.limit(1)], ) ).documents[0]; diff --git a/src/app/layout.js b/src/app/layout.js index 8f4ae10..cc07693 100644 --- a/src/app/layout.js +++ b/src/app/layout.js @@ -7,7 +7,7 @@ import { classNames } from "@/utils/classNames"; const inter = Inter({ subsets: ["latin"] }); export const metadata = { - title: "RepoRater: Rate GitHub Repos for Developer Experience" + title: "RepoRater: Rate GitHub Repos for Developer Experience", }; export default function RootLayout({ children }) { diff --git a/src/app/rankings/page.js b/src/app/rankings/page.js index f3cfe2f..441f126 100644 --- a/src/app/rankings/page.js +++ b/src/app/rankings/page.js @@ -5,7 +5,7 @@ import Users from "@/components/Users"; export const dynamic = "force-dynamic"; export const metadata = { - title: "User Rankings - RepoRater" + title: "User Rankings - RepoRater", }; export default function Page() { diff --git a/src/app/rate/Form.js b/src/app/rate/Form.js index feca33b..3171ba5 100644 --- a/src/app/rate/Form.js +++ b/src/app/rate/Form.js @@ -39,7 +39,7 @@ export default function Form({ name = "", owner = "" }) { setSending(false); const info = urlToOwnerAndName(formData.get("url")); redirect( - `/?alert=success&message=Rating saved for ${info.owner}/${info.name} 🎉` + `/?alert=success&message=Rating saved for ${info.owner}/${info.name} 🎉`, ); } diff --git a/src/components/Repos.js b/src/components/Repos.js index 49bfa62..119afe4 100644 --- a/src/components/Repos.js +++ b/src/components/Repos.js @@ -48,7 +48,7 @@ export default function Repos({ minimumVotes = 5, keyword, sort }) { params.push(`sort=${sort}`); } const res = await fetch( - `/api/repos${params.length ? `?${params.join("&")}` : ""}` + `/api/repos${params.length ? `?${params.join("&")}` : ""}`, ); const data = await res.json(); @@ -113,7 +113,9 @@ export default function Repos({ minimumVotes = 5, keyword, sort }) { - {repo.language &&
({repo.language})
} + {repo.language && ( +({repo.language})
+ )} {repo.stars && (({abbreviateNumber(repo.stars)} ⭐️) diff --git a/src/components/SideNav.js b/src/components/SideNav.js index 6271d91..32ae7ec 100644 --- a/src/components/SideNav.js +++ b/src/components/SideNav.js @@ -10,7 +10,7 @@ import { ServerIcon, StarIcon, XMarkIcon, - PuzzlePieceIcon + PuzzlePieceIcon, } from "@heroicons/react/24/outline"; import { Bars3Icon, MagnifyingGlassIcon } from "@heroicons/react/20/solid"; @@ -30,7 +30,7 @@ export default function SideNav({ setKeyword, children }) { account.createOAuth2Session( "github", `${process.env.NEXT_PUBLIC_BASE_URL}/`, - `${process.env.NEXT_PUBLIC_BASE_URL}/` + `${process.env.NEXT_PUBLIC_BASE_URL}/`, ); }; @@ -86,11 +86,10 @@ export default function SideNav({ setKeyword, children }) { { name: "Download Browser Extension", href: "https://github.com/EddieHubCommunity/RepoRater-Chrome", - current:false, + current: false, external: true, icon: PuzzlePieceIcon, - - } + }, ]; const secure = [ diff --git a/src/components/Users.js b/src/components/Users.js index c3024fa..a26302c 100644 --- a/src/components/Users.js +++ b/src/components/Users.js @@ -23,7 +23,7 @@ export default async function Users() { const ratings = await new Databases(clientAdmin()).listDocuments( process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID, process.env.NEXT_PUBLIC_APPWRITE_COLLECTION_RATINGS_ID, - [Query.limit(1000)] + [Query.limit(1000)], ); const users = ratings.documents.reduce((acc, rating) => { if (!acc[rating.username]) { diff --git a/src/config/app.json b/src/config/app.json index 6baf8ab..65bfc71 100644 --- a/src/config/app.json +++ b/src/config/app.json @@ -1,3 +1,4 @@ { "version": "0.5.1" -} \ No newline at end of file +} +