Skip to content

Commit

Permalink
feat: get project data from GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Yolijn committed May 20, 2024
1 parent afaf318 commit 1a67ddb
Show file tree
Hide file tree
Showing 6 changed files with 530 additions and 20 deletions.
28 changes: 28 additions & 0 deletions packages/component-progress/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"version": "1.0.0",
"author": "Community for NL Design System",
"description": "Script to get the component progress for the documentation of NL Design System",
"license": "EUPL-1.2",
"name": "@nl-design-system/component-progress",
"keywords": [
"nl-design-system"
],
"private": false,
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git+ssh",
"url": "[email protected]:nl-design-system/documentatie.git"
},
"scripts": {
"build": "node src/index.mjs",
"clean": "rm -rf dist/",
"prebuild": "npm run clean"
},
"dependencies": {
"@octokit/graphql": "8.1.1",
"lodash.isempty": "4.4.0",
"octokit": "4.0.2"
}
}
66 changes: 66 additions & 0 deletions packages/component-progress/src/getComponents.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import isEmpty from 'lodash.isempty';
import { PROJECT_NUMBERS } from './getProjects.mjs';
import { graphqlWithAuth } from './graphqlWithAuth.mjs';

const filterEstafetteProjects = (issues = []) => {
return issues.map(({ title, projectItems, ...issue }) => ({
title,
projects: projectItems.nodes.filter(({ project }) => PROJECT_NUMBERS.includes(project.number)).map(cleanupFields),
...issue,
}));
};

const cleanupFields = ({ project, fieldValues }) => ({
[project.number]: {
title: project.title,
checks: fieldValues.nodes
.filter((node) => !isEmpty(node))
.map(({ field: { name, id }, value }) => ({ name, id, value })),
},
});

export const getComponentProgess = async () => {
const {
repository: { issues },
} = await graphqlWithAuth({
query: `{
repository(name: "backlog", owner: "nl-design-system") {
issues(labels: ["component"], first: 100) {
totalCount
nodes {
title
url: bodyUrl
projectItems(includeArchived: false, first: 10) {
nodes {
project {
title
number
}
fieldValues(first: 50) {
nodes {
... on ProjectV2ItemFieldValueCommon {
field {
... on ProjectV2FieldCommon {
name
id
}
}
}
... on ProjectV2ItemFieldSingleSelectValue {
value: name
}
... on ProjectV2ItemFieldTextValue {
value: text
}
}
}
}
}
}
}
}
}`,
});

return filterEstafetteProjects(issues.nodes);
};
51 changes: 51 additions & 0 deletions packages/component-progress/src/getProjects.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { graphqlWithAuth } from './graphqlWithAuth.mjs';

const HELP_WANTED_PROJECT = 27;
const COMMUNITY_PROJECT = 29;
const CANDIDATE_PROJECT = 32;
const HALL_OF_FAME_PROJECT = 30;

export const PROJECT_NUMBERS = [HELP_WANTED_PROJECT, COMMUNITY_PROJECT, CANDIDATE_PROJECT, HALL_OF_FAME_PROJECT];

export const getProjectDetails = async () => {
const { organization } = await graphqlWithAuth({
query: `{
organization(login: "nl-design-system") {
HELP_WANTED: projectV2(number: ${HELP_WANTED_PROJECT}) {
...ProjectFragment
}
COMMUNITY: projectV2(number: ${COMMUNITY_PROJECT}) {
...ProjectFragment
}
CANDIDATE: projectV2(number: ${CANDIDATE_PROJECT}) {
...ProjectFragment
}
HALL_OF_FAME: projectV2(number: ${HALL_OF_FAME_PROJECT}) {
...ProjectFragment
}
}
}
fragment ProjectFragment on ProjectV2 {
number
title
shortDescription
url
updatedAt
view(number: 1) {
fields(first: 50) {
totalCount
nodes {
... on ProjectV2FieldCommon {
dataType
name
id
}
}
}
}
}`,
});

return organization;
};
8 changes: 8 additions & 0 deletions packages/component-progress/src/graphqlWithAuth.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* global process */
import { graphql } from '@octokit/graphql';

export const graphqlWithAuth = graphql.defaults({
headers: {
authorization: `token ${process.env.GH_ISSUES_TOKEN}`,
},
});
27 changes: 27 additions & 0 deletions packages/component-progress/src/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as fs from 'fs/promises';
import { getComponentProgess } from './getComponents.mjs';
import { getProjectDetails } from './getProjects.mjs';

const init = async () => {
try {
await fs.mkdir('./dist', { recursive: true });
} catch (error) {
console.error('Could not create dist directory', error);
}

try {
const componentProgress = await getComponentProgess();
await fs.writeFile('./dist/component-progress.json', JSON.stringify(componentProgress));
} catch (error) {
console.error('Could not create component-progress.json', error);
}

try {
const projectDetails = await getProjectDetails();
await fs.writeFile('./dist/project-details.json', JSON.stringify(projectDetails));
} catch (error) {
console.error('Could not create project-details.json', error);
}
};

init();
Loading

0 comments on commit 1a67ddb

Please sign in to comment.