Last active
February 22, 2018 16:37
-
-
Save gijsk/c22ca81bf0c10710f07c8284b77274f9 to your computer and use it in GitHub Desktop.
bulk plugins update + request review
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from kinto_http import Client | |
FIREFOX_GUID = "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}" | |
SERVER = os.getenv("SERVER") or "https://settings-writer.prod.mozaws.net/v1" | |
USERNAME = os.getenv("USERNAME") | |
PASSWORD = os.getenv("PASSWORD") | |
client = Client(server_url=SERVER, auth=(USERNAME, PASSWORD), | |
bucket='staging', collection='plugins') | |
records = client.get_records() | |
unchanged_records = ["p330", "p332", "p1054", "p1055", "49b843cc-a8fc-4ede-be0c-a0da56d0214f", "832dc9ff-3314-4df2-abcf-7bd65a645371"] | |
# 1. Change records in the "staging" bucket. | |
with client.batch() as batch: | |
for record in records: | |
# Ignore records in the list at the top of this file: | |
blockID = record.get("blockID") | |
if not blockID: | |
blockID = record.get("id") | |
if not blockID or blockID in unchanged_records: | |
continue | |
# As of 21 feb 2018, no record with several version ranges. | |
versionRange = record.get("versionRange") | |
if versionRange is None or len(versionRange) == 0: | |
versionRange = [{}] | |
targetApplications = versionRange[0].get("targetApplication") | |
if targetApplications is None or len(targetApplications) == 0: | |
targetApplications = [{}] | |
for ta in targetApplications: | |
if "guid" not in ta: | |
ta["guid"] = FIREFOX_GUID | |
ta["minVersion"] = "0" | |
ta["maxVersion"] = "57.0.*" | |
elif ta.get("guid") == FIREFOX_GUID: | |
ta.setdefault("minVersion", "0") | |
ta["maxVersion"] = "57.0.*" | |
versionRange[0]["targetApplication"] = targetApplications | |
record["versionRange"] = versionRange | |
batch.update_record(data=record) | |
# 2. Request a review. | |
client.patch_collection(data={"status": "to-review"}) | |
# 3. Approve changes via the UI. | |
# Or with a call to client.patch_collection(data={"status": "to-sign"}) | |
# as a different user (member of the reviewers group) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment