Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
feat: prettier Integration (#154)
Browse files Browse the repository at this point in the history
* Prettier file

* New package

* Script

* Husky

* Prettier
  • Loading branch information
Bashamega authored Oct 1, 2024
1 parent 68244be commit fac084f
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
npm run lint
# npm test

npm run format:check
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 2,
"useTabs": false
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand All @@ -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) |

Expand Down
19 changes: 18 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -31,6 +33,7 @@
"eslint-config-next": "14.0.4",
"husky": "^9.0.11",
"postcss": "^8",
"prettier": "3.3.3",
"tailwindcss": "^3.3.0"
}
}
2 changes: 1 addition & 1 deletion postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};
4 changes: 2 additions & 2 deletions src/app/api/activity/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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,
};
Expand Down
8 changes: 6 additions & 2 deletions src/app/api/badge/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -29,7 +33,7 @@ export async function GET(request) {
data.$id,
{
badgeViews: data.badgeViews + 1,
}
},
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/api/leaderboard/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/popular/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions src/app/api/rate/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ 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];

// 1. check if user already rated this repo
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
Expand All @@ -72,7 +72,7 @@ export async function POST(request) {
username: username,
url: urlClean,
rating: rating,
}
},
);
} else {
// 2b. create in ratings collection
Expand All @@ -85,7 +85,7 @@ export async function POST(request) {
username: username,
url: urlClean,
rating: rating,
}
},
);
}

Expand All @@ -98,15 +98,15 @@ export async function POST(request) {
{
ratings: appTotal.ratings + 1,
stars: appTotal.stars + rating,
}
},
);

// 3. check if repo exists
console.info(`Checking if repo ${urlClean} exists in database`);
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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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");
Expand All @@ -157,7 +157,7 @@ export async function POST(request) {
appTotal.$id,
{
repos: appTotal.repos + 1,
}
},
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/api/repos/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/stats/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/rankings/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/rate/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} 🎉`,
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/components/Repos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -113,7 +113,9 @@ export default function Repos({ minimumVotes = 5, keyword, sort }) {
<span className="absolute inset-0" />
</Link>
</h2>
{repo.language && <p className="text-xs text-gray-400">({repo.language})</p>}
{repo.language && (
<p className="text-xs text-gray-400">({repo.language})</p>
)}
{repo.stars && (
<p className="text-xs hidden sm:inline-block text-gray-400">
({abbreviateNumber(repo.stars)} ⭐️)
Expand Down
9 changes: 4 additions & 5 deletions src/components/SideNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ServerIcon,
StarIcon,
XMarkIcon,
PuzzlePieceIcon
PuzzlePieceIcon,
} from "@heroicons/react/24/outline";
import { Bars3Icon, MagnifyingGlassIcon } from "@heroicons/react/20/solid";

Expand All @@ -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}/`,
);
};

Expand Down Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion src/components/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
3 changes: 2 additions & 1 deletion src/config/app.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"version": "0.5.1"
}
}

0 comments on commit fac084f

Please sign in to comment.