-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62ef002
commit 5bce2cd
Showing
6 changed files
with
96 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .ingest import DataIngestor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from gato.caching.cache_manager import CacheManager | ||
from gato.models import Workflow, Repository | ||
|
||
class DataIngestor: | ||
|
||
def __init__(self, queue): | ||
""" | ||
Args: | ||
queue (queue): Queue to use for processing data. | ||
""" | ||
self.queue = queue | ||
|
||
|
||
@staticmethod | ||
def construct_workflow_cache(yml_results): | ||
"""Creates a cache of workflow yml files retrieved from graphQL. Since | ||
graphql and REST do not have parity, we still need to use rest for most | ||
enumeration calls. This method saves off all yml files, so during org | ||
level enumeration if we perform yml enumeration the cached file is used | ||
instead of making github REST requests. | ||
Args: | ||
yml_results (list): List of results from individual GraphQL queries | ||
(100 nodes at a time). | ||
""" | ||
|
||
cache = CacheManager() | ||
for result in yml_results: | ||
# If we get any malformed/missing data just skip it and | ||
# Gato will fall back to the contents API for these few cases. | ||
if not result: | ||
continue | ||
|
||
if 'nameWithOwner' not in result: | ||
continue | ||
|
||
owner = result['nameWithOwner'] | ||
cache.set_empty(owner) | ||
# Empty means no yamls, so just skip. | ||
if not result['object']: | ||
continue | ||
|
||
for yml_node in result['object']['entries']: | ||
yml_name = yml_node['name'] | ||
if yml_name.lower().endswith('yml') or yml_name.lower().endswith('yaml'): | ||
contents = yml_node['object']['text'] | ||
wf_wrapper = Workflow(owner, contents, yml_name) | ||
|
||
cache.set_workflow(owner, yml_name, wf_wrapper) | ||
repo_data = { | ||
'full_name': result['nameWithOwner'], | ||
'html_url': result['url'], | ||
'visibility': 'private' if result['isPrivate'] else 'public', | ||
'default_branch': result['defaultBranchRef']['name'], | ||
'fork': result['isFork'], | ||
'stargazers_count': result['stargazers']['totalCount'], | ||
'pushed_at': result['pushedAt'], | ||
'permissions': { | ||
'pull': result['viewerPermission'] == 'READ' or \ | ||
result['viewerPermission'] == 'TRIAGE' or \ | ||
result['viewerPermission'] == 'WRITE' or \ | ||
result['viewerPermission'] == 'ADMIN', | ||
'push': result['viewerPermission'] == 'WRITE' or \ | ||
result['viewerPermission'] == 'ADMIN', | ||
'admin': result['viewerPermission'] == 'ADMIN' | ||
}, | ||
'archived': result['isArchived'], | ||
'isFork': False | ||
} | ||
|
||
repo_wrapper = Repository(repo_data) | ||
cache.set_repository(repo_wrapper) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters