-
Notifications
You must be signed in to change notification settings - Fork 29
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
Move markdown out of JSON files #30
Comments
Yes! It's nice and easy to edit markdown files in github |
Has this issue progressed? I can help if you need. |
Sorry I was unable to do any work on this. PRs are welcome 👍 |
Ok, I started working on it, I have extracted all the descriptions and fixes to separate files using the script below (as some fixes are used in multiple vulns, the fix files can't be named after the vuln title, so for now I've decided to name them only after their id). I'll write the tests for this, and then I'll submit a PR. #!/usr/bin/env python
# coding: utf-8
import json
import os
from collections import OrderedDict
DB_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'db')
DESC_DIR = os.path.join(DB_DIR, 'description')
FIX_DIR = os.path.join(DB_DIR, 'fix')
for p in (DESC_DIR, FIX_DIR):
if not os.path.exists(p):
os.mkdir(p)
fixes = []
for f in os.listdir(DB_DIR):
fpath = os.path.join(DB_DIR, f)
if not os.path.isfile(fpath):
continue
# read JSON file
with open(fpath) as ifile:
data = json.load(ifile, object_pairs_hook=OrderedDict)
title = f.replace('.json', '')
vuln_id = data['id']
# write description to markdown file
description = '\n'.join(data['description'])
descpath = os.path.join(DESC_DIR, title+'.md')
with open(descpath, 'w') as ofile:
print('writing description file: {}'.format(descpath))
ofile.write(description)
descref = '#/files/description/{}'.format(vuln_id)
# store fix for later processing
fix = '\n'.join(data['fix']['guidance'])
if fix not in fixes:
fixes.append(fix)
fix_id = fixes.index(fix)
fixref = '#/files/fix/{}'.format(fix_id)
# rewrite JSON file
print('rewriting JSON file: {}'.format(fpath))
data['description'] = {'$ref': descref}
data['fix']['guidance'] = {'$ref': fixref}
with open(fpath, 'w') as ofile:
json.dump(data, ofile, indent=2)
for fix_id, fix in enumerate(fixes):
fixpath = os.path.join(FIX_DIR, str(fix_id)+'.md')
with open(fixpath, 'w') as ofile:
print('writing fix file: {}'.format(fixpath))
ofile.write(fix) |
Done! Thanks @mattoufoutu |
User story
As a user I complain and say that writing markdown text inside JSON is hard:
Tasks
"fix": { "$ref": "#/files/fix/123" }
and"description": { "$ref": "#/files/description/123" }
Reviewers
The text was updated successfully, but these errors were encountered: