Skip to content

Commit

Permalink
fix JENKINS-68435: Revert "Remove useless code for building clone url (
Browse files Browse the repository at this point in the history
…#50)" (#52)

This reverts commit 88a1ac7.
  • Loading branch information
cs8898 authored May 10, 2022
1 parent 23e4ec6 commit 8288e82
Showing 1 changed file with 23 additions and 0 deletions.
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

0 comments on commit 8288e82

Please sign in to comment.