[llvm] [workflows] Add a new workflow for checking commit access qualifications (PR #93301)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 16 23:53:50 PDT 2024
================
@@ -0,0 +1,443 @@
+import datetime
+import github
+import re
+import requests
+import time
+import sys
+import re
+
+
+class User:
+ THRESHOLD = 5
+
+ def __init__(self, name, triage_list):
+ self.name = name
+ self.authored = 0
+ self.merged = 0
+ self.reviewed = 0
+ self.triage_list = triage_list
+
+ def add_authored(self, val=1):
+ self.authored += val
+ if self.meets_threshold():
+ print(self.name, "meets the threshold with authored commits")
+ del self.triage_list[self.name]
+
+ def set_authored(self, val):
+ self.authored = 0
+ self.add_authored(val)
+
+ def add_merged(self, val=1):
+ self.merged += val
+ if self.meets_threshold():
+ print(self.name, "meets the threshold with merged commits")
+ del self.triage_list[self.name]
+
+ def add_reviewed(self, val=1):
+ self.reviewed += val
+ if self.meets_threshold():
+ print(self.name, "meets the threshold with reviewed commits")
+ del self.triage_list[self.name]
+
+ def get_total(self):
+ return self.authored + self.merged + self.reviewed
+
+ def meets_threshold(self):
+ return self.get_total() >= self.THRESHOLD
+
+ def __repr__(self):
+ return "{} : a: {} m: {} r: {}".format(
+ self.name, self.authored, self.merged, self.reviewed
+ )
+
+
+def run_graphql_query(
+ query: str, variables: dict, token: str, retry: bool = True
+) -> dict:
+ """
+ This function submits a graphql query and returns the results as a
+ dictionary.
+ """
+ s = requests.Session()
+ retries = requests.adapters.Retry(total=8, backoff_factor=2, status_forcelist=[504])
+ s.mount("https://", requests.adapters.HTTPAdapter(max_retries=retries))
+
+ headers = {
+ "Authorization": "bearer {}".format(token),
+ # See
+ # https://github.blog/2021-11-16-graphql-global-id-migration-update/
+ "X-Github-Next-Global-ID": "1",
+ }
+ request = s.post(
+ url="https://api.github.com/graphql",
+ json={"query": query, "variables": variables},
+ headers=headers,
+ )
+
+ rate_limit = request.headers.get("X-RateLimit-Remaining")
+ print(rate_limit)
+ if rate_limit and int(rate_limit) < 10:
+ reset_time = int(request.headers["X-RateLimit-Reset"])
+ while reset_time - int(time.time()) > 0:
+ time.sleep(60)
+ print(
+ "Waiting until rate limit reset",
+ reset_time - int(time.time()),
+ "seconds remaining",
+ )
+
+ if request.status_code == 200:
+ if "data" not in request.json():
+ print(request.json())
+ sys.exit(1)
+ return request.json()["data"]
+ elif retry:
+ return run_graphql_query(query, variables, token, False)
+ else:
+ raise Exception(
+ "Failed to run graphql query\nquery: {}\nerror: {}".format(
+ query, request.json()
+ )
+ )
+
+
+def check_manual_requests(start_date, token) -> bool:
+ query = """
+ query ($query: String!) {
+ search(query: $query, type: ISSUE, first: 100) {
+ nodes {
+ ... on Issue {
+ body
+ comments (first: 100) {
+ nodes {
+ author {
+ login
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ """
+ formatted_start_date = start_date.strftime("%Y-%m-%dT%H:%M:%S")
+ variables = {
+ "query": f"type:issue created:>{formatted_start_date} org:llvm repo:llvm-project label:infrastructure:commit-access"
+ }
+
+ data = run_graphql_query(query, variables, token)
+ users = []
+ for issue in data["search"]["nodes"]:
+ users.extend([user[1:] for user in re.findall("@[^ ,\n]+", issue["body"])])
+ # Do we need to check comments if we are checking mentions??
----------------
boomanaiden154 wrote:
This seems left over from testing?
https://github.com/llvm/llvm-project/pull/93301
More information about the llvm-commits
mailing list