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

Commit

Permalink
feat: gh projects v2 to GraphQL (#267)
Browse files Browse the repository at this point in the history
* feat: Moved GitHub Projects API usage from REST to GraphQL

* Update src/utils/github/getProjectsApi.js

* Update src/utils/github/getProjectsApi.js

---------

Co-authored-by: Eddie Jaoude <eddie@jaoudestudios.com>
  • Loading branch information
SaptarshiSarkar12 and eddiejaoude authored Oct 1, 2024
1 parent a164cbf commit 3db9e0f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/checks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/utils/checks/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down
36 changes: 28 additions & 8 deletions src/utils/github/getProjectsApi.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
import { Octokit } from "@octokit/rest";
import { graphql } from "@octokit/graphql";
import extractOwnerRepo from "./extractOwnerRepo";

export default async function getProjectsApi(url, token) {
// get owner and repo name from url
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 = {
Expand Down

0 comments on commit 3db9e0f

Please sign in to comment.