Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Batch close upsource reviews
import requests
import argparse
REVIEWS_LIST_PATH = "{host}/~rpc/getReviews"
CLOSE_REVIEW_PATH = "{host}/~rpc/closeReview"
REVIEWS_REQUEST = "(state: open) and (accepted-by: 1 or (not (updated: {this month})))"
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--host', required=True)
parser.add_argument('--project', required=True)
parser.add_argument('--login', required=True)
parser.add_argument('--password', required=True)
return parser.parse_args()
def fetch_reviews_batch(host, project, auth):
query = {
"projectId": project,
"query": REVIEWS_REQUEST,
"limit": 20
}
reviews_list_response = requests.post(REVIEWS_LIST_PATH.format(host=host), json=query, auth=auth, verify=False)
reviews_list_response.raise_for_status()
return reviews_list_response.json()["result"].get("reviews", [])
def close_review(host, auth, review_id):
query = {
"reviewId": review_id,
"isFlagged": True
}
reviews_list_response = requests.post(CLOSE_REVIEW_PATH.format(host=host), json=query, auth=auth, verify=False)
reviews_list_response.raise_for_status()
def close_reviews(host, project, auth):
batch = fetch_reviews_batch(host, project, auth)
while len(batch):
for review in batch:
close_review(host, auth, review["reviewId"])
print("Successfully closed a batch")
batch = fetch_reviews_batch(host, project, auth)
print("Done")
if __name__ == "__main__":
args = parse_args()
close_reviews(args.host, args.project, auth=(args.login, args.password))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment