InlineEdit: Respect change edits in download commands drop down
Change-Id: I0f4d101b3249722cd03851f814476129f79bb022
This commit is contained in:
		| @@ -1163,7 +1163,8 @@ exist for this change. Change edits are stored on special branches and there | ||||
| can be max one edit per user per change. Edits aren't tracked in the database. | ||||
| When request parameter `list` is provided the response also includes the file | ||||
| list. When `base` request parameter is provided the file list is computed | ||||
| against this base revision. | ||||
| against this base revision. When request parameter `download-commands` is | ||||
| provided fetch info map is also included. | ||||
|  | ||||
| .Response | ||||
| ---- | ||||
| @@ -3831,6 +3832,10 @@ link:#commit-info[CommitInfo] entity. | ||||
| Actions the caller might be able to perform on this change edit. The | ||||
| information is a map of view name to link:#action-info[ActionInfo] | ||||
| entities. | ||||
| |`fetch`       || | ||||
| Information about how to fetch this patch set. The fetch information is | ||||
| provided as a map that maps the protocol name ("`git`", "`http`", | ||||
| "`ssh`") to link:#fetch-info[FetchInfo] entities. | ||||
| |`files`       |optional| | ||||
| The files of the change edit as a map that maps the file names to | ||||
| link:#file-info[FileInfo] entities. | ||||
|   | ||||
| @@ -19,5 +19,6 @@ import java.util.Map; | ||||
| public class EditInfo { | ||||
|   public CommitInfo commit; | ||||
|   public Map<String, ActionInfo> actions; | ||||
|   public Map<String, FetchInfo> fetch; | ||||
|   public Map<String, FileInfo> files; | ||||
| } | ||||
|   | ||||
| @@ -18,6 +18,7 @@ import com.google.gerrit.client.Gerrit; | ||||
| import com.google.gerrit.client.account.AccountApi; | ||||
| import com.google.gerrit.client.changes.ChangeApi; | ||||
| import com.google.gerrit.client.changes.ChangeInfo; | ||||
| import com.google.gerrit.client.changes.ChangeInfo.EditInfo; | ||||
| import com.google.gerrit.client.changes.ChangeInfo.FetchInfo; | ||||
| import com.google.gerrit.client.changes.ChangeList; | ||||
| import com.google.gerrit.client.rpc.NativeMap; | ||||
| @@ -78,6 +79,20 @@ class DownloadBox extends VerticalPanel { | ||||
|   @Override | ||||
|   protected void onLoad() { | ||||
|     if (fetch == null) { | ||||
|       if (psId.get() == 0) { | ||||
|         ChangeApi.editWithCommands(change.legacy_id().get()).get( | ||||
|             new AsyncCallback<EditInfo>() { | ||||
|           @Override | ||||
|           public void onSuccess(EditInfo result) { | ||||
|             fetch = result.fetch(); | ||||
|             renderScheme(); | ||||
|           } | ||||
|  | ||||
|           @Override | ||||
|           public void onFailure(Throwable caught) { | ||||
|           } | ||||
|         }); | ||||
|       } else { | ||||
|         RestApi call = ChangeApi.detail(change.legacy_id().get()); | ||||
|         ChangeList.addOptions(call, EnumSet.of( | ||||
|             revision.equals(change.current_revision()) | ||||
| @@ -97,6 +112,7 @@ class DownloadBox extends VerticalPanel { | ||||
|         }); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   private void renderCommands() { | ||||
|     commandTable.removeAllRows(); | ||||
|   | ||||
| @@ -81,6 +81,10 @@ public class ChangeApi { | ||||
|     return change(id).view("edit"); | ||||
|   } | ||||
|  | ||||
|   public static RestApi editWithCommands(int id) { | ||||
|     return edit(id).addParameter("download-commands", true); | ||||
|   } | ||||
|  | ||||
|   public static void includedIn(int id, AsyncCallback<IncludedInInfo> cb) { | ||||
|     call(id, "in").get(cb); | ||||
|   } | ||||
|   | ||||
| @@ -217,6 +217,9 @@ public class ChangeInfo extends JavaScriptObject { | ||||
|     public final native boolean has_actions() /*-{ return this.hasOwnProperty('actions') }-*/; | ||||
|     public final native NativeMap<ActionInfo> actions() /*-{ return this.actions; }-*/; | ||||
|  | ||||
|     public final native boolean has_fetch() /*-{ return this.hasOwnProperty('fetch') }-*/; | ||||
|     public final native NativeMap<FetchInfo> fetch() /*-{ return this.fetch; }-*/; | ||||
|  | ||||
|     public final native boolean has_files() /*-{ return this.hasOwnProperty('files') }-*/; | ||||
|     public final native NativeMap<FileInfo> files() /*-{ return this.files; }-*/; | ||||
|  | ||||
|   | ||||
| @@ -239,6 +239,8 @@ public class ChangeEdits implements | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   // TODO(davido): Turn the boolean options to ChangeEditOption enum, | ||||
|   // like it's already the case for ListChangesOption/ListGroupsOption | ||||
|   static class Detail implements RestReadView<ChangeResource> { | ||||
|     private final ChangeEditUtil editUtil; | ||||
|     private final ChangeEditJson editJson; | ||||
| @@ -251,6 +253,9 @@ public class ChangeEdits implements | ||||
|     @Option(name = "--list", metaVar = "LIST") | ||||
|     boolean list; | ||||
|  | ||||
|     @Option(name = "--download-commands", metaVar = "download-commands") | ||||
|     boolean downloadCommands; | ||||
|  | ||||
|     @Inject | ||||
|     Detail(ChangeEditUtil editUtil, | ||||
|         ChangeEditJson editJson, | ||||
| @@ -271,7 +276,7 @@ public class ChangeEdits implements | ||||
|         return Response.none(); | ||||
|       } | ||||
|  | ||||
|       EditInfo editInfo = editJson.toEditInfo(edit.get()); | ||||
|       EditInfo editInfo = editJson.toEditInfo(edit.get(), downloadCommands); | ||||
|       if (list) { | ||||
|         PatchSet basePatchSet = null; | ||||
|         if (base != null) { | ||||
|   | ||||
| @@ -884,7 +884,18 @@ public class ChangeJson { | ||||
|       r.put(schemeName, fetchInfo); | ||||
|  | ||||
|       if (has(DOWNLOAD_COMMANDS)) { | ||||
|         for (DynamicMap.Entry<DownloadCommand> e2 : downloadCommands) { | ||||
|         populateFetchMap(scheme, downloadCommands, projectName, refName, | ||||
|             fetchInfo); | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     return r; | ||||
|   } | ||||
|  | ||||
|   public static void populateFetchMap(DownloadScheme scheme, | ||||
|       DynamicMap<DownloadCommand> commands, String projectName, | ||||
|       String refName, FetchInfo fetchInfo) { | ||||
|     for (DynamicMap.Entry<DownloadCommand> e2 : commands) { | ||||
|       String commandName = e2.getExportName(); | ||||
|       DownloadCommand command = e2.getProvider().get(); | ||||
|       String c = command.getCommand(scheme, projectName, refName); | ||||
| @@ -893,12 +904,9 @@ public class ChangeJson { | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|     } | ||||
|  | ||||
|     return r; | ||||
|   } | ||||
|  | ||||
|   private void addCommand(FetchInfo fetchInfo, String commandName, String c) { | ||||
|   private static void addCommand(FetchInfo fetchInfo, String commandName, | ||||
|       String c) { | ||||
|     if (fetchInfo.commands == null) { | ||||
|       fetchInfo.commands = Maps.newTreeMap(); | ||||
|     } | ||||
|   | ||||
| @@ -19,10 +19,18 @@ import com.google.common.collect.Maps; | ||||
| import com.google.gerrit.extensions.common.ActionInfo; | ||||
| import com.google.gerrit.extensions.common.CommitInfo; | ||||
| import com.google.gerrit.extensions.common.EditInfo; | ||||
| import com.google.gerrit.extensions.common.FetchInfo; | ||||
| import com.google.gerrit.extensions.config.DownloadCommand; | ||||
| import com.google.gerrit.extensions.config.DownloadScheme; | ||||
| import com.google.gerrit.extensions.registration.DynamicMap; | ||||
| import com.google.gerrit.extensions.webui.PrivateInternals_UiActionDescription; | ||||
| import com.google.gerrit.extensions.webui.UiAction; | ||||
| import com.google.gerrit.reviewdb.client.PatchSet; | ||||
| import com.google.gerrit.server.CommonConverters; | ||||
| import com.google.gerrit.server.CurrentUser; | ||||
| import com.google.gerrit.server.change.ChangeJson; | ||||
| import com.google.inject.Inject; | ||||
| import com.google.inject.Provider; | ||||
| import com.google.inject.Singleton; | ||||
|  | ||||
| import org.eclipse.jgit.revwalk.RevCommit; | ||||
| @@ -32,10 +40,27 @@ import java.util.Map; | ||||
|  | ||||
| @Singleton | ||||
| public class ChangeEditJson { | ||||
|   public EditInfo toEditInfo(ChangeEdit edit) throws IOException { | ||||
|   private final DynamicMap<DownloadCommand> downloadCommands; | ||||
|   private final DynamicMap<DownloadScheme> downloadSchemes; | ||||
|   private final Provider<CurrentUser> userProvider; | ||||
|  | ||||
|   @Inject | ||||
|   ChangeEditJson(DynamicMap<DownloadCommand> downloadCommand, | ||||
|       DynamicMap<DownloadScheme> downloadSchemes, | ||||
|       Provider<CurrentUser> userProvider) { | ||||
|     this.downloadCommands = downloadCommand; | ||||
|     this.downloadSchemes = downloadSchemes; | ||||
|     this.userProvider = userProvider; | ||||
|   } | ||||
|  | ||||
|   public EditInfo toEditInfo(ChangeEdit edit, boolean downloadCommands) | ||||
|       throws IOException { | ||||
|     EditInfo out = new EditInfo(); | ||||
|     out.commit = fillCommit(edit.getEditCommit()); | ||||
|     out.actions = fillActions(edit); | ||||
|     if (downloadCommands) { | ||||
|       out.fetch = fillFetchMap(edit); | ||||
|     } | ||||
|     return out; | ||||
|   } | ||||
|  | ||||
| @@ -84,4 +109,32 @@ public class ChangeEditJson { | ||||
|  | ||||
|     return actions; | ||||
|   } | ||||
|  | ||||
|   private Map<String, FetchInfo> fillFetchMap(ChangeEdit edit) { | ||||
|     Map<String, FetchInfo> r = Maps.newLinkedHashMap(); | ||||
|     for (DynamicMap.Entry<DownloadScheme> e : downloadSchemes) { | ||||
|       String schemeName = e.getExportName(); | ||||
|       DownloadScheme scheme = e.getProvider().get(); | ||||
|       if (!scheme.isEnabled() | ||||
|           || (scheme.isAuthRequired() | ||||
|               && !userProvider.get().isIdentifiedUser())) { | ||||
|         continue; | ||||
|       } | ||||
|  | ||||
|       // No fluff, just stuff | ||||
|       if (!scheme.isAuthSupported()) { | ||||
|         continue; | ||||
|       } | ||||
|  | ||||
|       String projectName = edit.getChange().getProject().get(); | ||||
|       String refName = edit.getRefName(); | ||||
|       FetchInfo fetchInfo = new FetchInfo(scheme.getUrl(projectName), refName); | ||||
|       r.put(schemeName, fetchInfo); | ||||
|  | ||||
|       ChangeJson.populateFetchMap(scheme, downloadCommands, projectName, | ||||
|           refName, fetchInfo); | ||||
|     } | ||||
|  | ||||
|     return r; | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 David Ostrovsky
					David Ostrovsky