-
Notifications
You must be signed in to change notification settings - Fork 14
Implementation of the find repo functionality #56
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
Changes from 2 commits
d3710a9
13d9a36
455f3db
9082c8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,7 +174,6 @@ def is_curdir_inside_path(base_path): | |
| self.local_repo = (meta['alias'], meta['uid']) | ||
| # Create a Repo object and add it to the list | ||
| repos_list.append(Repo(path=repo_path, meta=meta)) | ||
|
|
||
| return repos_list | ||
|
|
||
| def load_repos(self): | ||
|
|
@@ -947,20 +946,82 @@ def __init__(self, parent=None): | |
| self.__dict__.update(vars(parent)) | ||
|
|
||
| def find(self, run_args): | ||
| repo = run_args.get('item', run_args.get('artifact')) | ||
| repo_split = repo.split(",") | ||
| if len(repo_split) > 1: | ||
| repo_uid = repo_split[1] | ||
| repo_name = repo_split[0] | ||
|
|
||
| lst = [] | ||
| for i in self.repos: | ||
| if repo_uid and i.meta['uid'] == repo_uid: | ||
| lst.append(i) | ||
| elif repo_name == i.meta['alias']: | ||
| lst.append(i) | ||
|
|
||
| return {'return': 0, 'list': lst} | ||
| try: | ||
| # Get repos_list using the existing method | ||
| repos_list = self.load_repos_and_meta() | ||
| if(run_args.get('item', run_args.get('artifact'))): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need an if condition here since |
||
| repo = run_args.get('item', run_args.get('artifact')) | ||
| else: | ||
| repo = run_args.get('repo', run_args.get('item', run_args.get('artifact'))) | ||
|
|
||
| # Check if repo is None or empty | ||
| if not repo: | ||
| raise ValueError( | ||
| "Please enter a Repo Alias, Repo UID, or Repo URL in one of the following formats:\n" | ||
| "- <repo_owner>@<repos_name>\n" | ||
| "- <repo_url>\n" | ||
| "- <repo_uid>\n" | ||
| "- <repo_alias>\n" | ||
| "- <repo_alias>,<repo_uid>" | ||
| ) | ||
|
|
||
| # Handle the different repo input formats | ||
| repo_name = None | ||
| repo_uid = None | ||
|
|
||
| # Check if the repo is in the format of a repo UID (alphanumeric string) | ||
| if repo.isalnum(): # Assuming repo_uid is alphanumeric | ||
Sid9993 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| repo_uid = repo | ||
| if "," in repo: | ||
| repo_split = repo.split(",") | ||
| repo_name = repo_split[0] | ||
| if len(repo_split) > 1: | ||
| repo_uid = repo_split[1] | ||
| elif "@" in repo: | ||
| repo_name = repo | ||
| elif re.match(r"(?:https?://)?(?:www\.)?github\.com/([^/]+)/([^/.]+)(?:\.git)?", repo): | ||
Sid9993 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Convert GitHub URL to user@repo_name format if necessary | ||
| pattern = r"(?:https?://)?(?:www\.)?github\.com/([^/]+)/([^/.]+)(?:\.git)?" | ||
| match = re.match(pattern, repo) | ||
| if match: | ||
| user, repo_name = match.groups() | ||
| repo_name = f"{user}@{repo_name}" | ||
| else: | ||
| raise ValueError(f"Invalid GitHub URL format for: {repo}") | ||
Sid9993 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| else: | ||
| # If URL is malformed, handle it separately | ||
| if "github.com" in repo and not re.match(r"(https?://)?(?:www\.)?github\.com/([^/]+)/([^/.]+)(?:\.git)?", repo): | ||
| raise ValueError(f"Invalid GitHub URL format for: {repo}") | ||
|
|
||
| # Check if repo_name exists in repos.json | ||
| matched_repo_path = None | ||
| for repo_obj in repos_list: | ||
| if repo_name and repo_name == os.path.basename(repo_obj.path) : | ||
| matched_repo_path = repo_obj.path | ||
| break | ||
|
|
||
| # Search through self.repos for matching repos | ||
| lst = [] | ||
| for i in self.repos: | ||
| if repo_uid and i.meta['uid'] == repo_uid: | ||
| lst.append(i) | ||
| elif repo_name == i.meta['alias']: | ||
| lst.append(i) | ||
| elif repo.isalnum() and not any(i.meta['uid'] == repo_uid for i in self.repos): | ||
Sid9993 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| raise ValueError(f"No repository with UID: '{repo_uid}' was found") | ||
| elif not matched_repo_path and not any(i.meta['alias'] == repo_name for i in self.repos) and not any(i.meta['uid'] == repo_uid for i in self.repos ): | ||
| raise ValueError(f"No repository with alias: '{repo_name}' was found") | ||
| elif "," in repo and not matched_repo_path and not any(i.meta['uid'] == repo_uid for i in self.repos) and not any(i.meta['alias'] == repo_name for i in self.repos): | ||
| raise ValueError(f"No repository with alias: '{repo_name}' and UID: '{repo_uid}' was found") | ||
|
|
||
|
|
||
| # Append the matched repo path | ||
| lst.append(matched_repo_path) | ||
|
|
||
| return {'return': 0, 'list': lst} | ||
| except Exception as e: | ||
| # Return error message if any exception occurs | ||
| return {"return": 1, "error": str(e)} | ||
|
|
||
| def github_url_to_user_repo_format(self, url): | ||
| """ | ||
|
|
@@ -1360,11 +1421,22 @@ def mlcr(): | |
|
|
||
| def process_console_output(res, target, action, run_args): | ||
| if action == "find": | ||
| if "list" not in res: | ||
| return # Exit function if there's an error | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check for key
|
||
| if len(res['list']) == 0: | ||
| logger.warn(f"""No {target} entry found for the specified tags: {run_args['tags']}!""") | ||
| else: | ||
| for item in res['list']: | ||
| logger.info(f"""Item path: {item.path}""") | ||
| seen_paths = set() # To avoid duplicate logging | ||
| for item in res["list"]: | ||
| if isinstance(item, str): # If item is a string (repo path) | ||
Sid9993 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if item not in seen_paths: | ||
| logger.info(f"""Item path: {item}""") | ||
| seen_paths.add(item) | ||
|
|
||
| elif hasattr(item, "path"): # If item has `.path` attribute | ||
| if item.path not in seen_paths: | ||
| logger.info(f"""Item path: {item.path}""") | ||
| seen_paths.add(item.path) | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -1419,7 +1491,7 @@ def main(): | |
| run_args['repo'] = args.repo | ||
|
|
||
|
|
||
| if args.command in ['rm']: | ||
| if args.command in ['rm','find']: | ||
| if args.target == "repo": | ||
| run_args['repo'] = args.details | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't the
load_repos_and_metabe automatically called when initialising theActionclass while runningmlc? I think it could be accessed throughself.repos_list.