Fix website updater for other users.

It broke with adafruit-blinka but works now.
This commit is contained in:
Scott Shawcroft 2019-09-04 16:50:13 -07:00
parent fca440fb66
commit ff3d04f4d1
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E

View File

@ -117,7 +117,7 @@ def get_current_info():
current_info[info["id"]] = info
return git_info, current_info
def create_pr(changes, updated, git_info):
def create_pr(changes, updated, git_info, user):
commit_sha, original_blob_sha = git_info
branch_name = "new_release_" + changes["new_release"]
@ -138,7 +138,7 @@ def create_pr(changes, updated, git_info):
languages = ""
if changes["new_languages"]:
languages = "New languages:\n* " + "\n* ".join(changes["new_languages"])
message = "Automated website update for release {} by AdaBot.\n\n{}\n\n{}\n".format(
message = "Automated website update for release {} by Blinka.\n\n{}\n\n{}\n".format(
changes["new_release"],
boards,
languages
@ -148,7 +148,7 @@ def create_pr(changes, updated, git_info):
"ref": "refs/heads/" + branch_name,
"sha": commit_sha
}
response = github.post("/repos/adafruit-adabot/circuitpython-org/git/refs", json=create_branch)
response = github.post("/repos/{}/circuitpython-org/git/refs".format(user), json=create_branch)
if not response.ok and response.json()["message"] != "Reference already exists":
print("unable to create branch")
print(response.text)
@ -161,14 +161,14 @@ def create_pr(changes, updated, git_info):
"branch": branch_name
}
response = github.put("/repos/adafruit-adabot/circuitpython-org/contents/_data/files.json", json=update_file)
response = github.put("/repos/{}/circuitpython-org/contents/_data/files.json".format(user), json=update_file)
if not response.ok:
print("unable to post new file")
print(response.text)
return
pr_info = {
"title": pr_title,
"head": "adafruit-adabot:" + branch_name,
"head": user + ":" + branch_name,
"base": "master",
"body": message,
"maintainer_can_modify": True
@ -198,9 +198,12 @@ def update_downloads(boards, release):
def print_active_user():
response = github.get("/user")
if response.ok:
print("Logged in as {}".format(response.json()["login"]))
user = response.json()["login"]
print("Logged in as {}".format(user))
return user
else:
print("Not logged in")
return None
def generate_download_info():
boards = {}
@ -214,7 +217,7 @@ def generate_download_info():
"new_languages": []
}
print_active_user()
user = print_active_user()
sha, this_version = get_version_info()
@ -271,8 +274,8 @@ def generate_download_info():
changes["new_languages"] = set(languages) - previous_languages
if changes["new_release"]:
create_pr(changes, current_info, git_info)
if changes["new_release"] and user:
create_pr(changes, current_info, git_info, user)
else:
print("No new release to update")