[PATCH] D37259: [Tools] Add script to identify new contributors from Phabricator (WIP)
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 29 04:17:54 PDT 2017
fhahn created this revision.
This is a script I built a while ago and I thought it might be good to
share it related to
http://lists.llvm.org/pipermail/llvm-dev/2017-August/116898.html.
If people think that it is useful, I would be happy to turn this into a
proper script.
https://reviews.llvm.org/D37259
Files:
tools/phabricator-helpers/new-contributors.py
Index: tools/phabricator-helpers/new-contributors.py
===================================================================
--- /dev/null
+++ tools/phabricator-helpers/new-contributors.py
@@ -0,0 +1,78 @@
+"""
+ The LLVM Compiler Infrastructure
+
+This file is distributed under the University of Illinois Open Source
+License. See LICENSE.TXT for details.
+
+
+Requires the phabricator API package
+ pip install phabricator==0.7
+Add API token to ~/.arcrc
+ cat ~/.arcrc
+{
+ "hosts": {
+ "https://reviews.llvm.org/api/": {
+ "token": "api-insertYourAPITokenHere"
+ }
+ }
+}
+"""
+
+import os
+import sys
+
+from phabricator import Phabricator
+
+def read_time():
+ if not os.path.isfile('last_review.txt'):
+ print("no last_review.txt file found, starting from the beginning")
+ return 0
+
+ with open('last_review.txt', 'rt') as f:
+ return int(f.read())
+
+
+def write_time(t):
+ with open('last_review.txt', 'wt') as f:
+ f.write(t)
+
+
+SUBSCRIBER_FIELD = 'ccs'
+def add_subscriber(phab, review, user_id):
+ if user_id in review[SUBSCRIBER_FIELD]:
+ return
+
+ fields = {
+ 'ccPHIDs': review[SUBSCRIBER_FIELD] + [user_id,],
+ }
+ phab.differential.updaterevision(
+ id=int(review['id']),
+ diffid=int(review['diffs'][0]),
+ fields=fields, message='')
+
+
+def handle_reviews():
+ phab = Phabricator() # This will use your ~/.arcrc file
+
+ last_review = read_time()
+ new_reviews = phab.differential.query(
+ limit=100, order="order-created", status="status-open"
+ )
+
+ print('Last review timestamp: {}'.format(last_review))
+ new_reviews = [r for r in new_reviews if int(r['dateCreated']) > last_review]
+
+ if len(new_reviews) == 0:
+ print("No new reviews")
+ return
+
+ for r in new_reviews:
+ if len(phab.differential.query(limit=2, authors=[r['authorPHID']])) < 2:
+ print("Welcome new user "+r['uri'])
+ print(' * adding new subscriber')
+ # FIXME: user hardcoded to fhahn, add parameter.
+ add_subscriber(phab, r, 'PHID-USER-n4qjk3mn5cpkqytjhy7d')
+
+ write_time(new_reviews[0]['dateCreated'])
+
+handle_reviews()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37259.113060.patch
Type: text/x-patch
Size: 2255 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170829/b8837344/attachment.bin>
More information about the llvm-commits
mailing list