Skip to content

Commit

Permalink
Switch to SSH transport
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesbusy committed Dec 17, 2024
1 parent d420063 commit b14006e
Show file tree
Hide file tree
Showing 20 changed files with 712 additions and 118 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ target/
!**/src/main/**/target/
!**/src/test/**/target/

### Plugins Directory ###
test-plugins

### Log file ###
logs/

### IntelliJ IDEA ###
.idea/
!.idea/runConfigurations/
!.idea/.gitignore/
*.iws
*.iml
*.ipr
Expand All @@ -34,6 +33,8 @@ build/
!**/src/main/**/build/
!**/src/test/**/build/

!**/test/resources/**/.git

### VS Code ###
.vscode/

Expand Down
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.jenkins.tools.pluginmodernizer.core.config.Config;
import io.jenkins.tools.pluginmodernizer.core.config.Settings;
import io.jenkins.tools.pluginmodernizer.core.impl.PluginModernizer;
import io.jenkins.tools.pluginmodernizer.core.model.ModernizerException;
import java.nio.file.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;
Expand All @@ -27,6 +29,14 @@ public class BuildMetadataCommand implements ICommand {
@CommandLine.ArgGroup(exclusive = true, multiplicity = "1")
private PluginOptions pluginOptions;

/**
* Path to the authentication key in case of private repo
*/
@CommandLine.Option(
names = {"--ssh-private-key"},
description = "Path to the authentication key for GitHub. Default to ~/.ssh/id_rsa")
private Path sshPrivateKey = Settings.SSH_PRIVATE_KEY;

/**
* Global options for all commands
*/
Expand All @@ -44,12 +54,21 @@ public Config setup(Config.Builder builder) {
options.config(builder);
envOptions.config(builder);
pluginOptions.config(builder);
return builder.withRecipe(Settings.FETCH_METADATA_RECIPE).build();
return builder.withSshPrivateKey(sshPrivateKey)
.withRecipe(Settings.FETCH_METADATA_RECIPE)
.build();
}

@Override
public Integer call() throws Exception {
public Integer call() {
PluginModernizer modernizer = getModernizer();
try {
modernizer.validate();
} catch (ModernizerException e) {
LOG.error("Validation error");
LOG.error(e.getMessage());
return 1;
}
modernizer.start();
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.jenkins.tools.pluginmodernizer.core.config.Config;
import io.jenkins.tools.pluginmodernizer.core.impl.PluginModernizer;
import io.jenkins.tools.pluginmodernizer.core.model.ModernizerException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;
Expand Down Expand Up @@ -53,6 +55,11 @@ public Integer call() throws Exception {
try {
modernizer.validate();
LOG.info("GitHub owner: {}", modernizer.getGithubOwner());
if (Files.isRegularFile(Path.of(modernizer.getSshPrivateKeyPath()))) {
LOG.info("SSH key path: {}", modernizer.getSshPrivateKeyPath());
} else {
LOG.info("SSH key not set. Will use GitHub token for Git operation");
}
LOG.info("Maven home: {}", modernizer.getMavenHome());
LOG.info("Maven version: {}", modernizer.getMavenVersion());
LOG.info("Java version: {}", modernizer.getJavaVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.jenkins.tools.pluginmodernizer.core.config.Config;
import io.jenkins.tools.pluginmodernizer.core.config.Settings;
import java.nio.file.Path;
import picocli.CommandLine;

/**
Expand All @@ -15,6 +16,14 @@
commandListHeading = "%nCommands:%n")
public class GitHubOptions implements IOption {

/**
* Path to the authentication key
*/
@CommandLine.Option(
names = {"--ssh-private-key"},
description = "Path to the authentication key for GitHub. Default to ~/.ssh/id_rsa")
private Path sshPrivateKey = Settings.SSH_PRIVATE_KEY;

@CommandLine.Option(
names = {"-g", "--github-owner"},
description = "GitHub owner for forked repositories.")
Expand Down Expand Up @@ -46,6 +55,7 @@ public void config(Config.Builder builder) {
builder.withGitHubOwner(githubOwner)
.withGitHubAppId(githubAppId)
.withGitHubAppSourceInstallationId(githubAppSourceInstallationId)
.withGitHubAppTargetInstallationId(githubAppTargetInstallationId);
.withGitHubAppTargetInstallationId(githubAppTargetInstallationId)
.withSshPrivateKey(sshPrivateKey);
}
}
2 changes: 2 additions & 0 deletions plugin-modernizer-cli/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
<logger name="java.lang.Runtime" level="WARN" />
<logger name="org.apache.mina.core" level="WARN" />
<logger name="org.apache.sshd.client" level="WARN" />
<logger name="org.apache.sshd.client.keyverifier" level="ERROR" />
<logger name="org.apache.sshd.common" level="WARN" />
<logger name="org.apache.sshd.git.transport" level="WARN" />
<logger name="org.eclipse.jgit.internal" level="WARN" />
<logger name="org.eclipse.jgit.transport" level="INFO" />
<logger name="org.eclipse.jgit.util" level="INFO" />
Expand Down
Loading

0 comments on commit b14006e

Please sign in to comment.