summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNigel Babu <nigelb@redhat.com>2017-11-30 14:57:04 +0530
committerNigel Babu <nigelb@redhat.com>2017-11-30 14:57:04 +0530
commit978a2ab96413f0ed4ce2d13a2eedd84671b48c0c (patch)
treeaf8e18da90d2b80f3ce84c49015573f806b498b4
parent432a1d80ddf1f2ed4e2e39ca94464017f52db0af (diff)
Show better errors for close-old-reviews
Port to python3 Change-Id: Iebca168bf3b1e448f5e2092d04213d28934593e3
-rw-r--r--build-gluster-org/scripts/close-old-reviews.py57
1 files changed, 36 insertions, 21 deletions
diff --git a/build-gluster-org/scripts/close-old-reviews.py b/build-gluster-org/scripts/close-old-reviews.py
index 72fbcca..f4259b4 100644
--- a/build-gluster-org/scripts/close-old-reviews.py
+++ b/build-gluster-org/scripts/close-old-reviews.py
@@ -1,12 +1,19 @@
#!/usr/bin/env python
-
-import requests
+'''
+A small script to close old reviews in Gerrit
+'''
+from __future__ import absolute_import
+from __future__ import print_function
import json
import os
import sys
+import requests
-def get_unique_id(days=90, count=25):
+def get_change_ids(days=90, count=25):
+ '''
+ Get all the change IDs to close
+ '''
r = requests.get('https://review.gluster.org/changes/'
'?q=status:open+age:{}days+project:glusterfs'.
format(days))
@@ -16,41 +23,49 @@ def get_unique_id(days=90, count=25):
unique_id = []
for item in parsed_output:
unique_id.append(item['change_id'])
- n = -(int(count))
- oldest_reviews = unique_id[n:]
+ oldest_reviews = unique_id[-int(count):]
return oldest_reviews
-def close_reviews(oldest_id):
- for uid in oldest_id:
- url = 'https://review.gluster.org/a/changes/glusterfs~master~{}/abandon'.format(uid)
- data = {"message" : "This change has not had activity in 90 days."
- "We're automatically closing this change.\n"
- "Please re-open and get in touch with the component owners"
- " if you are interested in merging this patch."}
+def close_reviews(change_ids):
+ '''
+ Close the list of given change_ids
+ '''
+ for uid in change_ids:
+ url = ('https://review.gluster.org/a/changes/glusterfs~master~{}'
+ '/abandon'.format(uid))
+ data = {
+ "message": "This change has not had activity in 90 days. "
+ "We're automatically closing this change.\n"
+ "Please re-open and get in touch with the component "
+ "owners if you are interested in merging this patch."
+ }
username = os.environ.get('HTTP_USERNAME')
password = os.environ.get('HTTP_PASSWORD')
+ print("Attempting to close review: ", uid)
response = requests.post(url, auth=(username, password), json=data)
try:
response.raise_for_status()
- except Exception:
- print("Authentication error. Username or password is incorrect")
+ except requests.exceptions.HTTPError:
+ print(response.text)
sys.exit(1)
def main():
-
+ '''
+ Put all the pieces together
+ '''
# get the list of oldest unique_id
- days = os.environ.get('DAYS')
- count = os.environ.get('REV_COUNT')
- ids = get_unique_id(days, count)
+ days = os.environ.get('DAYS', 90)
+ count = os.environ.get('REV_COUNT', 25)
+ change_ids = get_change_ids(days, count)
# abandoning those reviews with a message
- close_reviews(ids)
+ close_reviews(change_ids)
# printing the list of abandoned reviews
print("The list of following reviews are abandoned:\n")
- for x in ids:
- print('https://review.gluster.org/#/q/{}\n'.format(str(x)))
+ for change in change_ids:
+ print('https://review.gluster.org/#/q/', str(change))
main()