Added a list branches rpc
| | |
| | | <tr><th>req=</th><th>name=</th><th>post body</th><th>response body</th></tr>
|
| | | <tr><td colspan='5'><em>web.enableRpcServlet=true</em></td></tr>
|
| | | <tr><td>LIST_REPOSITORIES</td><td>-</td><td>-</td><td>-</td><td>Map<String, RepositoryModel></td></tr>
|
| | | <tr><td>LIST_BRANCHES</td><td>-</td><td>-</td><td>-</td><td>Map<String, List<String>></td></tr>
|
| | | <tr><td colspan='5'><em>web.enableRpcManagement=true</em></td></tr>
|
| | | <tr><td>CREATE_REPOSITORY</td><td>repository name</td><td><em>admin</em></td><td>RepositoryModel</td><td>-</td></tr>
|
| | | <tr><td>EDIT_REPOSITORY</td><td>repository name</td><td><em>admin</em></td><td>RepositoryModel</td><td>-</td></tr>
|
| | |
| | | <pre>
|
| | | {
|
| | | "bootDate": "2011-10-22T12:13:00Z",
|
| | | "version": "0.7.0-SNAPSHOT",
|
| | | "releaseDate": "PENDING",
|
| | | "isGO": true,
|
| | | "systemProperties": {
|
| | | "file.encoding": "Cp1252",
|
| | | "java.home": "C:\\Program Files\\Java\\jdk1.6.0_26\\jre",
|
| | |
| | | },
|
| | | "heapAllocated": 128057344,
|
| | | "heapFree": 120399168,
|
| | | "heapSize": 1899560960
|
| | | "heapSize": 1899560960,
|
| | | "servletContainer": "jetty/7.4.3.v20110701"
|
| | | }
|
| | | </pre> |
| | |
| | | * a client.
|
| | | */
|
| | | public static enum RpcRequest {
|
| | | LIST_REPOSITORIES, CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,
|
| | | LIST_REPOSITORIES, LIST_BRANCHES, CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,
|
| | | LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER, LIST_REPOSITORY_MEMBERS,
|
| | | SET_REPOSITORY_MEMBERS, LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS,
|
| | | LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS, LIST_SETTINGS, EDIT_SETTINGS,
|
| | |
| | | super(message);
|
| | | }
|
| | |
|
| | | public GitBlitException(Throwable cause) {
|
| | | super(cause);
|
| | | }
|
| | |
|
| | | /**
|
| | | * Exception to indicate that the client should prompt for credentials
|
| | | * because the requested action requires authentication.
|
| | |
| | | return;
|
| | | }
|
| | |
|
| | | boolean adminRequest = requestType.exceeds(RpcRequest.LIST_REPOSITORIES);
|
| | | boolean adminRequest = requestType.exceeds(RpcRequest.LIST_BRANCHES);
|
| | |
|
| | | // conditionally reject all rpc requests
|
| | | if (!GitBlit.getBoolean(Keys.web.enableRpcServlet, true)) {
|
| | |
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | |
|
| | | import com.gitblit.Constants.RpcRequest;
|
| | | import com.gitblit.models.RefModel;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.ServerSettings;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.HttpUtils;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.RpcUtils;
|
| | |
|
| | | /**
|
| | |
| | | repositories.put(url, model);
|
| | | }
|
| | | result = repositories;
|
| | | } else if (RpcRequest.LIST_BRANCHES.equals(reqType)) {
|
| | | // list all branches in all repositories accessible to user
|
| | | Map<String, List<String>> allBranches = new HashMap<String, List<String>>();
|
| | | List<RepositoryModel> models = GitBlit.self().getRepositoryModels(user);
|
| | | for (RepositoryModel model : models) {
|
| | | if (!model.hasCommits) {
|
| | | // skip empty repository
|
| | | continue;
|
| | | }
|
| | | // get branches
|
| | | Repository repository = GitBlit.self().getRepository(model.name);
|
| | | List<RefModel> refs = JGitUtils.getLocalBranches(repository, false, -1);
|
| | | refs.addAll(JGitUtils.getRemoteBranches(repository, false, -1));
|
| | | if (refs.size() > 0) {
|
| | | List<String> branches = new ArrayList<String>();
|
| | | for (RefModel ref : refs) {
|
| | | branches.add(ref.getName());
|
| | | }
|
| | | allBranches.put(model.name, branches);
|
| | | }
|
| | | repository.close();
|
| | | }
|
| | | result = allBranches;
|
| | | } else if (RpcRequest.LIST_USERS.equals(reqType)) {
|
| | | // list users
|
| | | List<String> names = GitBlit.self().getAllUsernames();
|
| | |
| | | private static final Type SETS_TYPE = new TypeToken<Collection<FederationSet>>() {
|
| | | }.getType();
|
| | |
|
| | | private static final Type BRANCHES_TYPE = new TypeToken<Map<String, Collection<String>>>() {
|
| | | }.getType();
|
| | |
|
| | | /**
|
| | | *
|
| | | * @param remoteURL
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * Retrieves a map of all branches in the Gitblit server keyed by
|
| | | * repository.
|
| | | * |
| | | * @param serverUrl
|
| | | * @param account
|
| | | * @param password
|
| | | * @return
|
| | | * @throws IOException
|
| | | */
|
| | | public static Map<String, Collection<String>> getAllBranches(String serverUrl,
|
| | | String account, char[] password) throws IOException {
|
| | | String url = asLink(serverUrl, RpcRequest.LIST_BRANCHES);
|
| | | Map<String, Collection<String>> allReferences = JsonUtils.retrieveJson(url,
|
| | | BRANCHES_TYPE, account, password);
|
| | | return allReferences;
|
| | | }
|
| | |
|
| | | /**
|
| | | * Do the specified administrative action on the Gitblit server.
|
| | | *
|
| | | * @param request
|
| | |
| | | package com.gitblit.tests;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.util.Collection;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
| | | newValue = !newValue;
|
| | | updated.put(Keys.web.showRepositorySizes, String.valueOf(newValue));
|
| | | }
|
| | |
|
| | | public void testBranches() throws Exception {
|
| | | Map<String, Collection<String>> branches = RpcUtils.getAllBranches(url, account,
|
| | | password.toCharArray());
|
| | | assertTrue(branches != null);
|
| | | assertTrue(branches.size() > 0);
|
| | | }
|
| | | }
|