Skip to content

The Unified and Autonomous Development Platform

Fix issue #854 - default branch via api

Robin Shen79ae1a79cd6c
diff --git a/server-core/src/main/java/io/onedev/server/rest/RepositoryResource.java b/server-core/src/main/java/io/onedev/server/rest/RepositoryResource.java
index c0cc50af9d..257e025eb6 100644
--- a/server-core/src/main/java/io/onedev/server/rest/RepositoryResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/RepositoryResource.java
@@ -9,6 +9,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.validation.constraints.NotNull;
@@ -114,6 +115,20 @@ public class RepositoryResource {
return branchNames;
}
+ @Api(order=15, description="Get default branch. Return status code 204 if no default branch "
+ + "(repository not initialized)")
+ @Path("/{projectId}/default-branch")
+ @GET
+ @Nullable
+ public String getDefaultBranch(@PathParam("projectId") Long projectId) {
+ Project project = projectManager.load(projectId);
+ if (!SecurityUtils.canReadCode(project)) {
+ throw new UnauthorizedException();
+ }
+
+ return project.getDefaultBranch();
+ }
+
@Api(order=20, description="Get specified branch")
@Path("/{projectId}/branches/{branch:.*}")
@GET