diff --git a/README.md b/README.md index 55e7b0b..427e5ec 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ > [!NOTE] > This project is sponsored by the Open Source project Flagsmith https://github.com/Flagsmith/flagsmith -> +> > Feature flags have so many benefits, remote config, testing in production and so much more! # HealthCheck diff --git a/package-lock.json b/package-lock.json index f86983a..244cdd4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,12 +6,13 @@ "packages": { "": { "name": "healthcheck", - "version": "0.31.11", + "version": "0.36.0", "hasInstallScript": true, "dependencies": { "@auth/prisma-adapter": "^2.4.2", "@headlessui/react": "^2.1.5", "@heroicons/react": "^2.1.5", + "@octokit/graphql": "^8.1.1", "@octokit/rest": "^21.0.0", "@prisma/client": "^5.19.0", "@tailwindcss/aspect-ratio": "^0.4.2", diff --git a/package.json b/package.json index 9c35cbb..6b298da 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@auth/prisma-adapter": "^2.4.2", "@headlessui/react": "^2.1.5", "@heroicons/react": "^2.1.5", + "@octokit/graphql": "^8.1.1", "@octokit/rest": "^21.0.0", "@prisma/client": "^5.19.0", "@tailwindcss/aspect-ratio": "^0.4.2", diff --git a/src/utils/checks/index.js b/src/utils/checks/index.js index db306c6..cce04cd 100644 --- a/src/utils/checks/index.js +++ b/src/utils/checks/index.js @@ -46,7 +46,7 @@ export default function checks(data, ignoreChecks = []) { pullRequestTemplate(data.communityMetrics), codeOfConduct(data.communityMetrics), labels(data.labels), - // projects(data.repo, data.projects), + projects(data.repo, data.projects), ]; const userChecks = filterIgnoredChecks(allChecks, ignoreChecks); diff --git a/src/utils/checks/projects.js b/src/utils/checks/projects.js index 5e9fb40..0331d46 100644 --- a/src/utils/checks/projects.js +++ b/src/utils/checks/projects.js @@ -11,14 +11,18 @@ export default function projects(repo, projectsData) { response.extra = "No action required."; } - if (repo.has_projects && projectsData.length > 0) { + const filteredProjectsData = projectsData.filter( + (project) => !project.closed, + ); // filter out closed projects + + if (repo.has_projects && filteredProjectsData.length > 0) { response.status = "success"; response.description = "You have project boards enabled and it is being used."; response.extra = "No action required."; } - if (repo.has_projects && projectsData.length === 0) { + if (repo.has_projects && filteredProjectsData.length === 0) { response.status = "error"; response.description = "You have project boards enabled but it is not being used."; diff --git a/src/utils/github/getProjectsApi.js b/src/utils/github/getProjectsApi.js index e6b9dbf..55a7827 100644 --- a/src/utils/github/getProjectsApi.js +++ b/src/utils/github/getProjectsApi.js @@ -1,4 +1,4 @@ -import { Octokit } from "@octokit/rest"; +import { graphql } from "@octokit/graphql"; import extractOwnerRepo from "./extractOwnerRepo"; export default async function getProjectsApi(url, token) { @@ -6,16 +6,36 @@ export default async function getProjectsApi(url, token) { const { owner, repo } = extractOwnerRepo(url); // get data from github api using user's API - const octokit = new Octokit({ - auth: token, + const octokit = graphql.defaults({ + headers: { + authorization: `token ${token}`, + }, }); let response; try { - response = await octokit.rest.projects.listForRepo({ - owner, - repo, - state: "open", - }); + response = await octokit( + ` + query($owner: String!, $repo: String!) { + repository(owner: $owner, name: $repo) { + projectsV2(first: 10) { + nodes { + id + title + closed + } + } + } + } + `, + { + owner, + repo, + }, + ); + response = { + status: 200, + data: response.repository.projectsV2.nodes, + }; } catch (e) { console.error(e); response = {