Skip to content

Commit 2333bd3

Browse files
authored
Use new HACS API's (#26)
1 parent 37164eb commit 2333bd3

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ runs:
7373
echo "${{ inputs.ignore }}" > "${{ github.action_path }}/data/ignore"
7474
echo "${{ github.token }}" > "${{ github.action_path }}/data/token"
7575
76-
sudo apt install -y python3-testresources
7776
echo "::endgroup::"
7877
7978
- shell: bash

helpers/action.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
import os
55

66
import aiohttp
7-
from aiogithubapi import GitHub
7+
from aiogithubapi import GitHub, GitHubAPI
88
from homeassistant.core import HomeAssistant
99

10-
from custom_components.hacs.hacsbase.configuration import Configuration
11-
from custom_components.hacs.helpers.classes.exceptions import HacsException
12-
from custom_components.hacs.helpers.functions.logger import getLogger
13-
from custom_components.hacs.helpers.functions.register_repository import (
14-
register_repository,
15-
)
16-
from custom_components.hacs.share import get_hacs
10+
from custom_components.hacs.base import HacsBase
11+
from custom_components.hacs.const import HACS_ACTION_GITHUB_API_HEADERS
12+
from custom_components.hacs.exceptions import HacsException
13+
from custom_components.hacs.utils.logger import getLogger
14+
from custom_components.hacs.validate.manager import ValidationManager
1715

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

113111
async with aiohttp.ClientSession() as session:
114-
github = GitHub(TOKEN, session)
112+
github = GitHub(TOKEN, session, headers=HACS_ACTION_GITHUB_API_HEADERS)
115113
repo = await github.get_repo(repository)
116114
if ref is None and GITHUB_REPOSITORY != "hacs/default":
117115
ref = repo.default_branch
@@ -122,15 +120,29 @@ async def preflight():
122120
async def validate_repository(repository, category, ref=None):
123121
"""Validate."""
124122
async with aiohttp.ClientSession() as session:
125-
hacs = get_hacs()
123+
hacs = HacsBase()
126124
hacs.hass = HomeAssistant()
127125
hacs.session = session
128-
hacs.configuration = Configuration()
129126
hacs.configuration.token = TOKEN
130127
hacs.core.config_path = None
131-
hacs.github = GitHub(hacs.configuration.token, hacs.session)
128+
hacs.validation = ValidationManager(hacs=hacs, hass=hacs.hass)
129+
## Legacy GitHub client
130+
hacs.github = GitHub(
131+
hacs.configuration.token,
132+
session,
133+
headers=HACS_ACTION_GITHUB_API_HEADERS,
134+
)
135+
136+
## New GitHub client
137+
hacs.githubapi = GitHubAPI(
138+
token=hacs.configuration.token,
139+
session=session,
140+
**{"client_name": "HACS/Action"},
141+
)
132142
try:
133-
await register_repository(repository, category, ref=ref)
143+
await hacs.async_register_repository(
144+
repository_full_name=repository, category=category, ref=ref
145+
)
134146
except HacsException as exception:
135147
error(exception)
136148

0 commit comments

Comments
 (0)