Skip to content

Commit

Permalink
feat: readme check
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiejaoude committed Oct 2, 2024
1 parent d0b3cd6 commit bd7d560
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ yarn-error.log*
next-env.d.ts

.early.coverage
*.api.json
2 changes: 1 addition & 1 deletion src/checks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function checks(data: Data) {
goodFirstIssue(data.issues),
// branches(data.branches),
// release(data.release),
// readme(data.communityMetrics),
readme(data.community),
// license(data.communityMetrics),
// contributing(data.communityMetrics),
// pullRequestTemplate(data.communityMetrics),
Expand Down
16 changes: 10 additions & 6 deletions src/checks/readme.js → src/checks/readme.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
export default function readme(communityMetrics) {
let response = {
id: "readme",
href: "/repo/readme",
import { Community } from "@/models/github/community";
import { StatusCheck } from "@/types/checks";

export default function readme(community: Community) {
const response: StatusCheck = {
title: "Readme",
status: "unknown",
description: "-",
extra: "-",
};

if (communityMetrics.files?.readme) {
if (community.files?.readme) {
response.status = "success";
response.description = "You have a README file.";
response.extra = "No action required.";
}

if (!communityMetrics.files || !communityMetrics.files.readme) {
if (!community.files || !community.files.readme) {
response.status = "error";
response.description = "You do not have a readme.md file in your repo.";
response.extra = "This is the most important file in your project.";
Expand Down
8 changes: 7 additions & 1 deletion src/lib/github/getAllApi.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import Data from "@/models/data";
import getRepoApi from "./getRepoApi";
import getIssuesApi from "./getIssuesApi";
import getCommunityApi from "./getCommunityApi";

export default async function getAllApi(repoUrl: string): Promise<Data> {
const calls = await Promise.all([getRepoApi(repoUrl), getIssuesApi(repoUrl)]);
const calls = await Promise.all([
getRepoApi(repoUrl),
getIssuesApi(repoUrl),
getCommunityApi(repoUrl),
]);

const data: Data = {
repo: calls[0],
issues: calls[1],
community: calls[2],
};

return data;
Expand Down
17 changes: 17 additions & 0 deletions src/lib/github/getCommunityApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Issue } from "@/models/github/issue";
import extractOwnerRepo from "./extractOwnerRepo";
import { Community } from "@/models/github/community";

export default async function getCommunityApi(repoUrl: string) {
const { owner, repo } = extractOwnerRepo(repoUrl);
const res = await fetch(
`https://api.github.com/repos/${owner}/${repo}/community/profile`,
{
next: { revalidate: 3600 },
}
);

const data: Community = await res.json();

return data;
}
2 changes: 2 additions & 0 deletions src/models/data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Community } from "./github/community";
import { Issue } from "./github/issue";
import { Repo } from "./github/repo";

export default interface Data {
repo: Repo;
issues: Issue[];
community: Community;
}
31 changes: 31 additions & 0 deletions src/models/github/community.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// To parse this data:
//
// import { Convert, Community } from "./file";
//
// const community = Convert.toCommunity(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.

export interface Community {
health_percentage: number;
description: string;
documentation: null;
files: Files;
updated_at: null;
}

export interface Files {
code_of_conduct: null;
code_of_conduct_file: null;
contributing: null;
issue_template: null;
pull_request_template: null;
license: null;
readme: Readme;
}

export interface Readme {
url: string;
html_url: string;
}

0 comments on commit bd7d560

Please sign in to comment.