Skip to content

Commit

Permalink
Use new HACS API's (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Dec 26, 2021
1 parent 37164eb commit 2333bd3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
1 change: 0 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ runs:
echo "${{ inputs.ignore }}" > "${{ github.action_path }}/data/ignore"
echo "${{ github.token }}" > "${{ github.action_path }}/data/token"
sudo apt install -y python3-testresources
echo "::endgroup::"
- shell: bash
Expand Down
38 changes: 25 additions & 13 deletions helpers/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
import os

import aiohttp
from aiogithubapi import GitHub
from aiogithubapi import GitHub, GitHubAPI
from homeassistant.core import HomeAssistant

from custom_components.hacs.hacsbase.configuration import Configuration
from custom_components.hacs.helpers.classes.exceptions import HacsException
from custom_components.hacs.helpers.functions.logger import getLogger
from custom_components.hacs.helpers.functions.register_repository import (
register_repository,
)
from custom_components.hacs.share import get_hacs
from custom_components.hacs.base import HacsBase
from custom_components.hacs.const import HACS_ACTION_GITHUB_API_HEADERS
from custom_components.hacs.exceptions import HacsException
from custom_components.hacs.utils.logger import getLogger
from custom_components.hacs.validate.manager import ValidationManager

TOKEN = os.getenv("INPUT_GITHUB_TOKEN")
GITHUB_WORKSPACE = os.getenv("GITHUB_WORKSPACE")
Expand Down Expand Up @@ -111,7 +109,7 @@ async def preflight():
error("No category found, use env CATEGORY to set this.")

async with aiohttp.ClientSession() as session:
github = GitHub(TOKEN, session)
github = GitHub(TOKEN, session, headers=HACS_ACTION_GITHUB_API_HEADERS)
repo = await github.get_repo(repository)
if ref is None and GITHUB_REPOSITORY != "hacs/default":
ref = repo.default_branch
Expand All @@ -122,15 +120,29 @@ async def preflight():
async def validate_repository(repository, category, ref=None):
"""Validate."""
async with aiohttp.ClientSession() as session:
hacs = get_hacs()
hacs = HacsBase()
hacs.hass = HomeAssistant()
hacs.session = session
hacs.configuration = Configuration()
hacs.configuration.token = TOKEN
hacs.core.config_path = None
hacs.github = GitHub(hacs.configuration.token, hacs.session)
hacs.validation = ValidationManager(hacs=hacs, hass=hacs.hass)
## Legacy GitHub client
hacs.github = GitHub(
hacs.configuration.token,
session,
headers=HACS_ACTION_GITHUB_API_HEADERS,
)

## New GitHub client
hacs.githubapi = GitHubAPI(
token=hacs.configuration.token,
session=session,
**{"client_name": "HACS/Action"},
)
try:
await register_repository(repository, category, ref=ref)
await hacs.async_register_repository(
repository_full_name=repository, category=category, ref=ref
)
except HacsException as exception:
error(exception)

Expand Down

0 comments on commit 2333bd3

Please sign in to comment.