|
13 | 13 | from tqdm import tqdm |
14 | 14 | from collections import OrderedDict |
15 | 15 | import markdown2 |
| 16 | +import json |
16 | 17 |
|
17 | 18 | __version__ = "0.6.0" |
18 | 19 |
|
|
39 | 40 | "statuspage.js", |
40 | 41 | ] |
41 | 42 |
|
| 43 | +DEFAULT_CONFIG = { |
| 44 | + "footer": "Status page hosted by GitHub, generated with <a href='https://github.com/jayfk/statuspage'>jayfk/statuspage</a>", |
| 45 | + "logo": "https://raw.githubusercontent.com/jayfk/statuspage/master/template/logo.png", |
| 46 | + "title": "Status", |
| 47 | + "favicon": "https://raw.githubusercontent.com/jayfk/statuspage/master/template/favicon.png" |
| 48 | +} |
| 49 | + |
42 | 50 |
|
43 | 51 | @click.group() |
44 | 52 | @click.version_option(__version__, '-v', '--version') |
@@ -85,7 +93,7 @@ def run_upgrade(name, token, org): |
85 | 93 | click.echo("Upgrading...") |
86 | 94 |
|
87 | 95 | repo = get_repo(token=token, name=name, org=org) |
88 | | - files = [file.path for file in repo.get_dir_contents("/", ref="gh-pages")] |
| 96 | + files = get_files(repo=repo) |
89 | 97 | head_sha = repo.get_git_ref("heads/gh-pages").object.sha |
90 | 98 |
|
91 | 99 | # add all the template files to the gh-pages branch |
@@ -132,9 +140,10 @@ def run_update(name, token, org): |
132 | 140 | panels = get_panels(systems) |
133 | 141 |
|
134 | 142 | # render the template |
| 143 | + config = get_config(repo) |
135 | 144 | template = Template(template_file.decoded_content.decode("utf-8")) |
136 | 145 | content = template.render({ |
137 | | - "systems": systems, "incidents": incidents, "panels": panels |
| 146 | + "systems": systems, "incidents": incidents, "panels": panels, "config": config |
138 | 147 | }) |
139 | 148 |
|
140 | 149 | # create/update the index.html with the template |
@@ -283,6 +292,31 @@ def iter_systems(labels): |
283 | 292 | yield label.name |
284 | 293 |
|
285 | 294 |
|
| 295 | +def get_files(repo): |
| 296 | + """ |
| 297 | + Get a list of all files. |
| 298 | + """ |
| 299 | + return [file.path for file in repo.get_dir_contents("/", ref="gh-pages")] |
| 300 | + |
| 301 | + |
| 302 | +def get_config(repo): |
| 303 | + """ |
| 304 | + Get the config for the repo, merged with the default config. Returns the default config if |
| 305 | + no config file is found. |
| 306 | + """ |
| 307 | + files = get_files(repo) |
| 308 | + config = DEFAULT_CONFIG |
| 309 | + if "config.json" in files: |
| 310 | + # get the config file, parse JSON and merge it with the default config |
| 311 | + config_file = repo.get_file_contents('/config.json', ref="gh-pages") |
| 312 | + try: |
| 313 | + repo_config = json.loads(config_file.decoded_content.decode("utf-8")) |
| 314 | + config.update(repo_config) |
| 315 | + except ValueError: |
| 316 | + click.secho("WARNING: Unable to parse config file. Using defaults.", fg="yellow") |
| 317 | + return config |
| 318 | + |
| 319 | + |
286 | 320 | def get_severity(labels): |
287 | 321 | label_map = dict(COLORED_LABELS) |
288 | 322 | for label in labels: |
|
0 commit comments