Skip to content

Instantly share code, notes, and snippets.

@gijsk
Forked from leplatrem/bulk.py
Last active January 16, 2019 15:27
Show Gist options
  • Save gijsk/888354f4ffa9ad3272f64fb6921c3a16 to your computer and use it in GitHub Desktop.
Save gijsk/888354f4ffa9ad3272f64fb6921c3a16 to your computer and use it in GitHub Desktop.
bulk plugins update + request review
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 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["maxVersion"] = "57.0.*"
elif ta.get("guid") == FIREFOX_GUID:
ta.setdefault("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