Skip to content

Commit a503a05

Browse files
committed
Switch to SSH transport
1 parent d420063 commit a503a05

File tree

18 files changed

+682
-108
lines changed

18 files changed

+682
-108
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ target/
33
!**/src/main/**/target/
44
!**/src/test/**/target/
55

6-
### Plugins Directory ###
7-
test-plugins
8-
96
### Log file ###
107
logs/
118

129
### IntelliJ IDEA ###
1310
.idea/
11+
!.idea/runConfigurations/
12+
!.idea/.gitignore/
1413
*.iws
1514
*.iml
1615
*.ipr
@@ -34,6 +33,8 @@ build/
3433
!**/src/main/**/build/
3534
!**/src/test/**/build/
3635

36+
!**/test/resources/**/.git
37+
3738
### VS Code ###
3839
.vscode/
3940

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin-modernizer-cli/src/main/java/io/jenkins/tools/pluginmodernizer/cli/command/BuildMetadataCommand.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import io.jenkins.tools.pluginmodernizer.core.config.Config;
77
import io.jenkins.tools.pluginmodernizer.core.config.Settings;
88
import io.jenkins.tools.pluginmodernizer.core.impl.PluginModernizer;
9+
import io.jenkins.tools.pluginmodernizer.core.model.ModernizerException;
10+
import java.nio.file.Path;
911
import org.slf4j.Logger;
1012
import org.slf4j.LoggerFactory;
1113
import picocli.CommandLine;
@@ -27,6 +29,14 @@ public class BuildMetadataCommand implements ICommand {
2729
@CommandLine.ArgGroup(exclusive = true, multiplicity = "1")
2830
private PluginOptions pluginOptions;
2931

32+
/**
33+
* Path to the authentication key in case of private repo
34+
*/
35+
@CommandLine.Option(
36+
names = {"--ssh-private-key"},
37+
description = "Path to the authentication key for GitHub. Default to ~/.ssh/id_rsa")
38+
private Path sshPrivateKey = Settings.SSH_PRIVATE_KEY;
39+
3040
/**
3141
* Global options for all commands
3242
*/
@@ -44,12 +54,21 @@ public Config setup(Config.Builder builder) {
4454
options.config(builder);
4555
envOptions.config(builder);
4656
pluginOptions.config(builder);
47-
return builder.withRecipe(Settings.FETCH_METADATA_RECIPE).build();
57+
return builder.withSshPrivateKey(sshPrivateKey)
58+
.withRecipe(Settings.FETCH_METADATA_RECIPE)
59+
.build();
4860
}
4961

5062
@Override
51-
public Integer call() throws Exception {
63+
public Integer call() {
5264
PluginModernizer modernizer = getModernizer();
65+
try {
66+
modernizer.validate();
67+
} catch (ModernizerException e) {
68+
LOG.error("Validation error");
69+
LOG.error(e.getMessage());
70+
return 1;
71+
}
5372
modernizer.start();
5473
return 0;
5574
}

plugin-modernizer-cli/src/main/java/io/jenkins/tools/pluginmodernizer/cli/command/ValidateCommand.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import io.jenkins.tools.pluginmodernizer.core.config.Config;
77
import io.jenkins.tools.pluginmodernizer.core.impl.PluginModernizer;
88
import io.jenkins.tools.pluginmodernizer.core.model.ModernizerException;
9+
import java.nio.file.Files;
10+
import java.nio.file.Path;
911
import org.slf4j.Logger;
1012
import org.slf4j.LoggerFactory;
1113
import picocli.CommandLine;
@@ -53,6 +55,11 @@ public Integer call() throws Exception {
5355
try {
5456
modernizer.validate();
5557
LOG.info("GitHub owner: {}", modernizer.getGithubOwner());
58+
if (Files.isRegularFile(Path.of(modernizer.getSshPrivateKeyPath()))) {
59+
LOG.info("SSH key path: {}", modernizer.getSshPrivateKeyPath());
60+
} else {
61+
LOG.info("SSH key not set. Will use GitHub token for Git operation");
62+
}
5663
LOG.info("Maven home: {}", modernizer.getMavenHome());
5764
LOG.info("Maven version: {}", modernizer.getMavenVersion());
5865
LOG.info("Java version: {}", modernizer.getJavaVersion());

plugin-modernizer-cli/src/main/java/io/jenkins/tools/pluginmodernizer/cli/options/GitHubOptions.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.jenkins.tools.pluginmodernizer.core.config.Config;
44
import io.jenkins.tools.pluginmodernizer.core.config.Settings;
5+
import java.nio.file.Path;
56
import picocli.CommandLine;
67

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

19+
/**
20+
* Path to the authentication key
21+
*/
22+
@CommandLine.Option(
23+
names = {"--ssh-private-key"},
24+
description = "Path to the authentication key for GitHub. Default to ~/.ssh/id_rsa")
25+
private Path sshPrivateKey = Settings.SSH_PRIVATE_KEY;
26+
1827
@CommandLine.Option(
1928
names = {"-g", "--github-owner"},
2029
description = "GitHub owner for forked repositories.")
@@ -46,6 +55,7 @@ public void config(Config.Builder builder) {
4655
builder.withGitHubOwner(githubOwner)
4756
.withGitHubAppId(githubAppId)
4857
.withGitHubAppSourceInstallationId(githubAppSourceInstallationId)
49-
.withGitHubAppTargetInstallationId(githubAppTargetInstallationId);
58+
.withGitHubAppTargetInstallationId(githubAppTargetInstallationId)
59+
.withSshPrivateKey(sshPrivateKey);
5060
}
5161
}

plugin-modernizer-cli/src/main/resources/logback.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
<logger name="java.lang.Runtime" level="WARN" />
4646
<logger name="org.apache.mina.core" level="WARN" />
4747
<logger name="org.apache.sshd.client" level="WARN" />
48+
<logger name="org.apache.sshd.client.keyverifier" level="ERROR" />
4849
<logger name="org.apache.sshd.common" level="WARN" />
50+
<logger name="org.apache.sshd.git.transport" level="WARN" />
4951
<logger name="org.eclipse.jgit.internal" level="WARN" />
5052
<logger name="org.eclipse.jgit.transport" level="INFO" />
5153
<logger name="org.eclipse.jgit.util" level="INFO" />

0 commit comments

Comments
 (0)