Skip to content

Commit 7e3dd29

Browse files
authored
Merge pull request #5 from OpenPathfinder/feat/add-policies
2 parents e52ec46 + 6f8fd99 commit 7e3dd29

File tree

6 files changed

+106
-2
lines changed

6 files changed

+106
-2
lines changed
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Sync and update Compliance Checks
1+
name: Sync checks and policies
22

33
on:
44
# Manually trigger the workflow
@@ -67,10 +67,22 @@ jobs:
6767
git add -A
6868
git diff --cached --quiet || git commit -m "chore: sync with visionBoard Checks"
6969
70+
- name: Clone fortSphere and import policies
71+
run: |
72+
git clone https://github.com/OpenPathfinder/fortSphere.git temp-fortSphere
73+
cd temp-fortSphere
74+
npm install
75+
mkdir -p output
76+
npm run export-policies
77+
cp output/policies.json ../data/policies.json
78+
cd ..
79+
rm -rf temp-fortSphere
80+
7081
- name: Install Dependencies and update dynamic content
7182
run: |
7283
npm install
7384
npm run populate-checks
85+
npm run populate-policies
7486
7587
- name: Debug Git Changes
7688
run: |

data/policies.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"name": "restrictRepoCreationGitHub",
4+
"title": "Restrict Repository Creation",
5+
"description": "This policy is designed to prevent members of a GitHub organization from creating new repositories. This includes public and private repositories.",
6+
"technicalDetails": "This policy will set the following values for the organization(`members_allowed_repository_creation_type=none`, `members_can_create_public_repositories=false`, `members_can_create_private_repositories=false`) at the organization level."
7+
}
8+
]

docs/policies/_category_.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Policies",
3+
"position": 4
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
sidebar_position: 1
3+
id: restrictRepoCreationGitHub
4+
title: Restrict Repository Creation
5+
slug: /policies/restrictRepoCreationGitHub
6+
---
7+
8+
<!-- DESCRIPTION:START -->
9+
## Description
10+
This policy is designed to prevent members of a GitHub organization from creating new repositories. This includes public and private repositories.
11+
<!-- DESCRIPTION:END -->
12+
13+
<!-- TECHNICAL-DETAILS:START -->
14+
## Technical Details
15+
This policy will set the following values for the organization(`members_allowed_repository_creation_type=none`, `members_can_create_public_repositories=false`, `members_can_create_private_repositories=false`) at the organization level.
16+
<!-- TECHNICAL-DETAILS:END -->

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"serve": "docusaurus serve",
1313
"write-translations": "docusaurus write-translations",
1414
"write-heading-ids": "docusaurus write-heading-ids",
15-
"populate-checks": "node scripts/populate-checks.js"
15+
"populate-checks": "node scripts/populate-checks.js",
16+
"populate-policies": "node scripts/populate-policies.js"
1617
},
1718
"dependencies": {
1819
"@docusaurus/core": "3.6.3",

scripts/populate-policies.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const { writeFileSync, existsSync, readFileSync } = require('fs')
2+
const { updateOrCreateSegment } = require('@ulisesgascon/text-tags-manager')
3+
const path = require('path')
4+
5+
const policies = require('../data/policies.json')
6+
const descriptionStartTag = '<!-- DESCRIPTION:START -->'
7+
const descriptionEndTag = '<!-- DESCRIPTION:END -->'
8+
const technicalDetailsStartTag = '<!-- TECHNICAL-DETAILS:START -->'
9+
const technicalDetailsEndTag = '<!-- TECHNICAL-DETAILS:END -->'
10+
11+
// @TODO: Move this function to a shared file
12+
const replaceMetadata = (fileContent, metadata) => {
13+
return fileContent.replace(/---[^]*?---/, metadata)
14+
}
15+
16+
// Prepare the markdown files
17+
policies.forEach((policy, index) => {
18+
const metadata = `---
19+
sidebar_position: ${index + 1}
20+
id: ${policy.name}
21+
title: ${policy.title}
22+
slug: /policies/${policy.name}
23+
---`.trim()
24+
const descriptionContent = `## Description
25+
${policy.description}`.trim()
26+
const technicalDetailsContent = `## Technical Details
27+
${policy.technicalDetails}`.trim()
28+
29+
let fileContent = `${metadata}
30+
31+
${descriptionStartTag}
32+
${descriptionContent}
33+
${descriptionEndTag}
34+
35+
${technicalDetailsStartTag}
36+
${technicalDetailsContent}
37+
${technicalDetailsEndTag}
38+
`
39+
const updateContent = (currentContent) => {
40+
fileContent = currentContent
41+
replaceMetadata(fileContent, metadata)
42+
fileContent = updateOrCreateSegment({
43+
original: fileContent,
44+
replacementSegment: descriptionContent,
45+
startTag: descriptionStartTag,
46+
endTag: descriptionEndTag
47+
})
48+
fileContent = updateOrCreateSegment({
49+
original: fileContent,
50+
replacementSegment: technicalDetailsContent,
51+
startTag: technicalDetailsStartTag,
52+
endTag: technicalDetailsEndTag
53+
})
54+
}
55+
56+
const destination = path.join(process.cwd(), `docs/policies/${policy.name}.mdx`)
57+
const fileExists = existsSync(destination)
58+
if (fileExists) {
59+
const currentFileContent = readFileSync(destination, 'utf8')
60+
updateContent(currentFileContent)
61+
}
62+
writeFileSync(destination, fileContent)
63+
})

0 commit comments

Comments
 (0)