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

feat: add command to run repo and commit finder without analysis #827

Open
wants to merge 5 commits into
base: staging
Choose a base branch
from

Conversation

benmss
Copy link
Member

@benmss benmss commented Aug 15, 2024

This pull request adds a new command find-source that requires a PURL, and optionally accepts a repository path as input. If no repository path is provided, the command will call the Repo Finder and Commit Finder to find the repository and commit of the provided PURL. If a repository is provided as input, only the Commit Finder will be called.

Closes #781

…finding and commit finding for a PURL, or commit finding for a PURL and repo

Signed-off-by: Ben Selwyn-Smith <benselwynsmith@googlemail.com>
Signed-off-by: Ben Selwyn-Smith <benselwynsmith@googlemail.com>
Signed-off-by: Ben Selwyn-Smith <benselwynsmith@googlemail.com>
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Aug 15, 2024
Signed-off-by: Ben Selwyn-Smith <benselwynsmith@googlemail.com>
@benmss benmss marked this pull request as ready for review August 15, 2024 05:27

analyzer = Analyzer(global_config.output_path, global_config.build_log_path)
repo_dir = os.path.join(analyzer.output_path, analyzer.GIT_REPOS_DIR)
git_obj = analyzer.prepare_repo(repo_dir, found_repo, "", "", purl)
Copy link
Member

@tromai tromai Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking again at the implementation of this prepare_repo function, it only uses self at a few locations to run static methods:

Do you think it would be worth while to refactor this method to another module to avoid having to silent the pylint cyclic-import error?

@tromai
Copy link
Member

tromai commented Aug 16, 2024

I tried to run the find-source command against a Maven PURL that doesn't have a version:

$ macaron find-source -purl pkg:maven/org.apache.maven/maven
2024-08-16 11:16:55,421 [INFO] Setting the output directory to .../output
2024-08-16 11:16:55,422 [INFO] The logs will be stored in debug.log
2024-08-16 11:16:55,424 [ERROR] Could not find repo for PURL: pkg:maven/apache/maven

I believe we don't support Maven PURL without a version now -

if not version:
logger.debug("Version missing for maven artifact: %s:%s", group, artifact)
# TODO add support for Java artifacts without a version
return ""

However, the debug message doesn't show up if I ran it without the verbose flag. I believe we should let the user of the find-source command know about this behavior by default.

@tromai
Copy link
Member

tromai commented Aug 16, 2024

I also think it's great to add an integration test case for the new command too (may be we can revisit this after we settle on how to return the results to the user).

Signed-off-by: Ben Selwyn-Smith <benselwynsmith@googlemail.com>
@@ -218,3 +213,158 @@ def find_source(purl_string: str, repo: str | None) -> bool:
logger.info("%s/commit/%s", found_repo, digest)

return True


def prepare_repo(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the refactoring. However, I think prepare_repo, get_git_service and get_local_repos_path can be moved to a new package within src/macaron/ (for example, prepare_repo is used both within analyzer.py and repo_finder.py).
We could name this new package something like "repo_utils" or something like that 🤔
@behnazh-w I would love to know what you think about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants