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

fix JENKINS-68435: Revert "Remove useless code for building clone url… #52

Merged
merged 1 commit into from
May 10, 2022
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
23 changes: 23 additions & 0 deletions src/main/java/org/jenkinsci/plugin/gitea/GiteaSCMBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import hudson.plugins.git.GitSCM;
import hudson.security.ACL;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
Expand All @@ -48,6 +49,7 @@
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.transport.RefSpec;
import org.jenkinsci.plugin.gitea.credentials.PersonalAccessToken;

/**
* Builds a {@link GitSCM} for {@link GiteaSCMSource}.
Expand Down Expand Up @@ -171,6 +173,27 @@ public static UriTemplate checkoutUriTemplate(@CheckForNull Item context,
.literal(".git")
.build();
}
if (credentials instanceof PersonalAccessToken) {
try {
// TODO is there a way we can get git plugin to redact the secret?
URI tokenUri = new URI(
serverUri.getScheme(),
((PersonalAccessToken) credentials).getToken().getPlainText(),
serverUri.getHost(),
serverUri.getPort(),
serverUri.getPath(),
serverUri.getQuery(),
serverUri.getFragment()
);
return UriTemplate.buildFromTemplate(tokenUri.toASCIIString())
.path(UriTemplateBuilder.var("owner"))
.path(UriTemplateBuilder.var("repository"))
.literal(".git")
.build();
} catch (URISyntaxException e) {
// ok we are at the end of the road
}
}
}
return UriTemplate.buildFromTemplate(serverUrl)
.path(UriTemplateBuilder.var("owner"))
Expand Down