Repository Apply
Batch apply: apply every manifest of a public GitHub repository from the web console’s Apply page.
A user gives the Apply page a repository’s url, e.g. https://github.com/smarter-sh/example-manifests.
start_repository_apply() records the run, a RepositoryApply,
and queues the Celery task smarter.apps.account.tasks.apply_repository(), which runs
run_repository_apply(): it clones the repository, records each manifest that it finds, pending, and
applies them one by one, recording each one’s result. The page polls the run, and shows each manifest’s
state, and for a manifest that failed, why, what applying it printed, and its file on GitHub.
The manifests are found, ordered and applied by manage.py load_from_github’s own code: the
RepositoryLoader here is its command, with only what a web user may do. Everything is applied
as the user, in their account, through the same brokers and permission checks as the Apply page’s
single manifest, and:
only a public repository on GitHub, by its
https://github.com/<owner>/<repo>url, is cloned, with a time limit, and never with credentials;the repository’s
scripts/never run: they run as the database server’s administrator;a folder that the repository’s
owners.yamlgives an owner is skipped: it is applied only by the platform, as its owner;no LLMClient is deployed, and one that exists keeps its
deployedvalue;a manifest that names a resource that doesn’t exist, e.g. a Secret, fails, with the broker’s message.
A user may run one at a time, and REPOSITORY_APPLIES_PER_DAY a day.
- smarter.apps.account.repository_apply.MAX_MANIFESTS = 300
The most manifests that a batch apply applies.
A repository with more fails, before applying any.
- smarter.apps.account.repository_apply.REPOSITORY_APPLIES_PER_DAY = 20
The most batch applies that a user may start in 24 hours.
- class smarter.apps.account.repository_apply.RepositoryApplyListResponse(**data)[source]
Bases:
RepositoryApplyApiModelThe user’s recent batch applies, the newest first, without their manifests.
- model_config = {'alias_generator': <function to_camel>, 'extra': 'forbid', 'serialize_by_alias': True, 'validate_by_alias': True, 'validate_by_name': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- runs: list[RepositoryApplyResponse]
- class smarter.apps.account.repository_apply.RepositoryApplyManifestResponse(**data)[source]
Bases:
RepositoryApplyApiModelOne manifest of a batch apply, and what became of it.
- classmethod from_model(row, url, commit)[source]
Return a manifest’s response.
- Parameters:
row (
RepositoryApplyManifest) – The manifest.url (
str) – The repository’s url.commit (
str) – The commit that was cloned, or an empty string.
- Return type:
- Returns:
The response.
- model_config = {'alias_generator': <function to_camel>, 'extra': 'forbid', 'serialize_by_alias': True, 'validate_by_alias': True, 'validate_by_name': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- exception smarter.apps.account.repository_apply.RepositoryApplyRefused[source]
Bases:
ExceptionThe user may not start a batch apply now, or the url isn’t a public GitHub repository’s.
- class smarter.apps.account.repository_apply.RepositoryApplyResponse(**data)[source]
Bases:
RepositoryApplyApiModelA batch apply’s progress, as the Apply page reads it.
- classmethod from_model(run, with_manifests=True)[source]
Return a run’s progress.
- Parameters:
run (
RepositoryApply) – The run.with_manifests (
bool) – Include each manifest, or only the counts.
- Return type:
- Returns:
The response.
- manifests: list[RepositoryApplyManifestResponse]
- model_config = {'alias_generator': <function to_camel>, 'extra': 'forbid', 'serialize_by_alias': True, 'validate_by_alias': True, 'validate_by_name': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.account.repository_apply.RepositoryLoader(url, user_profile)[source]
Bases:
Commandmanage.py load_from_github, as a web user may run it: see the module’s docstring.It finds, orders and applies the manifests with the command’s own methods, and records each one’s result in a
RepositoryApplyManifest, rather than writing it to the console.- apply(filespec, user_profile, manifest=None)[source]
Apply one manifest, with the command’s
apply(), and remember whether it was.
- apply_one(item)[source]
Apply one manifest as the user, with the command’s
apply_manifest, and say what became of it.- Parameters:
item (
RepositoryManifest) – The manifest.- Returns:
Its status, why it failed or was skipped, and what applying it printed.
- Return type:
- capture()[source]
Send what the command writes to a new buffer, and return the buffer.
- Returns:
The buffer.
- Return type:
- clone_repo(local_path)[source]
Clone the repository’s default branch, without its history, within
CLONE_TIMEOUT_SECONDS.git never asks for credentials: a private or missing repository fails at once.
- skipped_for_owner(item)[source]
Return why a manifest of a folder that
owners.yamlgives an owner is skipped, or None.- Parameters:
item (
RepositoryManifest) – The manifest.- Returns:
The reason, or None if it isn’t in such a folder.
- Return type:
- smarter.apps.account.repository_apply.normalize_repository_url(url)[source]
Return a GitHub repository’s url, as it is cloned and recorded.
- Parameters:
url (
str) – The url that the user gave, e.g.https://github.com/smarter-sh/stackademy.git.- Returns:
e.g.
https://github.com/smarter-sh/stackademy.- Return type:
- Raises:
RepositoryApplyRefused – If it isn’t the url of a repository on GitHub.
- smarter.apps.account.repository_apply.recent_runs(user_profile, limit=10)[source]
Return the user’s recent batch applies.
- Parameters:
user_profile (
UserProfile) – The user.limit (
int) – How many, at most.
- Return type:
- Returns:
The runs, the newest first, without their manifests.
- smarter.apps.account.repository_apply.run_repository_apply(run_id)[source]
Run a batch apply: clone, discover, then apply each manifest, recording each step in the rows.
A failure of the run as a whole, e.g. a repository that can’t be cloned, is recorded in the run, with what went wrong, rather than raised, so that the Celery task isn’t retried: the user can start another.
- Parameters:
run_id (
int) – The run’s id.- Return type:
- Returns:
The run.
- Raises:
RepositoryApply.DoesNotExist – If there is no such run.
- smarter.apps.account.repository_apply.start_repository_apply(user_profile, url)[source]
Start a batch apply of a repository, unless one of the user’s is in progress.
The Celery task is queued once the run’s row is committed, so that the worker finds it.
- Parameters:
user_profile (
UserProfile) – The user, as whom the manifests are applied.url (
str) – The repository’s url.
- Return type:
- Returns:
The run, and True if it was started now, or False if one was already in progress.
- Raises:
RepositoryApplyRefused – If the url isn’t a public GitHub repository’s, or the user started
REPOSITORY_APPLIES_PER_DAYruns in the last 24 hours.