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

Commit 3db9e0f

Browse files
feat: gh projects v2 to GraphQL (#267)
* 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 <[email protected]>
1 parent a164cbf commit 3db9e0f

File tree

6 files changed

+39
-13
lines changed

6 files changed

+39
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
> [!NOTE]
22
> This project is sponsored by the Open Source project Flagsmith https://github.com/Flagsmith/flagsmith
3-
>
3+
>
44
> Feature flags have so many benefits, remote config, testing in production and so much more!
55
66
# HealthCheck

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@auth/prisma-adapter": "^2.4.2",
2626
"@headlessui/react": "^2.1.5",
2727
"@heroicons/react": "^2.1.5",
28+
"@octokit/graphql": "^8.1.1",
2829
"@octokit/rest": "^21.0.0",
2930
"@prisma/client": "^5.19.0",
3031
"@tailwindcss/aspect-ratio": "^0.4.2",

src/utils/checks/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function checks(data, ignoreChecks = []) {
4646
pullRequestTemplate(data.communityMetrics),
4747
codeOfConduct(data.communityMetrics),
4848
labels(data.labels),
49-
// projects(data.repo, data.projects),
49+
projects(data.repo, data.projects),
5050
];
5151

5252
const userChecks = filterIgnoredChecks(allChecks, ignoreChecks);

src/utils/checks/projects.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ export default function projects(repo, projectsData) {
1111
response.extra = "No action required.";
1212
}
1313

14-
if (repo.has_projects && projectsData.length > 0) {
14+
const filteredProjectsData = projectsData.filter(
15+
(project) => !project.closed,
16+
); // filter out closed projects
17+
18+
if (repo.has_projects && filteredProjectsData.length > 0) {
1519
response.status = "success";
1620
response.description =
1721
"You have project boards enabled and it is being used.";
1822
response.extra = "No action required.";
1923
}
2024

21-
if (repo.has_projects && projectsData.length === 0) {
25+
if (repo.has_projects && filteredProjectsData.length === 0) {
2226
response.status = "error";
2327
response.description =
2428
"You have project boards enabled but it is not being used.";

src/utils/github/getProjectsApi.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
1-
import { Octokit } from "@octokit/rest";
1+
import { graphql } from "@octokit/graphql";
22
import extractOwnerRepo from "./extractOwnerRepo";
33

44
export default async function getProjectsApi(url, token) {
55
// get owner and repo name from url
66
const { owner, repo } = extractOwnerRepo(url);
77

88
// get data from github api using user's API
9-
const octokit = new Octokit({
10-
auth: token,
9+
const octokit = graphql.defaults({
10+
headers: {
11+
authorization: `token ${token}`,
12+
},
1113
});
1214
let response;
1315
try {
14-
response = await octokit.rest.projects.listForRepo({
15-
owner,
16-
repo,
17-
state: "open",
18-
});
16+
response = await octokit(
17+
`
18+
query($owner: String!, $repo: String!) {
19+
repository(owner: $owner, name: $repo) {
20+
projectsV2(first: 10) {
21+
nodes {
22+
id
23+
title
24+
closed
25+
}
26+
}
27+
}
28+
}
29+
`,
30+
{
31+
owner,
32+
repo,
33+
},
34+
);
35+
response = {
36+
status: 200,
37+
data: response.repository.projectsV2.nodes,
38+
};
1939
} catch (e) {
2040
console.error(e);
2141
response = {

0 commit comments

Comments
 (0)