Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add project data #399

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/continuous-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
continuous-integration:
Expand Down Expand Up @@ -68,6 +69,8 @@ jobs:
pnpm ls --recursive

- name: Run the build script in package.json scripts
env:
GH_ISSUES_TOKEN: ${{ secrets.GH_ISSUES_TOKEN }}
run: |
pnpm run --if-present build

Expand Down
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": "git@github.com:nl-design-system/documentatie.git"
},
"scripts": {
"build": "node src/index.mjs",
"clean": "rm -rf dist/",
"prebuild": "npm run clean"
},
"devDependencies": {
"@octokit/graphql": "8.1.1",
"lodash.isempty": "4.4.0",
"octokit": "4.0.2"
Robbert marked this conversation as resolved.
Show resolved Hide resolved
}
}
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);
};
55 changes: 55 additions & 0 deletions packages/component-progress/src/getProjects.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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: `query projectDetails($helpWanted: Int!, $community: Int!, $candidate: Int!, $hallOfFame: Int!) {
organization(login: "nl-design-system") {
HELP_WANTED: projectV2(number:$helpWanted) {
...ProjectFragment
}
COMMUNITY: projectV2(number:$community) {
...ProjectFragment
}
CANDIDATE: projectV2(number:$candidate) {
...ProjectFragment
}
HALL_OF_FAME: projectV2(number:$hallOfFame) {
...ProjectFragment
}
}
}

fragment ProjectFragment on ProjectV2 {
number
title
shortDescription
url
updatedAt
view(number: 1) {
fields(first: 50) {
totalCount
checks: nodes {
... on ProjectV2FieldCommon {
dataType
name
id
}
}
}
}
}`,
helpWanted: HELP_WANTED_PROJECT,
community: COMMUNITY_PROJECT,
candidate: CANDIDATE_PROJECT,
hallOfFame: HALL_OF_FAME_PROJECT,
});

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