def run_update(name, token, org):
click.echo("Generating..")
repo = get_repo(token=token, name=name, org=org)
issues = get_issues(repo)
# get the SHA of the current HEAD
sha = repo.get_git_ref("heads/gh-pages").object.sha
# get the template from the repo
template_file = repo.get_file_contents(
path="/template.html",
ref=sha
)
systems = get_systems(repo, issues)
incidents = get_incidents(repo, issues)
panels = get_panels(systems)
# render the template
config = get_config(repo)
template = Template(template_file.decoded_content.decode("utf-8"))
content = template.render({
"systems": systems, "incidents": incidents, "panels": panels, "config": config
})
# create/update the index.html with the template
try:
# get the index.html file, we need the sha to update it
index = repo.get_file_contents(
path="/index.html",
ref=sha,
)
if is_same_content(content, base64.b64decode(index.content)):
click.echo("Local status matches remote status, no need to commit.")
return False
repo.update_file(
path="/index.html",
sha=index.sha,
message="update index",
content=content,
branch="gh-pages"
)
except UnknownObjectException:
# index.html does not exist, create it
repo.create_file(
path="/index.html",
message="initial",
content=content,
branch="gh-pages",
)
评论列表
文章目录