33This logic is inspired by that of @tiangolo's
44[FastAPI people script](https://github.com/tiangolo/fastapi/blob/master/.github/actions/people/app/main.py).
55"""
6- import requests
6+
77import logging
88import subprocess
99import sys
1212from pathlib import Path
1313from typing import Any , Container , Dict , List , Set , Union
1414
15+ import requests
1516import yaml
1617from github import Github
17- from pydantic import BaseModel , SecretStr
1818from pydantic_settings import BaseSettings
1919
20- github_graphql_url = "https://api.github.com/graphql"
20+ from pydantic import BaseModel , SecretStr
21+
22+ github_graphql_url = 'https://api.github.com/graphql'
2123
2224discussions_query = """
2325query Q($after: String) {
@@ -287,7 +289,7 @@ class PRsResponse(BaseModel):
287289
288290class Settings (BaseSettings ):
289291 input_token : SecretStr
290- github_repository : str = " pydantic/pydantic"
292+ github_repository : str = ' pydantic/pydantic'
291293 request_timeout : int = 30
292294
293295
@@ -297,24 +299,22 @@ def get_graphql_response(
297299 query : str ,
298300 after : Union [str , None ] = None ,
299301) -> Dict [str , Any ]:
300- headers = {" Authorization" : f" token { settings .input_token .get_secret_value ()} " }
301- variables = {" after" : after }
302+ headers = {' Authorization' : f' token { settings .input_token .get_secret_value ()} ' }
303+ variables = {' after' : after }
302304 response = requests .post (
303305 github_graphql_url ,
304306 headers = headers ,
305307 timeout = settings .request_timeout ,
306- json = {" query" : query , " variables" : variables , " operationName" : "Q" },
308+ json = {' query' : query , ' variables' : variables , ' operationName' : 'Q' },
307309 )
308310 if response .status_code != 200 :
309- logging .error (
310- f"Response was not 200, after: { after } "
311- )
311+ logging .error (f'Response was not 200, after: { after } ' )
312312 logging .error (response .text )
313313 raise RuntimeError (response .text )
314314 data = response .json ()
315- if " errors" in data :
316- logging .error (f" Errors in response, after: { after } " )
317- logging .error (data [" errors" ])
315+ if ' errors' in data :
316+ logging .error (f' Errors in response, after: { after } ' )
317+ logging .error (data [' errors' ])
318318 logging .error (response .text )
319319 raise RuntimeError (response .text )
320320 return data
@@ -390,9 +390,7 @@ def get_discussions_experts(settings: Settings):
390390 for discussion_edge in discussion_edges :
391391 discussion_nodes .append (discussion_edge .node )
392392 last_edge = discussion_edges [- 1 ]
393- discussion_edges = get_graphql_question_discussion_edges (
394- settings = settings , after = last_edge .cursor
395- )
393+ discussion_edges = get_graphql_question_discussion_edges (settings = settings , after = last_edge .cursor )
396394
397395 commentors = Counter ()
398396 last_month_commentors = Counter ()
@@ -483,7 +481,7 @@ def get_contributors(settings: Settings):
483481 pr_reviewers .add (review .author .login )
484482 for reviewer in pr_reviewers :
485483 reviewers [reviewer ] += 1
486- if pr .state == " MERGED" and pr .author :
484+ if pr .state == ' MERGED' and pr .author :
487485 contributors [pr .author .login ] += 1
488486 return contributors , commentors , reviewers , authors
489487
@@ -503,40 +501,45 @@ def get_top_users(
503501 author = authors [commentor ]
504502 users .append (
505503 {
506- " login" : commentor ,
507- " count" : count ,
508- " avatarUrl" : author .avatarUrl ,
509- " url" : author .url ,
504+ ' login' : commentor ,
505+ ' count' : count ,
506+ ' avatarUrl' : author .avatarUrl ,
507+ ' url' : author .url ,
510508 }
511509 )
512510 return users
513511
514512
515- if __name__ == " __main__" :
513+ if __name__ == ' __main__' :
516514 logging .basicConfig (level = logging .INFO )
517515 settings = Settings ()
518- logging .info (f" Using config: { settings .model_dump_json ()} " )
516+ logging .info (f' Using config: { settings .model_dump_json ()} ' )
519517 g = Github (settings .input_token .get_secret_value ())
520518 repo = g .get_repo (settings .github_repository )
521- question_commentors , question_last_month_commentors , question_authors = get_experts (
522- settings = settings
523- )
524- contributors , pr_commentors , reviewers , pr_authors = get_contributors (
525- settings = settings
526- )
519+ question_commentors , question_last_month_commentors , question_authors = get_experts (settings = settings )
520+ contributors , pr_commentors , reviewers , pr_authors = get_contributors (settings = settings )
527521 authors = {** question_authors , ** pr_authors }
528- maintainers_logins = {'samuelcolvin' , 'adriangb' , 'dmontagu' , 'hramezani' , 'Kludex' , 'davidhewitt' , 'sydney-runkle' , 'alexmojaki' }
529- bot_names = {"codecov" , "github-actions" , "pre-commit-ci" , "dependabot" }
522+ maintainers_logins = {
523+ 'samuelcolvin' ,
524+ 'adriangb' ,
525+ 'dmontagu' ,
526+ 'hramezani' ,
527+ 'Kludex' ,
528+ 'davidhewitt' ,
529+ 'sydney-runkle' ,
530+ 'alexmojaki' ,
531+ }
532+ bot_names = {'codecov' , 'github-actions' , 'pre-commit-ci' , 'dependabot' }
530533 maintainers = []
531534 for login in maintainers_logins :
532535 user = authors [login ]
533536 maintainers .append (
534537 {
535- " login" : login ,
536- " answers" : question_commentors [login ],
537- " prs" : contributors [login ],
538- " avatarUrl" : user .avatarUrl ,
539- " url" : user .url ,
538+ ' login' : login ,
539+ ' answers' : question_commentors [login ],
540+ ' prs' : contributors [login ],
541+ ' avatarUrl' : user .avatarUrl ,
542+ ' url' : user .url ,
540543 }
541544 )
542545
@@ -572,53 +575,45 @@ def get_top_users(
572575
573576 extra_experts = [
574577 {
575- " login" : " ybressler" ,
576- " count" : None ,
577- " avatarUrl" : " https://avatars.githubusercontent.com/u/40807730?v=4" ,
578- " url" : " https://github.com/ybressler"
578+ ' login' : ' ybressler' ,
579+ ' count' : None ,
580+ ' avatarUrl' : ' https://avatars.githubusercontent.com/u/40807730?v=4' ,
581+ ' url' : ' https://github.com/ybressler' ,
579582 },
580583 ]
581- expert_logins = {e [" login" ] for e in experts }
582- experts .extend ([expert for expert in extra_experts if expert [" login" ] not in expert_logins ])
584+ expert_logins = {e [' login' ] for e in experts }
585+ experts .extend ([expert for expert in extra_experts if expert [' login' ] not in expert_logins ])
583586
584587 people = {
585- " maintainers" : maintainers ,
586- " experts" : experts ,
587- " last_month_active" : last_month_active ,
588- " top_contributors" : top_contributors ,
589- " top_reviewers" : top_reviewers ,
588+ ' maintainers' : maintainers ,
589+ ' experts' : experts ,
590+ ' last_month_active' : last_month_active ,
591+ ' top_contributors' : top_contributors ,
592+ ' top_reviewers' : top_reviewers ,
590593 }
591- people_path = Path ("./docs/plugins/people.yml" )
592- people_old_content = people_path .read_text (encoding = "utf-8" )
593- new_people_content = yaml .dump (
594- people , sort_keys = False , width = 200 , allow_unicode = True
595- )
596- if (
597- people_old_content == new_people_content
598- ):
594+ people_path = Path ('./docs/plugins/people.yml' )
595+ people_old_content = people_path .read_text (encoding = 'utf-8' )
596+ new_people_content = yaml .dump (people , sort_keys = False , width = 200 , allow_unicode = True )
597+ if people_old_content == new_people_content :
599598 logging .info ("The Pydantic People data hasn't changed, finishing." )
600599 sys .exit (0 )
601- people_path .write_text (new_people_content , encoding = "utf-8" )
602-
603- logging .info ("Setting up GitHub Actions git user" )
604- subprocess .run (["git" , "config" , "user.name" , "github-actions" ], check = True )
605- subprocess .run (
606- ["git" , "config" , "user.email" , "github-actions@github.com" ], check = True
607- )
608-
609- branch_name = "pydantic-people-update"
610- logging .info (f"Creating a new branch { branch_name } " )
611- subprocess .run (["git" , "checkout" , "-b" , branch_name ], check = True )
612- logging .info ("Adding updated file" )
613- subprocess .run (
614- ["git" , "add" , str (people_path )], check = True
615- )
616- logging .info ("Committing updated file" )
617- message = "👥 Update Pydantic People"
618- result = subprocess .run (["git" , "commit" , "-m" , message ], check = True )
619- logging .info ("Pushing branch" )
620- subprocess .run (["git" , "push" , "origin" , branch_name ], check = True )
621- logging .info ("Creating PR" )
622- pr = repo .create_pull (title = message , body = message , base = "main" , head = branch_name )
623- logging .info (f"Created PR: { pr .number } " )
624- logging .info ("Finished" )
600+ people_path .write_text (new_people_content , encoding = 'utf-8' )
601+
602+ logging .info ('Setting up GitHub Actions git user' )
603+ subprocess .run (['git' , 'config' , 'user.name' , 'github-actions' ], check = True )
604+ subprocess .run (['git' , 'config' , 'user.email' , 'github-actions@github.com' ], check = True )
605+
606+ branch_name = 'pydantic-people-update'
607+ logging .info (f'Creating a new branch { branch_name } ' )
608+ subprocess .run (['git' , 'checkout' , '-b' , branch_name ], check = True )
609+ logging .info ('Adding updated file' )
610+ subprocess .run (['git' , 'add' , str (people_path )], check = True )
611+ logging .info ('Committing updated file' )
612+ message = '👥 Update Pydantic People'
613+ result = subprocess .run (['git' , 'commit' , '-m' , message ], check = True )
614+ logging .info ('Pushing branch' )
615+ subprocess .run (['git' , 'push' , 'origin' , branch_name ], check = True )
616+ logging .info ('Creating PR' )
617+ pr = repo .create_pull (title = message , body = message , base = 'main' , head = branch_name )
618+ logging .info (f'Created PR: { pr .number } ' )
619+ logging .info ('Finished' )
0 commit comments