11"""GitHub Action to create pull requests for upstream changes."""
22
33# Standard Python Libraries
4+ from collections .abc import Generator
45from enum import Enum , auto
56from importlib .resources import files
67import logging
78import os
89from pathlib import Path
910import subprocess # nosec
1011import sys
11- from typing import Generator , List , Optional , Tuple
1212from urllib .parse import ParseResult , urlparse
1313
1414# Third-Party Libraries
@@ -47,9 +47,9 @@ def clear_ca_variables_in_gha() -> None:
4747
4848
4949def run (
50- cmd : List [str ],
51- cwd : Optional [ str ] = None ,
52- comment : Optional [ str ] = None ,
50+ cmd : list [str ],
51+ cwd : str | None = None ,
52+ comment : str | None = None ,
5353 on_error : OnError = OnError .FAIL ,
5454) -> subprocess .CompletedProcess :
5555 """Run a command and display its output and return code."""
@@ -117,7 +117,7 @@ def get_repo_list(
117117 yield from matching_repos
118118
119119
120- def get_config (repo : Repository .Repository ) -> Optional [ dict ] :
120+ def get_config (repo : Repository .Repository ) -> dict | None :
121121 """Read the lineage configuration for this repo without checking it out."""
122122 config_url : str = (
123123 f"https://raw.githubusercontent.com/{ repo .full_name } /{ repo .default_branch } /{ CONFIG_FILENAME } "
@@ -132,7 +132,7 @@ def get_config(repo: Repository.Repository) -> Optional[dict]:
132132
133133def switch_branch (
134134 repo : Repository .Repository , lineage_id : str , local_branch : str
135- ) -> Tuple [str , bool ]:
135+ ) -> tuple [str , bool ]:
136136 """Switch to the PR branch, and possibly create it."""
137137 branch_name = f"lineage/{ lineage_id } "
138138 logging .info ("Attempting to switch to branch: %s" , branch_name )
@@ -154,7 +154,7 @@ def switch_branch(
154154 return branch_name , False # branch existed
155155
156156
157- def fetch (repo : Repository .Repository , remote_url : str , remote_branch : Optional [ str ] ):
157+ def fetch (repo : Repository .Repository , remote_url : str , remote_branch : str | None ):
158158 """Fetch commits from remote branch."""
159159 if remote_branch :
160160 logging .info ("Fetching %s %s" , remote_url , remote_branch )
@@ -164,9 +164,9 @@ def fetch(repo: Repository.Repository, remote_url: str, remote_branch: Optional[
164164 run ([GIT , "fetch" , remote_url ], cwd = repo .full_name )
165165
166166
167- def merge (repo : Repository .Repository , github_actor : str ) -> Tuple [bool , List [str ]]:
167+ def merge (repo : Repository .Repository , github_actor : str ) -> tuple [bool , list [str ]]:
168168 """Merge previously fetched commits."""
169- conflict_file_list : List [str ] = []
169+ conflict_file_list : list [str ] = []
170170 logging .debug ("Setting git user.name %s" , github_actor )
171171 proc = run ([GIT , "config" , "user.name" , github_actor ], cwd = repo .full_name )
172172 logging .debug ("Setting git user.email %s@github.com" , github_actor )
@@ -308,11 +308,11 @@ def main() -> None:
308308 )
309309
310310 # Get inputs from the environment
311- access_token : Optional [ str ] = core .get_input ("access_token" )
312- github_actor : Optional [ str ] = os .environ .get ("GITHUB_ACTOR" )
313- github_workspace_dir : Optional [ str ] = os .environ .get ("GITHUB_WORKSPACE" )
311+ access_token : str | None = core .get_input ("access_token" )
312+ github_actor : str | None = os .environ .get ("GITHUB_ACTOR" )
313+ github_workspace_dir : str | None = os .environ .get ("GITHUB_WORKSPACE" )
314314 mask_non_public : bool = core .get_boolean_input ("mask_non_public_repos" )
315- repo_query : Optional [ str ] = core .get_input ("repo_query" )
315+ repo_query : str | None = core .get_input ("repo_query" )
316316 include_non_public : bool = core .get_boolean_input ("include_non_public_repos" )
317317
318318 # sanity checks
@@ -405,7 +405,7 @@ def main() -> None:
405405 continue
406406 lineage_id : str
407407 local_branch : str
408- remote_branch : Optional [ str ]
408+ remote_branch : str | None
409409 remote_url : str
410410 if config .get ("version" ) != "1" :
411411 base_message = "Incompatible config version: %s"
@@ -451,7 +451,7 @@ def main() -> None:
451451 )
452452 fetch (repo , remote_url , remote_branch )
453453 changed : bool
454- conflict_file_list : List [str ]
454+ conflict_file_list : list [str ]
455455 changed , conflict_file_list = merge (repo , github_actor )
456456 if not changed :
457457 logging .info (
0 commit comments