Merge "Fix ssh:// advertised URL in RevisionInfo fetch map of /detail"
This commit is contained in:
@@ -74,14 +74,12 @@ import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
|||||||
import com.google.gerrit.server.project.ChangeControl;
|
import com.google.gerrit.server.project.ChangeControl;
|
||||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.gerrit.server.ssh.SshInfo;
|
import com.google.gerrit.server.ssh.SshAdvertisedAddresses;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import com.jcraft.jsch.HostKey;
|
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -103,11 +101,16 @@ public class ChangeJson {
|
|||||||
static class Urls {
|
static class Urls {
|
||||||
final String git;
|
final String git;
|
||||||
final String http;
|
final String http;
|
||||||
|
final String ssh;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Urls(@GerritServerConfig Config cfg) {
|
Urls(@GerritServerConfig Config cfg,
|
||||||
|
@SshAdvertisedAddresses List<String> sshAddresses) {
|
||||||
this.git = ensureSlash(cfg.getString("gerrit", null, "canonicalGitUrl"));
|
this.git = ensureSlash(cfg.getString("gerrit", null, "canonicalGitUrl"));
|
||||||
this.http = ensureSlash(cfg.getString("gerrit", null, "gitHttpUrl"));
|
this.http = ensureSlash(cfg.getString("gerrit", null, "gitHttpUrl"));
|
||||||
|
this.ssh = !sshAddresses.isEmpty()
|
||||||
|
? ensureSlash("ssh://" + sshAddresses.get(0))
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String ensureSlash(String in) {
|
private static String ensureSlash(String in) {
|
||||||
@@ -133,7 +136,6 @@ public class ChangeJson {
|
|||||||
private final Revisions revisions;
|
private final Revisions revisions;
|
||||||
|
|
||||||
private ChangeControl.Factory changeControlUserFactory;
|
private ChangeControl.Factory changeControlUserFactory;
|
||||||
private SshInfo sshInfo;
|
|
||||||
private EnumSet<ListChangesOption> options;
|
private EnumSet<ListChangesOption> options;
|
||||||
private AccountInfo.Loader accountLoader;
|
private AccountInfo.Loader accountLoader;
|
||||||
private ChangeControl lastControl;
|
private ChangeControl lastControl;
|
||||||
@@ -180,11 +182,6 @@ public class ChangeJson {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChangeJson setSshInfo(SshInfo info) {
|
|
||||||
sshInfo = info;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChangeJson setChangeControlFactory(ChangeControl.Factory cf) {
|
public ChangeJson setChangeControlFactory(ChangeControl.Factory cf) {
|
||||||
changeControlUserFactory = cf;
|
changeControlUserFactory = cf;
|
||||||
return this;
|
return this;
|
||||||
@@ -826,11 +823,9 @@ public class ChangeJson {
|
|||||||
+ cd.change(db).getProject().get(), refName));
|
+ cd.change(db).getProject().get(), refName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sshInfo != null && !sshInfo.getHostKeys().isEmpty()) {
|
if (urls.ssh != null) {
|
||||||
HostKey host = sshInfo.getHostKeys().get(0);
|
r.put("ssh", new FetchInfo(
|
||||||
r.put("ssh", new FetchInfo(String.format(
|
urls.ssh + cd.change(db).getProject().get(),
|
||||||
"ssh://%s/%s",
|
|
||||||
host.getHost(), cd.change(db).getProject().get()),
|
|
||||||
refName));
|
refName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,7 +24,6 @@ import com.google.gerrit.server.change.ChangeJson;
|
|||||||
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
import com.google.gerrit.server.project.ChangeControl;
|
||||||
import com.google.gerrit.server.query.QueryParseException;
|
import com.google.gerrit.server.query.QueryParseException;
|
||||||
import com.google.gerrit.server.ssh.SshInfo;
|
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
@@ -81,13 +80,11 @@ public class QueryChanges implements RestReadView<TopLevelResource> {
|
|||||||
@Inject
|
@Inject
|
||||||
QueryChanges(ChangeJson json,
|
QueryChanges(ChangeJson json,
|
||||||
QueryProcessor qp,
|
QueryProcessor qp,
|
||||||
SshInfo sshInfo,
|
|
||||||
ChangeControl.Factory cf) {
|
ChangeControl.Factory cf) {
|
||||||
this.json = json;
|
this.json = json;
|
||||||
this.imp = qp;
|
this.imp = qp;
|
||||||
|
|
||||||
options = EnumSet.noneOf(ListChangesOption.class);
|
options = EnumSet.noneOf(ListChangesOption.class);
|
||||||
json.setSshInfo(sshInfo);
|
|
||||||
json.setChangeControlFactory(cf);
|
json.setChangeControlFactory(cf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user