(
self,
number: int,
owner: str,
repo: str,
dry_run: bool = False,
raw_data: dict[str, Any] | None = None,
)
| 190 | |
| 191 | class PR: |
| 192 | def __init__( |
| 193 | self, |
| 194 | number: int, |
| 195 | owner: str, |
| 196 | repo: str, |
| 197 | dry_run: bool = False, |
| 198 | raw_data: dict[str, Any] | None = None, |
| 199 | ): |
| 200 | self.owner = owner |
| 201 | self.number = number |
| 202 | self.repo_name = repo |
| 203 | self.dry_run = dry_run |
| 204 | self.has_error = False |
| 205 | |
| 206 | if dry_run and raw_data: |
| 207 | # In test mode there is no need to fetch anything |
| 208 | self.raw = raw_data |
| 209 | self.github = None |
| 210 | else: |
| 211 | self.github = GitHubRepo(user=owner, repo=repo, token=os.environ["GITHUB_TOKEN"]) |
| 212 | if os.getenv("DEBUG", "0") == "1": |
| 213 | # For local runs fill in the requested data but cache it for |
| 214 | # later use |
| 215 | cached_path = Path("pr.json") |
| 216 | if not cached_path.exists(): |
| 217 | self.raw = self.fetch_data() |
| 218 | with open(cached_path, "w") as f: |
| 219 | json.dump(self.raw, f, indent=2) |
| 220 | else: |
| 221 | with open(cached_path) as f: |
| 222 | self.raw = json.load(f) |
| 223 | else: |
| 224 | # Usual path, fetch the PR's data based on the number from |
| 225 | # GitHub |
| 226 | self.raw = self.fetch_data() |
| 227 | |
| 228 | def checker(obj, parent_key): |
| 229 | """ |
| 230 | Verify that any paged results don't have extra data (if so the bot |
| 231 | may still work since most relevant comments will be more recent) |
| 232 | """ |
| 233 | if parent_key == "pageInfo": |
| 234 | if obj.get("hasPreviousPage", False): |
| 235 | warnings.warn(f"Found {obj} with a previous page, bot may be missing data") |
| 236 | if obj.get("hasNextPage", False): |
| 237 | warnings.warn(f"Found {obj} with a next page, bot may be missing data") |
| 238 | |
| 239 | walk(self.raw, checker) |
| 240 | |
| 241 | logging.info(f"Verified data, running with PR {to_json_str(self.raw)}") |
| 242 | |
| 243 | def __repr__(self): |
| 244 | return json.dumps(self.raw, indent=2) |
nothing calls this directly
no test coverage detected