|
4 | 4 |
|
5 | 5 | import os |
6 | 6 | import re |
| 7 | +from dataclasses import dataclass |
7 | 8 | from os.path import dirname, join |
8 | 9 |
|
9 | 10 | from dotenv import load_dotenv |
|
45 | 46 | ] |
46 | 47 |
|
47 | 48 |
|
| 49 | +@dataclass(frozen=True) |
| 50 | +class EvergreenConfig: # pylint: disable=too-many-instance-attributes |
| 51 | + """Configuration for the Evergreen action, parsed from environment variables.""" |
| 52 | + |
| 53 | + organization: str | None |
| 54 | + repository_list: list[str] |
| 55 | + search_query: str | None |
| 56 | + gh_app_id: int | None |
| 57 | + gh_app_installation_id: int | None |
| 58 | + gh_app_private_key_bytes: bytes |
| 59 | + gh_app_enterprise_only: bool |
| 60 | + token: str |
| 61 | + ghe: str |
| 62 | + ghe_api_url: str |
| 63 | + exempt_repositories_list: list[str] |
| 64 | + follow_up_type: str |
| 65 | + title: str |
| 66 | + body: str |
| 67 | + created_after_date: str |
| 68 | + dry_run: bool |
| 69 | + commit_message: str |
| 70 | + project_id: str | None |
| 71 | + group_dependencies: bool | None |
| 72 | + filter_visibility: list[str] |
| 73 | + batch_size: int | None |
| 74 | + enable_security_updates: bool | None |
| 75 | + exempt_ecosystems: list[str] |
| 76 | + update_existing: bool | None |
| 77 | + repo_specific_exemptions: dict |
| 78 | + schedule: str |
| 79 | + schedule_day: str |
| 80 | + team_name: str | None |
| 81 | + labels: list[str] |
| 82 | + dependabot_config_file: str | None |
| 83 | + |
| 84 | + |
48 | 85 | def get_api_endpoint(ghe: str, ghe_api_url: str) -> str: |
49 | 86 | """Return the GitHub API endpoint URL. |
50 | 87 |
|
@@ -134,74 +171,15 @@ def parse_repo_specific_exemptions(repo_specific_exemptions_str: str) -> dict: |
134 | 171 |
|
135 | 172 | def get_env_vars( |
136 | 173 | test: bool = False, |
137 | | -) -> tuple[ |
138 | | - str | None, |
139 | | - list[str], |
140 | | - str | None, |
141 | | - int | None, |
142 | | - int | None, |
143 | | - bytes, |
144 | | - bool, |
145 | | - str, |
146 | | - str, |
147 | | - list[str], |
148 | | - str, |
149 | | - str, |
150 | | - str, |
151 | | - str, |
152 | | - bool, |
153 | | - str, |
154 | | - str | None, |
155 | | - bool | None, |
156 | | - list[str] | None, |
157 | | - int | None, |
158 | | - bool | None, |
159 | | - list[str], |
160 | | - bool | None, |
161 | | - dict, |
162 | | - str, |
163 | | - str, |
164 | | - str | None, |
165 | | - list[str], |
166 | | - str | None, |
167 | | - str, |
168 | | -]: |
| 174 | +) -> EvergreenConfig: |
169 | 175 | """ |
170 | 176 | Get the environment variables for use in the action. |
171 | 177 |
|
172 | 178 | Args: |
173 | | - None |
| 179 | + test: If True, skip loading from .env file. |
174 | 180 |
|
175 | 181 | Returns: |
176 | | - organization (str): The organization to search for repositories in |
177 | | - repository_list (list[str]): A list of repositories to search for |
178 | | - search_query (str): A search query string to filter repositories by |
179 | | - gh_app_id (int | None): The GitHub App ID to use for authentication |
180 | | - gh_app_installation_id (int | None): The GitHub App Installation ID to use for authentication |
181 | | - gh_app_private_key_bytes (bytes): The GitHub App Private Key as bytes to use for authentication |
182 | | - gh_app_enterprise_only (bool): Set this to true if the GH APP is created on GHE and needs to communicate with GHE api only |
183 | | - token (str): The GitHub token to use for authentication |
184 | | - ghe (str): The GitHub Enterprise URL to use for authentication |
185 | | - exempt_repositories_list (list[str]): A list of repositories to exempt from the action |
186 | | - follow_up_type (str): The type of follow up to open (issue or pull) |
187 | | - title (str): The title of the follow up |
188 | | - body (str): The body of the follow up |
189 | | - created_after_date (str): The date to filter repositories by |
190 | | - dry_run (bool): Whether or not to actually open issues/pull requests |
191 | | - commit_message (str): The commit message of the follow up |
192 | | - group_dependencies (bool): Whether to group dependencies in the dependabot.yml file |
193 | | - filter_visibility (list[str]): Run the action only on repositories with the specified listed visibility |
194 | | - batch_size (int): The max number of repositories in scope |
195 | | - enable_security_updates (bool): Whether to enable security updates in target repositories |
196 | | - exempt_ecosystems_list (list[str]): A list of package ecosystems to exempt from the action |
197 | | - update_existing (bool): Whether to update existing dependabot configuration files |
198 | | - repo_specific_exemptions (dict): A dictionary of per repository ecosystem exemptions |
199 | | - schedule (str): The schedule to run the action on |
200 | | - schedule_day (str): The day of the week to run the action on if schedule is daily |
201 | | - team_name (str): The team to search for repositories in |
202 | | - labels (list[str]): A list of labels to be added to dependabot configuration |
203 | | - dependabot_config_file (str): Dependabot extra configuration file location path |
204 | | - ghe_api_url (str): The full GitHub Enterprise API endpoint URL override |
| 182 | + EvergreenConfig: A frozen dataclass containing all configuration values. |
205 | 183 | """ |
206 | 184 |
|
207 | 185 | if not test: # pragma: no cover |
@@ -404,35 +382,35 @@ def get_env_vars( |
404 | 382 | f"No dependabot extra configuration found. Please create one in {dependabot_config_file}" |
405 | 383 | ) |
406 | 384 |
|
407 | | - return ( |
408 | | - organization, |
409 | | - repositories_list, |
410 | | - search_query, |
411 | | - gh_app_id, |
412 | | - gh_app_installation_id, |
413 | | - gh_app_private_key_bytes, |
414 | | - gh_app_enterprise_only, |
415 | | - token, |
416 | | - ghe, |
417 | | - exempt_repositories_list, |
418 | | - follow_up_type, |
419 | | - title, |
420 | | - body, |
421 | | - created_after_date, |
422 | | - dry_run_bool, |
423 | | - commit_message, |
424 | | - project_id, |
425 | | - group_dependencies_bool, |
426 | | - filter_visibility_list, |
427 | | - batch_size, |
428 | | - enable_security_updates_bool, |
429 | | - exempt_ecosystems_list, |
430 | | - update_existing, |
431 | | - repo_specific_exemptions, |
432 | | - schedule, |
433 | | - schedule_day, |
434 | | - team_name, |
435 | | - labels_list, |
436 | | - dependabot_config_file, |
437 | | - ghe_api_url, |
| 385 | + return EvergreenConfig( |
| 386 | + organization=organization, |
| 387 | + repository_list=repositories_list, |
| 388 | + search_query=search_query, |
| 389 | + gh_app_id=gh_app_id, |
| 390 | + gh_app_installation_id=gh_app_installation_id, |
| 391 | + gh_app_private_key_bytes=gh_app_private_key_bytes, |
| 392 | + gh_app_enterprise_only=gh_app_enterprise_only, |
| 393 | + token=token, |
| 394 | + ghe=ghe, |
| 395 | + ghe_api_url=ghe_api_url, |
| 396 | + exempt_repositories_list=exempt_repositories_list, |
| 397 | + follow_up_type=follow_up_type, |
| 398 | + title=title, |
| 399 | + body=body, |
| 400 | + created_after_date=created_after_date, |
| 401 | + dry_run=dry_run_bool, |
| 402 | + commit_message=commit_message, |
| 403 | + project_id=project_id, |
| 404 | + group_dependencies=group_dependencies_bool, |
| 405 | + filter_visibility=filter_visibility_list, |
| 406 | + batch_size=batch_size, |
| 407 | + enable_security_updates=enable_security_updates_bool, |
| 408 | + exempt_ecosystems=exempt_ecosystems_list, |
| 409 | + update_existing=update_existing, |
| 410 | + repo_specific_exemptions=repo_specific_exemptions, |
| 411 | + schedule=schedule, |
| 412 | + schedule_day=schedule_day, |
| 413 | + team_name=team_name, |
| 414 | + labels=labels_list, |
| 415 | + dependabot_config_file=dependabot_config_file, |
438 | 416 | ) |
0 commit comments