-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Cardano Problem Statements script (#1144)
* Add CPS fetching script * Adjust formatting * Add folder for CPS markdown files * Remove .gitkeep file * Add .gitkeep file * Fix comment typo --------- Co-authored-by: fill-the-fill <[email protected]>
- Loading branch information
1 parent
f016483
commit 410df6d
Showing
6 changed files
with
161 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
File to push empty folder to github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,66 @@ | ||
// CIP constants | ||
const cip_readme_url: string = "/README.md"; | ||
const cip_readme_regex: RegExp = /\.\/CIP.?\/|\.\/CIP-.*\)/gm | ||
const cip_readme_regex: RegExp = /\.\/CIP.?\/|\.\/CIP-.*\)/gm; | ||
const cip_source_repo: string = "cardano-foundation/CIPs"; | ||
const cip_static_resource_path: string = "/static/img/cip/"; | ||
const cip_docs_path: string = "./docs/governance/cardano-improvement-proposals"; | ||
const cip_regex: RegExp = /\]\(.*?.png\)|\]\(.*?.jpg\)|\]\(.*?.jpeg\)|\]\(.*?.json\)/gm; | ||
const cip_repo_base_url: string = "https://github.com/cardano-foundation/CIPs/tree/master/"; | ||
const cip_repo_raw_base_url: string = "https://raw.githubusercontent.com/cardano-foundation/CIPs/master/"; | ||
const cip_regex: RegExp = | ||
/\]\(.*?.png\)|\]\(.*?.jpg\)|\]\(.*?.jpeg\)|\]\(.*?.json\)/gm; | ||
const cip_repo_base_url: string = | ||
"https://github.com/cardano-foundation/CIPs/tree/master/"; | ||
const cip_repo_raw_base_url: string = | ||
"https://raw.githubusercontent.com/cardano-foundation/CIPs/master/"; | ||
|
||
// Rust Library constants | ||
// CPS constants | ||
const cps_repository_url: string = | ||
"https://api.github.com/repos/cardano-foundation/CIPs/contents"; | ||
const cps_target_folder: string = | ||
"./docs/governance/cardano-problem-statements"; | ||
|
||
// Rust Library constants | ||
const rl_static_resource_path: string = "/tree/master/doc/getting-started"; | ||
const rl_docs_path: string = "./docs/get-started/cardano-serialization-lib"; | ||
const rl_repo_base_url: string = "https://github.com/Emurgo/cardano-serialization-lib"; | ||
const rl_raw_base_index_url: string = "https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/master/doc/index.rst"; | ||
const rl_repo_raw_base_url: string = "https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/master/doc/getting-started/"; | ||
const rl_repo_base_url: string = | ||
"https://github.com/Emurgo/cardano-serialization-lib"; | ||
const rl_raw_base_index_url: string = | ||
"https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/master/doc/index.rst"; | ||
const rl_repo_raw_base_url: string = | ||
"https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/master/doc/getting-started/"; | ||
|
||
// Token Registry constants | ||
const tr_docs_path: string = "./docs/native-tokens/token-registry"; | ||
const tr_github_wiki: string = "https://github.com/cardano-foundation/cardano-token-registry/wiki"; | ||
const tr_url: string = "https://github.com/cardano-foundation/cardano-token-registry/blob/master/"; | ||
const tr_raw_wiki_url: string = "https://raw.githubusercontent.com/wiki/cardano-foundation/cardano-token-registry/"; | ||
const tr_overview_url: string = "https://raw.githubusercontent.com/cardano-foundation/cardano-token-registry/master/README.md"; | ||
const tr_github_wiki: string = | ||
"https://github.com/cardano-foundation/cardano-token-registry/wiki"; | ||
const tr_url: string = | ||
"https://github.com/cardano-foundation/cardano-token-registry/blob/master/"; | ||
const tr_raw_wiki_url: string = | ||
"https://raw.githubusercontent.com/wiki/cardano-foundation/cardano-token-registry/"; | ||
const tr_overview_url: string = | ||
"https://raw.githubusercontent.com/cardano-foundation/cardano-token-registry/master/README.md"; | ||
|
||
// General constants | ||
const custom_edit_url = "\ncustom_edit_url: null" | ||
|
||
export {cip_readme_url, cip_readme_regex, cip_source_repo, cip_static_resource_path, cip_docs_path, cip_regex, cip_repo_base_url, cip_repo_raw_base_url, rl_static_resource_path, rl_docs_path, rl_repo_base_url, rl_raw_base_index_url, rl_repo_raw_base_url, tr_docs_path, tr_github_wiki, tr_url, tr_raw_wiki_url, tr_overview_url, custom_edit_url}; | ||
export { | ||
cip_readme_url, | ||
cip_readme_regex, | ||
cip_source_repo, | ||
cip_static_resource_path, | ||
cip_docs_path, | ||
cip_regex, | ||
cip_repo_base_url, | ||
cip_repo_raw_base_url, | ||
cps_repository_url, | ||
cps_target_folder, | ||
rl_static_resource_path, | ||
rl_docs_path, | ||
rl_repo_base_url, | ||
rl_raw_base_index_url, | ||
rl_repo_raw_base_url, | ||
tr_docs_path, | ||
tr_github_wiki, | ||
tr_url, | ||
tr_raw_wiki_url, | ||
tr_overview_url, | ||
custom_edit_url, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import fetch from "node-fetch"; | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import { | ||
custom_edit_url, | ||
cps_repository_url, | ||
cps_target_folder, | ||
cip_source_repo, | ||
cip_repo_base_url, | ||
cip_readme_url, | ||
} from "./constants"; | ||
import { getDocTag } from "./reusable"; | ||
|
||
// Fetch markdown files from Github | ||
async function fetchReadmeContent(folderUrl: string): Promise<string | null> { | ||
try { | ||
const response = await fetch(folderUrl); | ||
const data = await response.json(); | ||
const readmeFile = data.find((file: any) => file.name === "README.md"); | ||
|
||
if (readmeFile) { | ||
const readmeResponse = await fetch(readmeFile.download_url); | ||
const readmeText = await readmeResponse.text(); | ||
return readmeText; | ||
} else { | ||
return null; | ||
} | ||
} catch (error) { | ||
console.error("Error fetching README:", error.message); | ||
return null; | ||
} | ||
} | ||
|
||
// Update/Create CPS locally | ||
async function updateOrCreateReadmeFile( | ||
folderName: string, | ||
content: string | ||
): Promise<void> { | ||
const title = getDocTag(content, "Title"); | ||
const cps = getDocTag(content, "CPS"); | ||
const sidebarLabel = `sidebar_label: "(${cps}) ${title}"`; | ||
const status = getDocTag(content, "Status"); | ||
const creationDate = getDocTag(content, "Created"); | ||
|
||
// Sanitize title | ||
const newContent = content.replace( | ||
/Title: .+/, | ||
`Title: "${title}"\n${sidebarLabel}${custom_edit_url}` | ||
); | ||
|
||
// Add Content Info at the bottom of the page | ||
const newContentWithInfo = newContent.concat( | ||
"\n" + | ||
"## CPS Information \nThis CPS was created on **" + | ||
creationDate + | ||
"** and has the status: [" + | ||
status + | ||
"](../cardano-improvement-proposals/CIP-0001#cip-workflow). \nThis page was generated automatically from: [" + | ||
cip_source_repo + | ||
"](" + | ||
cip_repo_base_url + | ||
folderName + | ||
cip_readme_url + | ||
")." | ||
); | ||
|
||
const filePath = path.join(cps_target_folder, `${folderName}.md`); | ||
try { | ||
await fs.promises.writeFile(filePath, newContentWithInfo); | ||
console.log(`Updated ${filePath}`); | ||
} catch (error) { | ||
console.error(`Error updating ${filePath}:`, error.message); | ||
} | ||
} | ||
|
||
async function main() { | ||
try { | ||
const response = await fetch(cps_repository_url); | ||
const data = await response.json(); | ||
const cpsFolders = data.filter( | ||
(item: any) => item.type === "dir" && item.name.includes("CPS") | ||
); | ||
|
||
for (const folder of cpsFolders) { | ||
const readmeContent = await fetchReadmeContent(folder.url); | ||
if (readmeContent) { | ||
const folderName = folder.name; | ||
await updateOrCreateReadmeFile(folderName, readmeContent); | ||
} | ||
} | ||
} catch (error) { | ||
console.error("Error fetching repository contents:", error.message); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters