summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordeepshikhaaa <deepshikhakhandelwal8@gmail.com>2017-11-13 17:14:40 +0530
committerNigel Babu <nigelb@redhat.com>2017-11-21 06:37:33 +0000
commitee1cf947652c750a57a20d0573a8dd4c239cb311 (patch)
tree020dd793264500ae01fd5528d807e0900d545a3b
parent989f67a45843937d4a285daaa012fd6b6ea58eb5 (diff)
Job to abandon the oldest reviews
Change-Id: I143ef9c65c1fa7755d5d1e21fb32c484396c887d
-rw-r--r--build-gluster-org/jobs/close_old_reviews.yml30
-rw-r--r--build-gluster-org/scripts/close_old_reviews.py54
2 files changed, 84 insertions, 0 deletions
diff --git a/build-gluster-org/jobs/close_old_reviews.yml b/build-gluster-org/jobs/close_old_reviews.yml
new file mode 100644
index 0000000..e8ad6cc
--- /dev/null
+++ b/build-gluster-org/jobs/close_old_reviews.yml
@@ -0,0 +1,30 @@
+- job:
+ name: close_old_reviews
+ node: smoke7
+ description: Closing the oldest reviews
+ project-type: freestyle
+ concurrent: true
+
+ triggers:
+ - timed: "H 0 * * *"
+
+ parameters:
+ - string:
+ default: '90'
+ description: Reviews which are 90 days or more older on Gerrit
+ name: DAYS
+ - string:
+ default: '25'
+ description: Number of oldest reviews to be abandoned on Gerrit
+ name: REV_COUNT
+
+ builders:
+ - shell: !include-raw: ../scripts/close_old_reviews.py
+
+ wrappers:
+ - timestamps
+ - credentials-binding:
+ - username-password-separated:
+ credential-id: 7e0c919e-4568-42ac-b28a-660a148609fe
+ username: HTTP_USERNAME
+ password: HTTP_PASSWORD
diff --git a/build-gluster-org/scripts/close_old_reviews.py b/build-gluster-org/scripts/close_old_reviews.py
new file mode 100644
index 0000000..5aed85e
--- /dev/null
+++ b/build-gluster-org/scripts/close_old_reviews.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+import requests
+import json
+import os
+
+
+def get_unique_id(days=90, count=25):
+ r = requests.get('https://review.gluster.org/changes/
+ '?q=status:open+age:{}days+project:glusterfs'.
+ format(days))
+ output = r.text
+ cleaned_output = '\n'.join(output.split('\n')[1:])
+ parsed_output = json.loads(cleaned_output)
+ unique_id = []
+ for item in parsed_output:
+ unique_id.append(item['changed_id'])
+ n = -(int(count))
+ oldest_reviews = unique_id[n:]
+ return oldest_reviews
+
+
+def close_reviews(oldest_id):
+ for uid in oldest_id:
+ try:
+ 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')
+ respone = requests.post(url, auth('username', 'password'), json=data)
+ response.raise_for_status()
+ except Exception:
+ print("Authentication error.Username or password is incorrect")
+
+
+def main():
+
+ # get the list of oldest unique_id
+ days = os.environ.get('DAYS')
+ count = os.environ.get('REV_COUNT')
+ ids = get_unique_id(days, count)
+
+ # abandoning those reviews with a message
+ close_reviews(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)))
+
+main()