Skip to content

Commit

Permalink
feat: branches check
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiejaoude committed Oct 2, 2024
1 parent 5e4ec2f commit 6930159
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/checks/branches.js → src/checks/branches.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
export default function branches(branches) {
import { Branch } from "@/models/github/branch";
import { StatusCheck } from "@/types/checks";

export default function branches(branches: Branch[]) {
const min = 5;
const max = 10;

let response = {
id: "branches",
href: "/repo/status",
const response: StatusCheck = {
title: "Branches",
status: "unknown",
description: "-",
extra: "-",
};

if (!branches) {
return {
...response,
status: "-",
description: "No data available",
extra: "-",
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/checks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function checks(data: Data) {
issues(data.repo),
defaultBranch(data.repo),
goodFirstIssue(data.issues),
// branches(data.branches),
branches(data.branches),
// release(data.release),
readme(data.community),
license(data.community),
Expand Down
3 changes: 3 additions & 0 deletions src/lib/github/getAllApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ import Data from "@/models/data";
import getRepoApi from "./getRepoApi";
import getIssuesApi from "./getIssuesApi";
import getCommunityApi from "./getCommunityApi";
import getBranchesApi from "./getBranchesApi";

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

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

return data;
Expand Down
16 changes: 16 additions & 0 deletions src/lib/github/getBranchesApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import extractOwnerRepo from "./extractOwnerRepo";
import { Branch } from "@/models/github/branch";

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

const data: Branch[] = 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,3 +1,4 @@
import { Branch } from "./github/branch";
import { Community } from "./github/community";
import { Issue } from "./github/issue";
import { Repo } from "./github/repo";
Expand All @@ -6,4 +7,5 @@ export default interface Data {
repo: Repo;
issues: Issue[];
community: Community;
branches: Branch[];
}
19 changes: 19 additions & 0 deletions src/models/github/branch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// To parse this data:
//
// import { Convert } from "./file";
//
// const branch = Convert.toBranch(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.

export interface Branch {
name: string;
commit: Commit;
protected: boolean;
}

export interface Commit {
sha: string;
url: string;
}

0 comments on commit 6930159

Please sign in to comment.