Skip to content

Commit

Permalink
fix: several updates due to changes in PyGithub and GitHub (#296)
Browse files Browse the repository at this point in the history
* Remove slash from path

As per PyGithub#1210 slash at beginning of path cannot be used.

Fix: #293

* Replace master with main

Due to GitHub branch naming convention, starting from 1st October, all new repositories are having main instead of master branch.

* Use get_contents instead of get_file_contents

Due to PyGithub#1222 and PyGithub#1223

* update_file cannot use slash

Fix #293
  • Loading branch information
pasuder committed Feb 23, 2022
1 parent 8de4a50 commit e742e89
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions statuspage/statuspage.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@

DEFAULT_CONFIG = {
"footer": "Status page hosted by GitHub, generated with <a href='https://github.com/jayfk/statuspage'>jayfk/statuspage</a>",
"logo": "https://raw.githubusercontent.com/jayfk/statuspage/master/template/logo.png",
"logo": "https://raw.githubusercontent.com/jayfk/statuspage/main/template/logo.png",
"title": "Status",
"favicon": "https://raw.githubusercontent.com/jayfk/statuspage/master/template/favicon.png"
"favicon": "https://raw.githubusercontent.com/jayfk/statuspage/main/template/favicon.png"
}


Expand Down Expand Up @@ -143,7 +143,7 @@ def run_upgrade(name, token, org):
with open(os.path.join(ROOT, "template", template), "r") as f:
content = f.read()
if template in files:
repo_template = repo.get_file_contents(
repo_template = repo.get_contents(
path="/" + template,
ref=head_sha,
)
Expand All @@ -152,15 +152,15 @@ def run_upgrade(name, token, org):
base64.b64decode(repo_template.content)
):
repo.update_file(
path="/" + template,
path=template,
sha=repo_template.sha,
message="upgrade",
content=content,
branch="gh-pages"
)
else:
repo.create_file(
path="/" + template,
path=template,
message="upgrade",
content=content,
branch="gh-pages"
Expand All @@ -176,7 +176,7 @@ def run_update(name, token, org):
sha = repo.get_git_ref("heads/gh-pages").object.sha

# get the template from the repo
template_file = repo.get_file_contents(
template_file = repo.get_contents(
path="/template.html",
ref=sha
)
Expand All @@ -195,7 +195,7 @@ def run_update(name, token, org):
# 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(
index = repo.get_contents(
path="/index.html",
ref=sha,
)
Expand All @@ -205,7 +205,7 @@ def run_update(name, token, org):
return False

repo.update_file(
path="/index.html",
path="index.html",
sha=index.sha,
message="update index",
content=content,
Expand All @@ -214,7 +214,7 @@ def run_update(name, token, org):
except UnknownObjectException:
# index.html does not exist, create it
repo.create_file(
path="/index.html",
path="index.html",
message="initial",
content=content,
branch="gh-pages",
Expand Down Expand Up @@ -249,7 +249,7 @@ def run_create(name, token, systems, org, private):
for label in tqdm(systems.split(","), desc="Creating system labels"):
repo.create_label(name=label.strip(), color=SYSTEM_LABEL_COLOR)

# add an empty file to master, otherwise we won't be able to create the gh-pages
# add an empty file to main, otherwise we won't be able to create the gh-pages
# branch
repo.create_file(
path="README.md",
Expand All @@ -258,7 +258,7 @@ def run_create(name, token, systems, org, private):
)

# create the gh-pages branch
ref = repo.get_git_ref("heads/master")
ref = repo.get_git_ref("heads/main")
repo.create_git_ref(ref="refs/heads/gh-pages", sha=ref.object.sha)

# add all the template files to the gh-pages branch
Expand Down Expand Up @@ -317,7 +317,7 @@ def get_config(repo):
config = DEFAULT_CONFIG
if "config.json" in files:
# get the config file, parse JSON and merge it with the default config
config_file = repo.get_file_contents('config.json', ref="gh-pages")
config_file = repo.get_contents('config.json', ref="gh-pages")
try:
repo_config = json.loads(config_file.decoded_content.decode("utf-8"))
config.update(repo_config)
Expand Down

0 comments on commit e742e89

Please sign in to comment.