fonsdant commented on code in PR #17124:
URL: https://github.com/apache/kafka/pull/17124#discussion_r1751051460


##########
refresh_collaborators.py:
##########
@@ -0,0 +1,181 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+This script automates the process of fetching contributor data from GitHub
+repositories, filtering top contributors who are not part of the existing
+committers, and updating a configuration file (.asf.yaml) in the repository to
+include these new contributors.
+"""
+
+import io
+import logging
+import os
+from datetime import datetime, timedelta
+from typing import Dict, List, Tuple
+
+from bs4 import BeautifulSoup
+from github import Github, GithubException
+from github.ContentFile import ContentFile
+from github.Repository import Repository
+from github.PaginatedList import PaginatedList
+from github.Commit import Commit
+from ruamel.yaml import YAML
+
+logging.basicConfig(
+    
format='{"timestamp":"%(asctime)s","level":"%(levelname)s","message":"%(message)s"}',
+    level=logging.INFO,
+)
+
+GITHUB_TOKEN: str = os.getenv("GITHUB_TOKEN")
+REPO_KAFKA_SITE: str = "apache/kafka-site"
+REPO_KAFKA: str = "apache/kafka"
+ASF_YAML_PATH: str = ".asf.yaml"
+BRANCH_NAME: str = "update-asf-yaml-github-whitelist-and-collaborators"
+COMMIT_MESSAGE: str = (
+    "MINOR: Update .asf.yaml file with refreshed github_whitelist and 
collaborators"
+)
+PR_TITLE: str = COMMIT_MESSAGE
+PR_BODY: str = (
+    "This pull request updates the github_whitelist and collaborators lists "
+    "in .asf.yaml."
+)
+TOP_N_CONTRIBUTORS: int = 10
+
+
+def get_github_client() -> Github:
+    """
+    Initialize GitHub client with token.
+    """
+    if not GITHUB_TOKEN:
+        logging.error("GITHUB_TOKEN is not set in the environment")
+        raise ValueError("GITHUB_TOKEN is not set in the environment")
+
+    logging.info("Successfully initialized GitHub client")
+    return Github(GITHUB_TOKEN)
+
+
+def get_committers_list(repo: Repository) -> List[str]:
+    """
+    Fetch the committers from the given repository.
+    """
+    logging.info(f"Fetching committers from the repository {REPO_KAFKA_SITE}")
+    committers_file: ContentFile = repo.get_contents("committers.html")
+    content: bytes = committers_file.decoded_content
+    soup: BeautifulSoup = BeautifulSoup(content, "html.parser")
+
+    committers = [login.text for login in soup.find_all("div", 
class_="github_login")]
+    logging.info(f"Found {len(committers)} committers")
+    return committers
+
+
+def get_top_contributors(repo: Repository, committers: List[str]) -> List[str]:
+    """
+    Get top contributors for the given repository excluding committers.
+    """
+    logging.info(f"Fetching contributors from the repository {REPO_KAFKA}")
+    one_year_ago: datetime = datetime.now() - timedelta(days=365)
+    contributors: Dict[str, int] = {}
+
+    last_year_commits: PaginatedList[Commit] = 
repo.get_commits(since=one_year_ago)

Review Comment:
   Since we are authenticated (have a token), I think rate limit is not a 
problem. See 
(this)[https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#about-primary-rate-limits].
   
   >You can use a personal access token to make API requests. Additionally, you 
can authorize a GitHub App or OAuth app, which can then make API requests on 
your behalf.
   >
   >All of these requests count towards your personal rate limit of 5,000 
requests per hour. Requests made on your behalf by a GitHub App that is owned 
by a GitHub Enterprise Cloud organization have a higher rate limit of 15,000 
requests per hour. Similarly, requests made on your behalf by a OAuth app that 
is owned or approved by a GitHub Enterprise Cloud organization have a higher 
rate limit of 15,000 requests per hour if you are a member of the GitHub 
Enterprise Cloud organization.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to