Skip to content

Commit 527d69f

Browse files
committed
added upgrade command
1 parent 2c51774 commit 527d69f

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## 0.7.0 [2016-07-31]
66
- Added markdown support.
7+
- Added upgrade command.
78

89
## 0.6.0 [2016-07-26]
910
- Added an option to automate the update process.

statuspage/statuspage.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ def create(token, name, systems, org, private):
6262
def update(name, token, org):
6363
run_update(name=name, token=token, org=org)
6464

65+
66+
@cli.command()
67+
@click.option('--name', prompt='Name', help='')
68+
@click.option('--org', help='GitHub Organization', default=False)
69+
@click.option('--token', prompt='GitHub API Token', help='')
70+
def upgrade(name, token, org):
71+
run_upgrade(name=name, token=token, org=org)
72+
73+
6574
@cli.command()
6675
@click.option('--name', prompt='Name', help='')
6776
@click.option('--org', help='GitHub Organization', default=False)
@@ -71,6 +80,38 @@ def automate(name, token, org, key):
7180
run_automate(name=name, token=token, org=org, key=key)
7281

7382

83+
def run_upgrade(name, token, org):
84+
click.echo("Upgrading...")
85+
86+
repo = get_repo(token=token, name=name, org=org)
87+
files = [file.path for file in repo.get_dir_contents("/", ref="gh-pages")]
88+
head_sha = repo.get_git_ref("heads/gh-pages").object.sha
89+
90+
# add all the template files to the gh-pages branch
91+
for template in tqdm(TEMPLATES, desc="Updating template files"):
92+
with open(os.path.join(ROOT, "template", template), "r") as f:
93+
content = f.read()
94+
if template in files:
95+
template_sha = repo.get_file_contents(
96+
path="/" + template,
97+
ref=head_sha,
98+
).sha
99+
repo.update_file(
100+
path="/" + template,
101+
sha=template_sha,
102+
message="upgrade",
103+
content=content,
104+
branch="gh-pages"
105+
)
106+
else:
107+
repo.create_file(
108+
path="/" + template,
109+
message="upgrade",
110+
content=content,
111+
branch="gh-pages"
112+
)
113+
114+
74115
def run_update(name, token, org):
75116
click.echo("Generating..")
76117
repo = get_repo(token=token, name=name, org=org)

0 commit comments

Comments
 (0)