Some minor enhancements

Highlight reference links among normal links
Detect primary ip address when run out side of docker/k8s
This commit is contained in:
Robin Shen 2019-12-13 15:47:08 +08:00
parent 9125c148b7
commit ff7a632aba
10 changed files with 37 additions and 11 deletions

View File

@ -2,7 +2,10 @@ package io.onedev.server;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Set;
@ -14,6 +17,7 @@ import javax.annotation.Nullable;
import javax.inject.Inject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -213,9 +217,23 @@ public class OneDev extends AbstractPlugin implements Serializable {
if (ipRef.get() == null) {
try {
ipRef.set(InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException e) {
throw new RuntimeException(e);
if (SystemUtils.IS_OS_MAC_OSX) {
try (Socket socket = new Socket()) {
socket.connect(new InetSocketAddress("microsoft.com", 80));
ipRef.set(StringUtils.stripStart(socket.getLocalAddress().toString(), "/"));
}
} else {
try (DatagramSocket socket = new DatagramSocket()) {
socket.connect(InetAddress.getByName("8.8.8.8"), 10002);
ipRef.set(socket.getLocalAddress().getHostAddress());
}
}
} catch (Exception e) {
try {
ipRef.set(InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException e2) {
throw new RuntimeException(e2);
}
}
}

View File

@ -89,7 +89,7 @@ public class Role extends AbstractEntity implements Permission {
@OneToMany(mappedBy="role", cascade=CascadeType.REMOVE)
private Collection<GroupAuthorization> groupAuthorizations = new ArrayList<>();
@Editable(order=100, description="Specify name of the role. <b style='color:red'>NOTE: </b> "
@Editable(order=100, description="Specify name of the role. <b class='red'>NOTE: </b> "
+ "Permission to view issues will be granted implicitly even if no other permissions "
+ "are specified here")
@NotEmpty

View File

@ -38,6 +38,8 @@ public class AutoDiscoveredJobExecutor extends JobExecutor {
});
JobExecutor jobExecutor = jobExecutors.iterator().next();
context.getLogger().log("Discovered job executor type: "
+ EditableUtils.getDisplayName(jobExecutor.getClass()));
jobExecutor.setName(getName());
jobExecutor.setApplicableBranches(getApplicableBranches());
jobExecutor.setCacheTTL(getCacheTTL());

View File

@ -34,7 +34,7 @@ public class JobPrivilege implements Serializable {
private String accessibleReports;
@Editable(order=100, description="Specify space-separated jobs. Use * or ? for wildcard match. "
+ "<b style='color:red'>NOTE: </b> Permission to access build artifacts will be granted "
+ "<b class='red'>NOTE: </b> Permission to access build artifacts will be granted "
+ "implicitly in matched jobs even if no other permissions are specified here")
@Patterns(suggester = "suggestJobNames")
@NotEmpty

View File

@ -6,7 +6,9 @@ body {
a {
color: #1f3b7b;
}
a.embedded-reference {
color: #0d87e9;
}
.pointer {
cursor: pointer;
}
@ -19,6 +21,9 @@ a {
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
}
.red {
color: red;
}
/* FEEDBACK */
#session-feedback {

View File

@ -43,7 +43,7 @@ public class ReferenceTransformer implements Function<String, String> {
@Override
protected String toHtml(Issue referenceable, String referenceText) {
return "<a href='" + RequestCycle.get().urlFor(IssueActivitiesPage.class,
return "<a class='embedded-reference' href='" + RequestCycle.get().urlFor(IssueActivitiesPage.class,
IssueActivitiesPage.paramsOf(referenceable, null)) + "'>" + referenceText + "</a>";
}
@ -61,7 +61,7 @@ public class ReferenceTransformer implements Function<String, String> {
@Override
protected String toHtml(PullRequest referenceable, String referenceText) {
return "<a href='" + RequestCycle.get().urlFor(PullRequestActivitiesPage.class,
return "<a class='embedded-reference' href='" + RequestCycle.get().urlFor(PullRequestActivitiesPage.class,
PullRequestActivitiesPage.paramsOf(referenceable, null)) + "'>" + referenceText + "</a>";
}
@ -79,7 +79,7 @@ public class ReferenceTransformer implements Function<String, String> {
@Override
protected String toHtml(Build referenceable, String referenceText) {
return "<a href='" + RequestCycle.get().urlFor(BuildDashboardPage.class,
return "<a class='embedded-reference' href='" + RequestCycle.get().urlFor(BuildDashboardPage.class,
BuildDashboardPage.paramsOf(referenceable, null)) + "'>" + referenceText + "</a>";
}

View File

@ -56,6 +56,7 @@ public class DockerModule extends AbstractPluginModule {
}
}).checkReturnCode();
return new DockerExecutor();
} catch (Exception e) {
return null;

View File

@ -67,7 +67,7 @@ import io.onedev.server.web.editable.annotation.OmitName;
import io.onedev.server.web.util.Testable;
@Editable(order=100, description="This executor runs build jobs as pods in a kubernetes cluster. "
+ "<b style='color:red'>Note:</b> Make sure server url is specified correctly in system "
+ "<b class='red'>Note:</b> Make sure server url is specified correctly in system "
+ "setting as job pods need to access it to download source and artifacts")
@Horizontal
public class KubernetesExecutor extends JobExecutor implements Testable<TestData> {

View File

@ -58,6 +58,7 @@ public class KubernetesModule extends AbstractPluginModule {
}
}).checkReturnCode();
return new KubernetesExecutor();
} catch (Exception e) {
return null;

View File

@ -5,5 +5,4 @@ public class Test {
@org.junit.Test
public void test() {
}
}