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

Try to configure authentication for command from GitWithAuth #884

Merged
merged 4 commits into from
Sep 15, 2023

Conversation

jrhee17
Copy link
Contributor

@jrhee17 jrhee17 commented Sep 14, 2023

Motivation

  • Goes well with the name GitWithAuth which implies that authentication is done from the object implicitly
  • We don't have to pass a Consumer around for each location where we want to execute a git command

@codecov
Copy link

codecov bot commented Sep 14, 2023

Codecov Report

Patch coverage: 97.95% and project coverage change: +0.05% 🎉

Comparison is base (61ecc9b) 65.93% compared to head (1390106) 65.98%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #884      +/-   ##
============================================
+ Coverage     65.93%   65.98%   +0.05%     
- Complexity     3376     3379       +3     
============================================
  Files           360      360              
  Lines         14019    14025       +6     
  Branches       1505     1505              
============================================
+ Hits           9243     9255      +12     
+ Misses         3918     3915       -3     
+ Partials        858      855       -3     
Files Changed Coverage Δ
...ogma/server/internal/mirror/AbstractGitMirror.java 82.67% <96.00%> (-0.15%) ⬇️
...dogma/server/internal/mirror/DefaultGitMirror.java 56.00% <100.00%> (ø)
...ntraldogma/server/internal/mirror/GitWithAuth.java 89.79% <100.00%> (-0.45%) ⬇️
...traldogma/server/internal/mirror/SshGitMirror.java 76.84% <100.00%> (+0.24%) ⬆️

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jrhee17 jrhee17 marked this pull request as ready for review September 14, 2023 03:36
@jrhee17 jrhee17 added this to the 0.62.2 milestone Sep 14, 2023
Copy link
Contributor

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

I thought configuring commands right away was more intuitive but this also looks good. 👍

mirrorRemoteToLocal(git, executor, maxNumFiles, maxNumBytes, sessionFactory::configureCommand);
final SshClient sshClient = createSshClient();
final URIish remoteUri = remoteUri();
final ClientSession session = createSession(sshClient, remoteUri);
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to close the sshClient even if an exception is raised while creating ClientSession.

@@ -228,20 +226,18 @@ dirCache, new InsertText(mirrorStatePath.substring(1), // Strip the leading '/'.
}

final PushCommand push = git.push();
configurator.accept(push);
push.setRefSpecs(new RefSpec(headBranchRefName))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you revert this as well?

git.push().setRefSpecs(...)

Comment on lines -139 to -140
GitWithAuth openGit(File workDir, String jGitUri,
URIish remoteUri) throws IOException, URISyntaxException, GitAPIException {
Copy link
Contributor

Choose a reason for hiding this comment

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

That was my mistake. 😓

final DefaultGitSshdSessionFactory sessionFactory =
new DefaultGitSshdSessionFactory(sshClient, session);
mirrorRemoteToLocal(git, executor, maxNumFiles, maxNumBytes, sessionFactory::configureCommand);
try (GitWithAuth git = openGit(workDir, remoteUri, sessionFactory::configureCommand)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about using the previous style so that we can use only one try with resources block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

openGit has a dependency on sessionFactory. Do you mean initializing the variable as null and closing in the finally block manually?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ha, the parameters of openGit methods are now changed and I forgot about it. 😅
I'm fine with the current approach. 👍

Copy link
Contributor

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning this up! 👍

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks, @jrhee17!

@ikhoon ikhoon merged commit 03540a1 into line:main Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants