Preflight checks.
()
| 92 | |
| 93 | |
| 94 | async def preflight(): |
| 95 | """Preflight checks.""" |
| 96 | event_data = get_event_data() |
| 97 | ref: str | None = None |
| 98 | |
| 99 | hacs = HacsBase() |
| 100 | hacs.hass = HomeAssistant("") |
| 101 | |
| 102 | hacs.system.action = True |
| 103 | hacs.configuration.token = TOKEN |
| 104 | hacs.core.config_path = None |
| 105 | |
| 106 | async with aiohttp.ClientSession() as session: |
| 107 | hacs.session = session |
| 108 | hacs.validation = ValidationManager(hacs=hacs, hass=hacs.hass) |
| 109 | hacs.githubapi = GitHubAPI( |
| 110 | token=hacs.configuration.token, |
| 111 | session=session, |
| 112 | client_name="HACS/Action", |
| 113 | ) |
| 114 | |
| 115 | if REPOSITORY and CATEGORY: |
| 116 | repository = REPOSITORY |
| 117 | category = CATEGORY |
| 118 | elif GITHUB_REPOSITORY == HacsGitHubRepo.DEFAULT: |
| 119 | category = choose_category() |
| 120 | repository = await choose_repository(hacs.githubapi, category) |
| 121 | LOGGER.info(f"Actor: {GITHUB_ACTOR}") |
| 122 | else: |
| 123 | category = CATEGORY.lower() |
| 124 | if event_data.get("pull_request") is not None: |
| 125 | head = event_data["pull_request"]["head"] |
| 126 | ref = head["ref"] |
| 127 | repository = head["repo"]["full_name"] |
| 128 | else: |
| 129 | repository = GITHUB_REPOSITORY |
| 130 | if event_data.get("ref") is not None: |
| 131 | # For push events |
| 132 | ref = event_data["ref"] |
| 133 | |
| 134 | # For tag events |
| 135 | if ref.startswith("refs/tags/"): |
| 136 | ref = ref.split("/")[-1] |
| 137 | |
| 138 | LOGGER.info(f"Category: {category}") |
| 139 | LOGGER.info(f"Repository: {repository}{f'@{ref}' if ref else ''}") |
| 140 | |
| 141 | if TOKEN is None: |
| 142 | error("No GitHub token found, use env GITHUB_TOKEN to set this.") |
| 143 | |
| 144 | if repository is None: |
| 145 | error("No repository found, use env REPOSITORY to set this.") |
| 146 | |
| 147 | if category is None: |
| 148 | error("No category found, use env CATEGORY to set this.") |
| 149 | |
| 150 | if category not in CATEGORIES: |
| 151 | error(f"Category {category} is not valid.") |
searching dependent graphs…