mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
feat: Add endpoint to retrieve clone roots in McpHelperResource (OD-2567)
This commit is contained in:
parent
7eee7de067
commit
0c85caedfa
@ -87,7 +87,7 @@ public class SystemSetting implements Serializable, Validatable {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String deriveSshRootUrl(@Nullable String serverUrl) {
|
||||
public static String deriveSshRootUrl(@Nullable String serverUrl) {
|
||||
if (serverUrl != null) {
|
||||
try {
|
||||
URL url = new URL(serverUrl);
|
||||
|
||||
@ -47,6 +47,7 @@ import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
import io.onedev.commons.utils.StringUtils;
|
||||
import io.onedev.server.ServerConfig;
|
||||
import io.onedev.server.SubscriptionManager;
|
||||
import io.onedev.server.buildspec.BuildSpec;
|
||||
import io.onedev.server.data.migration.VersionedYamlDoc;
|
||||
@ -94,6 +95,7 @@ import io.onedev.server.model.PullRequestComment;
|
||||
import io.onedev.server.model.PullRequestReview;
|
||||
import io.onedev.server.model.PullRequestUpdate;
|
||||
import io.onedev.server.model.User;
|
||||
import io.onedev.server.model.support.administration.SystemSetting;
|
||||
import io.onedev.server.model.support.issue.field.FieldUtils;
|
||||
import io.onedev.server.model.support.issue.field.spec.BooleanField;
|
||||
import io.onedev.server.model.support.issue.field.spec.DateField;
|
||||
@ -179,6 +181,8 @@ public class McpHelperResource {
|
||||
|
||||
private final Validator validator;
|
||||
|
||||
private final ServerConfig serverConfig;
|
||||
|
||||
@Inject
|
||||
public McpHelperResource(ObjectMapper objectMapper, SettingManager settingManager,
|
||||
UserManager userManager, IssueManager issueManager, ProjectManager projectManager,
|
||||
@ -191,7 +195,8 @@ public class McpHelperResource {
|
||||
PullRequestAssignmentManager pullRequestAssignmentManager,
|
||||
PullRequestLabelManager pullRequestLabelManager, UrlManager urlManager,
|
||||
PullRequestCommentManager pullRequestCommentManager, BuildManager buildManager,
|
||||
BuildParamManager buildParamManager, JobManager jobManager, Validator validator) {
|
||||
BuildParamManager buildParamManager, JobManager jobManager, Validator validator,
|
||||
ServerConfig serverConfig) {
|
||||
this.objectMapper = objectMapper;
|
||||
this.settingManager = settingManager;
|
||||
this.issueManager = issueManager;
|
||||
@ -217,6 +222,7 @@ public class McpHelperResource {
|
||||
this.buildParamManager = buildParamManager;
|
||||
this.jobManager = jobManager;
|
||||
this.validator = validator;
|
||||
this.serverConfig = serverConfig;
|
||||
}
|
||||
|
||||
private String getIssueQueryStringDescription() {
|
||||
@ -2133,6 +2139,25 @@ public class McpHelperResource {
|
||||
return buildMap;
|
||||
}
|
||||
|
||||
@Path("/get-clone-roots")
|
||||
@GET
|
||||
public Map<String, String> getCloneUrl() {
|
||||
if (SecurityUtils.getAuthUser() == null)
|
||||
throw new UnauthenticatedException();
|
||||
|
||||
var cloneRoots = new HashMap<String, String>();
|
||||
var systemSetting = settingManager.getSystemSetting();
|
||||
var serverUrl = systemSetting.getServerUrl();
|
||||
cloneRoots.put("http", serverUrl);
|
||||
if (serverConfig.getSshPort() != 0) {
|
||||
var sshRootUrl = systemSetting.getSshRootUrl();
|
||||
if (sshRootUrl == null)
|
||||
sshRootUrl = SystemSetting.deriveSshRootUrl(serverUrl);
|
||||
cloneRoots.put("ssh", sshRootUrl);
|
||||
}
|
||||
return cloneRoots;
|
||||
}
|
||||
|
||||
@Path("/check-build-spec")
|
||||
@POST
|
||||
@Consumes(MediaType.TEXT_PLAIN)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user