Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill the repo_type column in the repos table #2304

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions augur/application/db/models/augur_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ def is_valid_github_repo(gh_session, url: str) -> bool:

return False, {"status": f"Github Error: {data['message']}"}

return True, {"status": "Valid repo"}
return True, {"status": "Valid repo", "repo_type": data["owner"]["type"]}

@staticmethod
def parse_github_repo_url(url: str) -> tuple:
Expand Down Expand Up @@ -964,7 +964,7 @@ def parse_github_org_url(url):
return result.groups()[0]

@staticmethod
def insert(session, url: str, repo_group_id: int, tool_source):
def insert(session, url: str, repo_group_id: int, tool_source, repo_type):
"""Add a repo to the repo table.

Args:
Expand All @@ -976,6 +976,8 @@ def insert(session, url: str, repo_group_id: int, tool_source):
"""

if not isinstance(url, str) or not isinstance(repo_group_id, int) or not isinstance(tool_source, str):

if not isinstance(url, str) or not isinstance(repo_group_id, int) or not isinstance(tool_source, str) or not isinstance(repo_type, str):
return None

if not RepoGroup.is_valid_repo_group_id(session, repo_group_id):
Expand All @@ -992,6 +994,7 @@ def insert(session, url: str, repo_group_id: int, tool_source):
"repo_git": url,
"repo_path": f"github.com/{owner}/",
"repo_name": repo,
"repo_type": repo_type,
"tool_source": tool_source,
"tool_version": "1.0",
"data_source": "Git"
Expand Down
18 changes: 12 additions & 6 deletions augur/application/db/models/augur_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def retrieve_org_repos(session, url: str) -> List[str]:

repo_urls = [repo["html_url"] for repo in repos]

return repo_urls, {"status": "Invalid owner url"}
return repo_urls, {"status": "success", "owner_type": "Organization"}


metadata = Base.metadata
Expand Down Expand Up @@ -697,7 +697,7 @@ def insert(session, repo_id: int, group_id:int = 1) -> bool:
return data[0]["group_id"] == group_id and data[0]["repo_id"] == repo_id

@staticmethod
def add(session, url: List[str], user_id: int, group_name=None, group_id=None, valid_repo=False, repo_group_id=None) -> dict:
def add(session, url: List[str], user_id: int, group_name=None, group_id=None, from_org_list=False, repo_type=None, repo_group_id=None) -> dict:
"""Add repo to the user repo table

Args:
Expand All @@ -719,18 +719,23 @@ def add(session, url: List[str], user_id: int, group_name=None, group_id=None, v

if not group_name and not group_id:
return False, {"status": "Need group name or group id to add a repo"}

if from_org_list and not repo_type:
return False, {"status": "Repo type must be passed if the repo is from an organization's list of repos"}

if group_id is None:

group_id = UserGroup.convert_group_name_to_id(session, user_id, group_name)
if group_id is None:
return False, {"status": "Invalid group name"}

if not valid_repo:
if not from_org_list:
result = Repo.is_valid_github_repo(session, url)
if not result[0]:
return False, {"status": result[1]["status"], "repo_url": url}

repo_type = result[1]["repo_type"]

# if no repo_group_id is passed then assign the repo to the frontend repo group
if repo_group_id is None:

Expand All @@ -741,7 +746,7 @@ def add(session, url: List[str], user_id: int, group_name=None, group_id=None, v
repo_group_id = frontend_repo_group.repo_group_id


repo_id = Repo.insert(session, url, repo_group_id, "Frontend")
repo_id = Repo.insert(session, url, repo_group_id, "Frontend", repo_type)
if not repo_id:
return False, {"status": "Repo insertion failed", "repo_url": url}

Expand Down Expand Up @@ -798,6 +803,7 @@ def add_org_repos(session, url: List[str], user_id: int, group_name: int):
if not result[0]:
return False, result[1]
repos = result[0]
type = result[1]["owner_type"]


# parse github org url to get org name
Expand Down Expand Up @@ -828,7 +834,7 @@ def add_org_repos(session, url: List[str], user_id: int, group_name: int):
failed_repos = []
for repo in repos:

result = UserRepo.add(session, repo, user_id, group_id=group_id, valid_repo=True, repo_group_id=repo_group_id)
result = UserRepo.add(session, repo, user_id, group_id=group_id, from_org_list=True, repo_type=type, repo_group_id=repo_group_id)

# keep track of all the repos that failed
if not result[0]:
Expand Down