diff --git a/.gitignore b/.gitignore index 763c1fe..2f25cb6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ config.yaml .env __pycache__ *.egg-info/ -build/ \ No newline at end of file +build/ +*.ignore.* \ No newline at end of file diff --git a/src/docker_publisher_osparc_services/http_interface.py b/src/docker_publisher_osparc_services/http_interface.py index b508bbf..d92eeb8 100644 --- a/src/docker_publisher_osparc_services/http_interface.py +++ b/src/docker_publisher_osparc_services/http_interface.py @@ -20,11 +20,12 @@ async def github_did_last_repo_run_pass( async with async_client() as client: repo_path = repo_model.repo.split("github.com/")[1].replace(".git", "") url = f"https://api.github.com/repos/{repo_path}/actions/runs" + headers = {"Authorization": f"Bearer {repo_model.github.gitlab_token}"} params = {"per_page": "10"} associated_run: Optional[Dict[str, Any]] = None while url: - result = await client.get(url, params=params) + result = await client.get(url, params=params, headers=headers) runs = result.json() for run in runs["workflow_runs"]: diff --git a/src/docker_publisher_osparc_services/models.py b/src/docker_publisher_osparc_services/models.py index fcd6468..bffbdf1 100644 --- a/src/docker_publisher_osparc_services/models.py +++ b/src/docker_publisher_osparc_services/models.py @@ -3,7 +3,7 @@ from typing import Dict, List, Optional from envyaml import EnvYAML -from pydantic import BaseModel, Field, SecretStr, root_validator +from pydantic import BaseModel, Field, SecretStr, root_validator, validator class HostType(str, Enum): @@ -71,13 +71,13 @@ class GitLabModel(BaseModel): deploy_token_password: SecretStr +class GitHubModel(BaseModel): + gitlab_token: str + + class RepoModel(BaseModel): address: str = Field(..., description="clone address https") - gitlab: Optional[GitLabModel] = Field( - None, description="GitLab credentials to clone and access the v4 API" - ) branch: str - host_type: HostType registry: RegistryTargetModel clone_path: Optional[Path] = Field( None, description="Used internally to specify directory where to clone" @@ -95,13 +95,24 @@ class RepoModel(BaseModel): description="a list of commands to execute before running the docker build command", ) + host_type: HostType + gitlab: Optional[GitLabModel] = Field( + None, description="GitLab credentials to clone and access the v4 API" + ) + github: Optional[GitHubModel] = None + @classmethod @root_validator() - def require_access_token_for_gitlab(cls, values): + def require_access_token(cls, values): if values["host_type"] == HostType.GITLAB and values["gitlab"] is None: raise ValueError( f"Provide a valid 'gitlab' field for {HostType.GITLAB} repo" ) + if values["host_type"] == HostType.GITHUB and values["github"] is None: + raise ValueError( + f"Provide a valid 'gitlab' field for {HostType.GITHUB} repo" + ) + return values def _format_repo(