Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
Change github objects in set to only strings (#67)
Browse files Browse the repository at this point in the history
* Change github objects in set to only strings

* Remove the old self.github_repos references
  • Loading branch information
xtuchyna authored Jan 26, 2021
1 parent bab72ce commit 9cf4de6
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import os

from github import Github
from github.Repository import Repository

from github.GithubException import UnknownObjectException
from thoth.common import OpenShift
Expand All @@ -48,9 +47,10 @@ class Schedule:
def __init__(self, github: Github, organizations: List[str] = None, repositories: List[str] = None):
"""Initialize with github, orgs and repos optional."""
self.gh = github
self.orgs = organizations
self.repos = repositories
self.github_repos: Set[Repository] = set()
self.orgs = organizations if organizations else []
self.repos = repositories if repositories else []

self.checked_repos: Set[str] = set()

self._initialize_repositories_from_organizations()
self._initialize_repositories_from_raw()
Expand All @@ -68,7 +68,7 @@ def _initialize_repositories_from_organizations(self):
if repo.full_name in self.repos:
self.repos.remove(repo.full_name)

self.github_repos.add(repo)
self.checked_repos.add(repo.full_name)

except UnknownObjectException:
_LOGGER.error("organization %s was not recognized by GitHub API", org)
Expand All @@ -83,31 +83,33 @@ def _initialize_repositories_from_raw(self):
_LOGGER.info("repository %s is archived, therefore skipped", repo.full_name)
continue

self.github_repos.add(gh_repo)
self.checked_repos.add(gh_repo.full_name)

except UnknownObjectException:
_LOGGER.error("Repository %s was not recognized by GitHub API", repo)

def schedule_for_mi_analysis(self) -> None:
"""Schedule workflows for mi analysis."""
for repo in self.github_repos:
workflow_id = OpenShift().schedule_mi_workflow(repository=repo.full_name)
for repo in self.checked_repos:
workflow_id = OpenShift().schedule_mi_workflow(repository=repo)
_LOGGER.info("Scheduled mi with id %r", workflow_id)

def schedule_for_kebechet_analysis(self):
"""Schedule workflows for kebechet analysis."""
for repo in self.github_repos:
workflow_id = OpenShift().schedule_mi_workflow(repository=repo.full_name, entities=KEBECHET_ENTITIES)
for repo in self.checked_repos:
workflow_id = OpenShift().schedule_mi_workflow(repository=repo, entities=KEBECHET_ENTITIES)
_LOGGER.info("Scheduled mi-kebechet analysis with id %r", workflow_id)


def main():
"""MI-Scheduler entrypoint."""
gh = Github(login_or_token=GITHUB_ACCESS_TOKEN)

# regular mi schedule
repos, orgs = OpenShift().get_mi_repositories_and_organizations()
Schedule(gh, orgs, repos).schedule_for_mi_analysis()
Schedule(gh, organizations=orgs, repositories=repos).schedule_for_mi_analysis()

# kebechet schedule
graph = GraphDatabase()
graph.connect()
kebechet_repos = graph.get_active_kebechet_github_installations_repos()
Expand Down

0 comments on commit 9cf4de6

Please sign in to comment.