label_approved.py — fastapi Source File
Architecture documentation for label_approved.py, a python file in the fastapi codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 7f22203c_da11_9853_3598_82d00d007cbb["label_approved.py"] a4a63925_76bf_e8a8_bef2_cb86d161a300["logging"] 7f22203c_da11_9853_3598_82d00d007cbb --> a4a63925_76bf_e8a8_bef2_cb86d161a300 0dda2280_3359_8460_301c_e98c77e78185["typing"] 7f22203c_da11_9853_3598_82d00d007cbb --> 0dda2280_3359_8460_301c_e98c77e78185 319484c7_306f_9ec1_3de4_788004953d77["github"] 7f22203c_da11_9853_3598_82d00d007cbb --> 319484c7_306f_9ec1_3de4_788004953d77 c777a238_ef79_6a11_2bae_eae831e85e23["github.PullRequestReview"] 7f22203c_da11_9853_3598_82d00d007cbb --> c777a238_ef79_6a11_2bae_eae831e85e23 6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"] 7f22203c_da11_9853_3598_82d00d007cbb --> 6913fbd4_39df_d14b_44bb_522e99b65b90 d2280984_30d0_0ee6_97ed_95cfcc358f18["pydantic_settings"] 7f22203c_da11_9853_3598_82d00d007cbb --> d2280984_30d0_0ee6_97ed_95cfcc358f18 style 7f22203c_da11_9853_3598_82d00d007cbb fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import logging
from typing import Literal
from github import Github
from github.PullRequestReview import PullRequestReview
from pydantic import BaseModel, SecretStr
from pydantic_settings import BaseSettings
class LabelSettings(BaseModel):
await_label: str | None = None
number: int
default_config = {"approved-2": LabelSettings(await_label="awaiting-review", number=2)}
class Settings(BaseSettings):
github_repository: str
token: SecretStr
debug: bool | None = False
config: dict[str, LabelSettings] | Literal[""] = default_config
settings = Settings()
if settings.debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
logging.debug(f"Using config: {settings.model_dump_json()}")
g = Github(settings.token.get_secret_value())
repo = g.get_repo(settings.github_repository)
for pr in repo.get_pulls(state="open"):
logging.info(f"Checking PR: #{pr.number}")
pr_labels = list(pr.get_labels())
pr_label_by_name = {label.name: label for label in pr_labels}
reviews = list(pr.get_reviews())
review_by_user: dict[str, PullRequestReview] = {}
for review in reviews:
if review.user.login in review_by_user:
stored_review = review_by_user[review.user.login]
if review.submitted_at >= stored_review.submitted_at:
review_by_user[review.user.login] = review
else:
review_by_user[review.user.login] = review
approved_reviews = [
review for review in review_by_user.values() if review.state == "APPROVED"
]
config = settings.config or default_config
for approved_label, conf in config.items():
logging.debug(f"Processing config: {conf.model_dump_json()}")
if conf.await_label is None or (conf.await_label in pr_label_by_name):
logging.debug(f"Processable PR: {pr.number}")
if len(approved_reviews) >= conf.number:
logging.info(f"Adding label to PR: {pr.number}")
pr.add_to_labels(approved_label)
if conf.await_label:
logging.info(f"Removing label from PR: {pr.number}")
pr.remove_from_labels(conf.await_label)
logging.info("Finished")
Domain
Subdomains
Functions
Classes
Dependencies
- github
- github.PullRequestReview
- logging
- pydantic
- pydantic_settings
- typing
Source
Frequently Asked Questions
What does label_approved.py do?
label_approved.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Applications subdomain.
What functions are defined in label_approved.py?
label_approved.py defines 1 function(s): logging.
What does label_approved.py depend on?
label_approved.py imports 6 module(s): github, github.PullRequestReview, logging, pydantic, pydantic_settings, typing.
Where is label_approved.py in the architecture?
label_approved.py is located at scripts/label_approved.py (domain: FastAPI, subdomain: Applications, directory: scripts).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free