Skip to content

Commit

Permalink
Add 'allow' and 'disallow' setting to each manager
Browse files Browse the repository at this point in the history
Signed-off-by: Shreekara <sshreeka@redhat.com>
  • Loading branch information
shreekarSS committed Oct 12, 2022
1 parent 356af8e commit 77d466e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 36 deletions.
86 changes: 50 additions & 36 deletions kebechet/managers/thoth_advise/thoth_advise.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,46 +316,60 @@ def run(self, labels: list, analysis_id=None):
runtime_environments = [
e["name"] for e in thoth_config["runtime_environments"]
]
managers = thoth_config.get("managers")
for mgr in managers:
if mgr.get('name') == 'thoth-advise':
disallow_run_times = mgr.get("disallow", None)
allowed_run_times = mgr.get("allow", None)
if disallow_run_times:
runtime_environments = list(
set(runtime_environments) - set(disallow_run_times)
)
if allowed_run_times:
runtime_environments = allowed_run_times
else:
runtime_environments = [
thoth_config["runtime_environments"][0]["name"]
]
for e in runtime_environments:
try:
analysis_id = lib.advise_here(
nowait=True,
origin=(f"{self.service_url}/{self.slug}"),
source_type=ThothAdviserIntegrationEnum.KEBECHET,
kebechet_metadata=self.metadata,
runtime_environment_name=e,
)
self._tracking_issue.comment(
STARTED_ADVISE_COMMENT.format(
analysis_id=analysis_id,
env=e,
host=thoth_config["host"],
)
)
except (FileLoadError, ThothConfigurationError) as exc:
if isinstance(exc, FileLoadError):
self._tracking_issue.comment(
f"""Result for {e}: Error advising, no requirements found.
If this project does not use requirements.txt or Pipfile then remove thoth-advise
manager from your .thoth.yaml configuration."""
)
elif isinstance(exc, ThothConfigurationError):
self._tracking_issue.comment(
f"""Result for {e}: Error advising, configuration error found in .thoth.yaml. The
following exception was caught when submitting:
```
{exc}
```"""
)
# open issue
# comment on advise issue with issue id
return False
logging.info(disallow_run_times)
logging.info(allowed_run_times)
logging.info(runtime_environments)
# for e in runtime_environments:
# try:
# analysis_id = lib.advise_here(
# nowait=True,
# origin=(f"{self.service_url}/{self.slug}"),
# source_type=ThothAdviserIntegrationEnum.KEBECHET,
# kebechet_metadata=self.metadata,
# runtime_environment_name=e,
# )
# self._tracking_issue.comment(
# STARTED_ADVISE_COMMENT.format(
# analysis_id=analysis_id,
# env=e,
# host=thoth_config["host"],
# )
# )
# except (FileLoadError, ThothConfigurationError) as exc:
# if isinstance(exc, FileLoadError):
# self._tracking_issue.comment(
# f"""Result for {e}: Error advising, no requirements found.
#
# If this project does not use requirements.txt or Pipfile then remove thoth-advise
# manager from your .thoth.yaml configuration."""
# )
# elif isinstance(exc, ThothConfigurationError):
# self._tracking_issue.comment(
# f"""Result for {e}: Error advising, configuration error found in .thoth.yaml. The
# following exception was caught when submitting:
#
# ```
# {exc}
# ```"""
# )
# # open issue
# # comment on advise issue with issue id
# return False
return True
else:
with cloned_repo(self, self.project.default_branch, depth=1) as repo:
Expand Down
11 changes: 11 additions & 0 deletions kebechet/managers/update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,17 @@ def run(self, labels: list = []) -> Optional[dict]:
else:
runtime_environments = [None]

managers = thoth_config.content.get("managers")
for mgr in managers:
if mgr.get('name') == 'update':
disallow_run_times = mgr.get("disallow", None)
allowed_run_times = mgr.get("allow", None)
if disallow_run_times:
runtime_environments = list(
set(runtime_environments) - set(disallow_run_times)
)
if allowed_run_times:
runtime_environments = allowed_run_times
results: dict = {}
for e in runtime_environments:
self.runtime_environment = e or "default"
Expand Down

0 comments on commit 77d466e

Please sign in to comment.