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

implement jgit repository resolver #583

Merged
merged 1 commit into from
Sep 27, 2024
Merged

Conversation

laDok8
Copy link
Contributor

@laDok8 laDok8 commented Sep 18, 2024

Introduce xtf.git.repository.url and xtf.git.repository.ref properties intended for pointing to TS repo itself.
This should get auto resolved via jgit, but can be overridden by manually setting properties

closes #574

@simkam
Copy link
Contributor

simkam commented Sep 18, 2024

is the core really correct location? Wouldn't test-helpers module fit better?

@laDok8
Copy link
Contributor Author

laDok8 commented Sep 18, 2024

I'm not sure but all configurable properties (openshift,helm or XTF itself) seem to be in cz.xtf.core.config. Considering current content of test-helpers I don't see that many similarities

@mnovak1
Copy link
Contributor

mnovak1 commented Sep 18, 2024

Looks like maven dependency org.eclipse.jgit is JDK 11 but XTF is based on JDK 8.

@mchoma
Copy link
Contributor

mchoma commented Sep 18, 2024

Can we have run from OS TS showing this dynamic resolver works as expected. That mean without those properties in configuration

# Repo data
xtf.git.repository.url=<URL>
xtf.git.repository.ref=<BRANCH>

return getRepositoryUrl(remoteConfig.getURIs().get(0).getHost(), pathTokens[0], pathTokens[1]);
}

static {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not in favor to have this executed when it's not needed. Can the whole class be written as a singleton. It would be used like:

GitRemoteResolver gitRemoteResolver = GitRemoteResolver.getInstance(); // all initialization happens here
gitRemoteResolver.getRepositoryReference();
gitRemoteResolver.getRepositoryUrl();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code is not always executed, it's executed after loading to memory, which according to my testing happens upon first method call of mentioned class

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, still I think that using Singleton would provide cleaner design.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now the methods in Resolver are private, this would just move code you mentioned into GitRemoteConfig and would result in no public facing API change

Copy link
Contributor

Choose a reason for hiding this comment

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

There would be no public facing change but internal code could use Singleton, Factory, or Strategy pattern to make it more maintanable. However I'm ok to let it be if we don't anticipate more complex use cases.

*/
private static void resolveRepoFromHEAD() throws IOException, URISyntaxException {
//look for a git repository recursively till system root folder
Repository repository = new FileRepositoryBuilder().findGitDir().build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to use findGitDir(File current) instead and make current configurable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO not really, at this point user could specify xtf.git.repository.url which is also more universal than "hardcoding" local path

@laDok8
Copy link
Contributor Author

laDok8 commented Sep 23, 2024

CI run with applied changes

updated CI run with applied changes

@laDok8 laDok8 force-pushed the git_resolver branch 3 times, most recently from e339819 to cabd7f3 Compare September 26, 2024 12:40
Repository repository = new FileRepositoryBuilder().findGitDir().build();

if (repository == null) {
log.debug("Failed to find a git repository");
Copy link
Contributor

Choose a reason for hiding this comment

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

can be these log into error instead of debug.. I would like to see a message if something is wrong. now you have to do extra step to enable debug logging to see what is wrong.

@mnovak1
Copy link
Contributor

mnovak1 commented Sep 27, 2024

After discussion with @laDok8 the functionality is working. If any other changes are required, those will be handled in a follow up PR.

Merging.

@mnovak1 mnovak1 merged commit 708a9a6 into xtf-cz:master Sep 27, 2024
2 checks passed
@laDok8 laDok8 mentioned this pull request Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamically find out git repo of current repo from .git folder
6 participants