Skip to content

Commit ccca540

Browse files
committed
Refactor cherry_pick_v2.py to use Any type for PullRequest references
This commit updates the `cherry_pick_v2.py` script to replace specific type hints for PullRequest with the more generic Any type. This change enhances flexibility in handling PullRequest objects, accommodating potential variations in the GitHub API. Key changes: - Updated type hints for `pull_requests` and related functions to use `Any` instead of the specific `PullRequest` type. - Adjusted function signatures to reflect the new type annotations, improving code maintainability and compatibility with future API changes.
1 parent 285b82d commit ccca540

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

.github/scripts/cherry_pick_v2.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
Maintains order of input sources and creates PRs with proper metadata.
66
"""
77

8+
from __future__ import annotations
9+
810
import os
911
import sys
1012
import datetime
@@ -14,9 +16,9 @@
1416
import re
1517
import tempfile
1618
import shutil
17-
from typing import List, Optional, Tuple
19+
from typing import List, Optional, Tuple, Any
1820
from dataclasses import dataclass, field
19-
from github import Github, GithubException, PullRequest, Auth
21+
from github import Github, GithubException, Auth
2022
import requests
2123

2224
try:
@@ -40,13 +42,13 @@ class Source:
4042
title: str
4143
body_item: str
4244
author: Optional[str]
43-
pull_requests: List[PullRequest]
45+
pull_requests: List[Any] # github.PullRequest.PullRequest
4446

4547

4648
@dataclass
4749
class BackportResult:
4850
target_branch: str
49-
pr: Optional[PullRequest] = None
51+
pr: Optional[Any] = None # github.PullRequest.PullRequest
5052
conflict_files: List[ConflictInfo] = field(default_factory=list)
5153
cherry_pick_logs: List[str] = field(default_factory=list)
5254

@@ -108,7 +110,7 @@ def create_commit_source(commit, repo, logger) -> Source:
108110
)
109111

110112

111-
def create_pr_source(pull: PullRequest, allow_unmerged: bool, logger) -> Source:
113+
def create_pr_source(pull: Any, allow_unmerged: bool, logger) -> Source: # pull: github.PullRequest.PullRequest
112114
"""Creates source from PR"""
113115
if not pull.merged:
114116
commit_shas = [c.sha for c in pull.get_commits()]
@@ -155,7 +157,7 @@ def detect_conflicts(repo_path: str, logger) -> List[ConflictInfo]:
155157
return conflict_files
156158

157159

158-
def get_linked_issues(repo, token: str, pull_requests: List[PullRequest], logger) -> str:
160+
def get_linked_issues(repo, token: str, pull_requests: List[Any], logger) -> str: # pull_requests: List[github.PullRequest.PullRequest]
159161
"""Gets linked issues for all PRs"""
160162
all_issues = []
161163
owner, repo_name = repo.full_name.split('/')
@@ -385,7 +387,7 @@ def build_pr_content(
385387
return title, body
386388

387389

388-
def find_existing_backport_comment(pull: PullRequest, logger):
390+
def find_existing_backport_comment(pull: Any, logger): # pull: github.PullRequest.PullRequest
389391
"""Finds existing backport comment"""
390392
try:
391393
for comment in pull.get_issue_comments():
@@ -396,7 +398,7 @@ def find_existing_backport_comment(pull: PullRequest, logger):
396398
return None
397399

398400

399-
def update_comments(backport_comments: List[Tuple[PullRequest, object]], results: List, skipped_branches: List[Tuple[str, str]], target_branches: List[str], workflow_url: Optional[str], logger):
401+
def update_comments(backport_comments: List[Tuple[Any, object]], results: List, skipped_branches: List[Tuple[str, str]], target_branches: List[str], workflow_url: Optional[str], logger): # backport_comments: List[Tuple[github.PullRequest.PullRequest, object]]
400402
"""Updates comments with backport results"""
401403
if not backport_comments:
402404
return

0 commit comments

Comments
 (0)