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

We only clone from Git, so strip scm:git early #525

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
325 changes: 158 additions & 167 deletions src/main/java/org/jenkins/tools/test/PluginCompatTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,170 +377,162 @@ private void testPluginAgainst(
public static void cloneFromScm(
String url, String fallbackGitHubOrganization, String scmTag, File checkoutDirectory)
throws PluginSourcesUnavailableException {
List<String> connectionURLs = new ArrayList<>();
connectionURLs.add(url);
if (StringUtils.startsWith(url, "scm:git:")) {
url = StringUtils.substringAfter(url, "scm:git:");
}

List<String> gitUrls = new ArrayList<>();
gitUrls.add(url);
if (fallbackGitHubOrganization != null) {
connectionURLs = getFallbackConnectionURL(connectionURLs, url, fallbackGitHubOrganization);
gitUrls = getFallbackGitUrl(gitUrls, url, fallbackGitHubOrganization);
}

PluginSourcesUnavailableException lastException = null;
for (String connectionURL : connectionURLs) {
if (connectionURL != null) {
if (StringUtils.startsWith(connectionURL, "scm:git:")) {
connectionURL = StringUtils.substringAfter(connectionURL, "scm:git:");
}

// See: https://github.blog/2021-09-01-improving-git-protocol-security-github/

// TODO pending release of
// https://github.com/jenkinsci/antisamy-markup-formatter-plugin/pull/106
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/antisamy-markup-formatter-plugin",
"https://github.com/jenkinsci/antisamy-markup-formatter-plugin");

// TODO pending release of
// https://github.com/jenkinsci/authentication-tokens-plugin/pull/106
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/authentication-tokens-plugin",
"https://github.com/jenkinsci/authentication-tokens-plugin");

// TODO pending release of
// https://github.com/jenkinsci/aws-global-configuration-plugin/pull/51
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/aws-global-configuration-plugin",
"https://github.com/jenkinsci/aws-global-configuration-plugin");

// TODO pending release of
// https://github.com/jenkinsci/blueocean-display-url-plugin/pull/227
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/blueocean-display-url-plugin",
"https://github.com/jenkinsci/blueocean-display-url-plugin");

// TODO pending release of
// https://github.com/jenkinsci/bootstrap5-api-plugin/commit/8c5f60ab5e21c03b68d696e7b760caa991b25aa9
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/bootstrap5-api-plugin",
"https://github.com/jenkinsci/bootstrap5-api-plugin");

// TODO pending backport of
// https://github.com/jenkinsci/cloudbees-folder-plugin/pull/260
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/cloudbees-folder-plugin",
"https://github.com/jenkinsci/cloudbees-folder-plugin");

// TODO pending release of
// https://github.com/jenkinsci/configuration-as-code-plugin/pull/2166
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/configuration-as-code-plugin",
"https://github.com/jenkinsci/configuration-as-code-plugin");

// TODO pending backport of
// https://github.com/jenkinsci/custom-folder-icon-plugin/pull/109
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/custom-folder-icon-plugin",
"https://github.com/jenkinsci/custom-folder-icon-plugin");

// TODO pending release of
// https://github.com/jenkinsci/data-tables-api-plugin/commit/97dc7555017e6c7ea17f0b67cc292773f1114a54
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/data-tables-api-plugin",
"https://github.com/jenkinsci/data-tables-api-plugin");

// TODO pending backport of
// https://github.com/jenkinsci/echarts-api-plugin/commit/d6951a26e6f1c27b82c8308359f7f76e182de3e3
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/echarts-api-plugin",
"https://github.com/jenkinsci/echarts-api-plugin");

// TODO pending release of
// https://github.com/jenkinsci/file-parameters-plugin/pull/142
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/file-parameters-plugin",
"https://github.com/jenkinsci/file-parameters-plugin");

// TODO pending release of https://github.com/jenkinsci/github-api-plugin/pull/182
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/github-api-plugin",
"https://github.com/jenkinsci/github-api-plugin");

// TODO pending release of
// https://github.com/jenkinsci/google-kubernetes-engine-plugin/pull/312
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/google-kubernetes-engine-plugin",
"https://github.com/jenkinsci/google-kubernetes-engine-plugin");

// TODO pending release of
// https://github.com/jenkinsci/google-metadata-plugin/pull/50
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/google-metadata-plugin",
"https://github.com/jenkinsci/google-metadata-plugin");

// TODO pending release of https://github.com/jenkinsci/google-oauth-plugin/pull/176
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/google-oauth-plugin",
"https://github.com/jenkinsci/google-oauth-plugin");

// TODO pending release of
// https://github.com/jenkinsci/kubernetes-credentials-plugin/pull/37
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/kubernetes-credentials-plugin",
"https://github.com/jenkinsci/kubernetes-credentials-plugin");

// TODO pending release of
// https://github.com/jenkinsci/kubernetes-credentials-provider-plugin/pull/75
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/kubernetes-credentials-provider-plugin",
"https://github.com/jenkinsci/kubernetes-credentials-provider-plugin");

// TODO pending adoption of https://github.com/jenkinsci/matrix-auth-plugin/pull/131
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/matrix-auth-plugin",
"https://github.com/jenkinsci/matrix-auth-plugin");

// TODO pending release of
// https://github.com/jenkinsci/node-iterator-api-plugin/pull/11
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/node-iterator-api-plugin",
"https://github.com/jenkinsci/node-iterator-api-plugin");

// TODO pending release of
// https://github.com/jenkinsci/oauth-credentials-plugin/pull/9
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/oauth-credentials-plugin",
"https://github.com/jenkinsci/oauth-credentials-plugin");

// TODO pending release of
// https://github.com/jenkinsci/popper2-api-plugin/commit/bf781e31b072103f3f72d7195e9071863f7f4dd9
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/popper2-api-plugin",
"https://github.com/jenkinsci/popper2-api-plugin");

// TODO pending release of https://github.com/jenkinsci/pubsub-light-plugin/pull/100
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/pubsub-light-plugin",
"https://github.com/jenkinsci/pubsub-light-plugin");

// TODO pending release of https://github.com/jenkinsci/s3-plugin/pull/243
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/s3-plugin", "https://github.com/jenkinsci/s3-plugin");

// TODO pending release of https://github.com/jenkinsci/ssh-agent-plugin/pull/116
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/ssh-agent-plugin", "https://github.com/jenkinsci/ssh-agent-plugin");

// TODO pending release of https://github.com/jenkinsci/ssh-slaves-plugin/pull/352
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/ssh-slaves-plugin",
"https://github.com/jenkinsci/ssh-slaves-plugin");

// TODO pending release of
// https://github.com/jenkinsci/theme-manager-plugin/pull/154
connectionURL = connectionURL.replace(
"git://github.com/jenkinsci/theme-manager-plugin",
"https://github.com/jenkinsci/theme-manager-plugin");
}
for (String gitUrl : gitUrls) {
// See: https://github.blog/2021-09-01-improving-git-protocol-security-github/

// TODO pending release of
// https://github.com/jenkinsci/antisamy-markup-formatter-plugin/pull/106
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/antisamy-markup-formatter-plugin",
"https://github.com/jenkinsci/antisamy-markup-formatter-plugin");

// TODO pending release of
// https://github.com/jenkinsci/authentication-tokens-plugin/pull/106
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/authentication-tokens-plugin",
"https://github.com/jenkinsci/authentication-tokens-plugin");

// TODO pending release of
// https://github.com/jenkinsci/aws-global-configuration-plugin/pull/51
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/aws-global-configuration-plugin",
"https://github.com/jenkinsci/aws-global-configuration-plugin");

// TODO pending release of
// https://github.com/jenkinsci/blueocean-display-url-plugin/pull/227
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/blueocean-display-url-plugin",
"https://github.com/jenkinsci/blueocean-display-url-plugin");

// TODO pending release of
// https://github.com/jenkinsci/bootstrap5-api-plugin/commit/8c5f60ab5e21c03b68d696e7b760caa991b25aa9
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/bootstrap5-api-plugin",
"https://github.com/jenkinsci/bootstrap5-api-plugin");

// TODO pending backport of
// https://github.com/jenkinsci/cloudbees-folder-plugin/pull/260
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/cloudbees-folder-plugin",
"https://github.com/jenkinsci/cloudbees-folder-plugin");

// TODO pending release of
// https://github.com/jenkinsci/configuration-as-code-plugin/pull/2166
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/configuration-as-code-plugin",
"https://github.com/jenkinsci/configuration-as-code-plugin");

// TODO pending backport of
// https://github.com/jenkinsci/custom-folder-icon-plugin/pull/109
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/custom-folder-icon-plugin",
"https://github.com/jenkinsci/custom-folder-icon-plugin");

// TODO pending release of
// https://github.com/jenkinsci/data-tables-api-plugin/commit/97dc7555017e6c7ea17f0b67cc292773f1114a54
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/data-tables-api-plugin",
"https://github.com/jenkinsci/data-tables-api-plugin");

// TODO pending backport of
// https://github.com/jenkinsci/echarts-api-plugin/commit/d6951a26e6f1c27b82c8308359f7f76e182de3e3
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/echarts-api-plugin", "https://github.com/jenkinsci/echarts-api-plugin");

// TODO pending release of
// https://github.com/jenkinsci/file-parameters-plugin/pull/142
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/file-parameters-plugin",
"https://github.com/jenkinsci/file-parameters-plugin");

// TODO pending release of https://github.com/jenkinsci/github-api-plugin/pull/182
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/github-api-plugin", "https://github.com/jenkinsci/github-api-plugin");

// TODO pending release of
// https://github.com/jenkinsci/google-kubernetes-engine-plugin/pull/312
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/google-kubernetes-engine-plugin",
"https://github.com/jenkinsci/google-kubernetes-engine-plugin");

// TODO pending release of
// https://github.com/jenkinsci/google-metadata-plugin/pull/50
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/google-metadata-plugin",
"https://github.com/jenkinsci/google-metadata-plugin");

// TODO pending release of https://github.com/jenkinsci/google-oauth-plugin/pull/176
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/google-oauth-plugin",
"https://github.com/jenkinsci/google-oauth-plugin");

// TODO pending release of
// https://github.com/jenkinsci/kubernetes-credentials-plugin/pull/37
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/kubernetes-credentials-plugin",
"https://github.com/jenkinsci/kubernetes-credentials-plugin");

// TODO pending release of
// https://github.com/jenkinsci/kubernetes-credentials-provider-plugin/pull/75
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/kubernetes-credentials-provider-plugin",
"https://github.com/jenkinsci/kubernetes-credentials-provider-plugin");

// TODO pending adoption of https://github.com/jenkinsci/matrix-auth-plugin/pull/131
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/matrix-auth-plugin", "https://github.com/jenkinsci/matrix-auth-plugin");

// TODO pending release of
// https://github.com/jenkinsci/node-iterator-api-plugin/pull/11
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/node-iterator-api-plugin",
"https://github.com/jenkinsci/node-iterator-api-plugin");

// TODO pending release of
// https://github.com/jenkinsci/oauth-credentials-plugin/pull/9
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/oauth-credentials-plugin",
"https://github.com/jenkinsci/oauth-credentials-plugin");

// TODO pending release of
// https://github.com/jenkinsci/popper2-api-plugin/commit/bf781e31b072103f3f72d7195e9071863f7f4dd9
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/popper2-api-plugin", "https://github.com/jenkinsci/popper2-api-plugin");

// TODO pending release of https://github.com/jenkinsci/pubsub-light-plugin/pull/100
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/pubsub-light-plugin",
"https://github.com/jenkinsci/pubsub-light-plugin");

// TODO pending release of https://github.com/jenkinsci/s3-plugin/pull/243
gitUrl = gitUrl.replace("git://github.com/jenkinsci/s3-plugin", "https://github.com/jenkinsci/s3-plugin");

// TODO pending release of https://github.com/jenkinsci/ssh-agent-plugin/pull/116
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/ssh-agent-plugin", "https://github.com/jenkinsci/ssh-agent-plugin");

// TODO pending release of https://github.com/jenkinsci/ssh-slaves-plugin/pull/352
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/ssh-slaves-plugin", "https://github.com/jenkinsci/ssh-slaves-plugin");

// TODO pending release of
// https://github.com/jenkinsci/theme-manager-plugin/pull/154
gitUrl = gitUrl.replace(
"git://github.com/jenkinsci/theme-manager-plugin",
"https://github.com/jenkinsci/theme-manager-plugin");
try {
cloneImpl(connectionURL, scmTag, checkoutDirectory);
cloneImpl(gitUrl, scmTag, checkoutDirectory);
return; // checkout was ok
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand All @@ -551,7 +543,6 @@ public static void cloneFromScm(
lastException = e;
}
}

if (lastException != null) {
throw lastException;
}
Expand Down Expand Up @@ -661,17 +652,17 @@ private static void cloneImpl(String gitUrl, String scmTag, File checkoutDirecto
}
}

public static List<String> getFallbackConnectionURL(
List<String> connectionURLs, String connectionURLPomData, String fallbackGitHubOrganization) {
public static List<String> getFallbackGitUrl(
List<String> gitUrls, String gitUrlFromMetadata, String fallbackGitHubOrganization) {
Pattern pattern = Pattern.compile("(.*github.com[:|/])([^/]*)(.*)");
Matcher matcher = pattern.matcher(connectionURLPomData);
Matcher matcher = pattern.matcher(gitUrlFromMetadata);
matcher.find();
connectionURLs.add(matcher.replaceFirst("scm:git:git@github.com:" + fallbackGitHubOrganization + "$3"));
gitUrls.add(matcher.replaceFirst("git@github.com:" + fallbackGitHubOrganization + "$3"));
pattern = Pattern.compile("(.*github.com[:|/])([^/]*)(.*)");
matcher = pattern.matcher(connectionURLPomData);
matcher = pattern.matcher(gitUrlFromMetadata);
matcher.find();
connectionURLs.add(matcher.replaceFirst("$1" + fallbackGitHubOrganization + "$3"));
return connectionURLs;
gitUrls.add(matcher.replaceFirst("$1" + fallbackGitHubOrganization + "$3"));
return gitUrls;
}

private boolean localCheckoutProvided() {
Expand Down