mirror of
https://github.com/esphome/esphome.git
synced 2025-09-12 00:02:21 +01:00
Allow dashboard import to pull complete file from github (#3982)
This commit is contained in:
@@ -1,23 +1,22 @@
|
||||
import re
|
||||
from pathlib import Path
|
||||
from esphome.core import EsphomeError
|
||||
from esphome.config_helpers import merge_config
|
||||
|
||||
import esphome.config_validation as cv
|
||||
from esphome import git, yaml_util
|
||||
from esphome.config_helpers import merge_config
|
||||
from esphome.const import (
|
||||
CONF_ESPHOME,
|
||||
CONF_FILE,
|
||||
CONF_FILES,
|
||||
CONF_MIN_VERSION,
|
||||
CONF_PACKAGES,
|
||||
CONF_PASSWORD,
|
||||
CONF_REF,
|
||||
CONF_REFRESH,
|
||||
CONF_URL,
|
||||
CONF_USERNAME,
|
||||
CONF_PASSWORD,
|
||||
__version__ as ESPHOME_VERSION,
|
||||
)
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import __version__ as ESPHOME_VERSION
|
||||
from esphome.core import EsphomeError
|
||||
|
||||
DOMAIN = CONF_PACKAGES
|
||||
|
||||
@@ -55,23 +54,15 @@ def validate_source_shorthand(value):
|
||||
if not isinstance(value, str):
|
||||
raise cv.Invalid("Shorthand only for strings")
|
||||
|
||||
m = re.match(
|
||||
r"github://([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-\._]+)/([a-zA-Z0-9\-_.\./]+)(?:@([a-zA-Z0-9\-_.\./]+))?",
|
||||
value,
|
||||
)
|
||||
if m is None:
|
||||
raise cv.Invalid(
|
||||
"Source is not a file system path or in expected github://username/name/[sub-folder/]file-path.yml[@branch-or-tag] format!"
|
||||
)
|
||||
git_file = git.GitFile.from_shorthand(value)
|
||||
|
||||
conf = {
|
||||
CONF_URL: f"https://github.com/{m.group(1)}/{m.group(2)}.git",
|
||||
CONF_FILE: m.group(3),
|
||||
CONF_URL: git_file.git_url,
|
||||
CONF_FILE: git_file.filename,
|
||||
}
|
||||
if m.group(4):
|
||||
conf[CONF_REF] = m.group(4)
|
||||
if git_file.ref:
|
||||
conf[CONF_REF] = git_file.ref
|
||||
|
||||
# print(conf)
|
||||
return BASE_SCHEMA(conf)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user