From: James Moger Date: Mon, 19 Dec 2011 23:00:29 +0000 (-0500) Subject: RPC support for hook script selection X-Git-Tag: v0.8.0~66 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4bd2037edddbf444ac9817e9d14710be45850a10;p=gitblit.git RPC support for hook script selection --- diff --git a/src/com/gitblit/RpcServlet.java b/src/com/gitblit/RpcServlet.java index 115d5536..c33bd8a2 100644 --- a/src/com/gitblit/RpcServlet.java +++ b/src/com/gitblit/RpcServlet.java @@ -276,7 +276,7 @@ public class RpcServlet extends JsonServlet { } } else if (RpcRequest.LIST_SETTINGS.equals(reqType)) { // return the server's settings - ServerSettings settings = GitBlit.self().getSettingsModel(); + ServerSettings settings = GitBlit.self().getSettingsModel(); if (allowAdmin) { // return all settings result = settings; @@ -294,10 +294,13 @@ public class RpcServlet extends JsonServlet { keys.add(Keys.federation.sets); } // build the settings - ServerSettings managementSettings = new ServerSettings(); + ServerSettings managementSettings = new ServerSettings(); for (String key : keys) { managementSettings.add(settings.get(key)); } + if (allowManagement) { + settings.pushScripts = settings.pushScripts; + } result = managementSettings; } } else if (RpcRequest.EDIT_SETTINGS.equals(reqType)) { diff --git a/src/com/gitblit/client/EditRepositoryDialog.java b/src/com/gitblit/client/EditRepositoryDialog.java index a70a6178..44b6fc6a 100644 --- a/src/com/gitblit/client/EditRepositoryDialog.java +++ b/src/com/gitblit/client/EditRepositoryDialog.java @@ -88,7 +88,7 @@ public class EditRepositoryDialog extends JDialog { private JCheckBox skipSummaryMetrics; private JCheckBox isFrozen; - + private JTextField mailRecipientsField; private JComboBox accessRestriction; @@ -98,11 +98,15 @@ public class EditRepositoryDialog extends JDialog { private JComboBox ownerField; private JPalette usersPalette; - + private JPalette setsPalette; - + private JPalette teamsPalette; + private JPalette preReceivePalette; + + private JPalette postReceivePalette; + private Set repositoryNames; public EditRepositoryDialog(int protocolVersion) { @@ -162,7 +166,7 @@ public class EditRepositoryDialog extends JDialog { mailRecipientsField = new JTextField(anRepository.mailRecipients == null ? "" : StringUtils.flattenStrings(anRepository.mailRecipients, " "), 50); - + accessRestriction = new JComboBox(AccessRestrictionType.values()); accessRestriction.setRenderer(new AccessRestrictionRenderer()); accessRestriction.setSelectedItem(anRepository.accessRestriction); @@ -216,6 +220,18 @@ public class EditRepositoryDialog extends JDialog { federationPanel.add(newFieldPanel(Translation.get("gb.federationSets"), setsPalette), BorderLayout.CENTER); + preReceivePalette = new JPalette(true); + JPanel preReceivePanel = new JPanel(new BorderLayout(5, 5)); + preReceivePanel.add( + newFieldPanel(Translation.get("gb.preReceiveScripts"), preReceivePalette), + BorderLayout.CENTER); + + postReceivePalette = new JPalette(true); + JPanel postReceivePanel = new JPanel(new BorderLayout(5, 5)); + postReceivePanel.add( + newFieldPanel(Translation.get("gb.postReceiveScripts"), postReceivePalette), + BorderLayout.CENTER); + JTabbedPane panel = new JTabbedPane(JTabbedPane.TOP); panel.addTab(Translation.get("gb.general"), fieldsPanel); panel.addTab(Translation.get("gb.accessRestriction"), accessPanel); @@ -223,6 +239,8 @@ public class EditRepositoryDialog extends JDialog { panel.addTab(Translation.get("gb.teams"), teamsPanel); } panel.addTab(Translation.get("gb.federation"), federationPanel); + panel.addTab(Translation.get("gb.preReceiveScripts"), preReceivePanel); + panel.addTab(Translation.get("gb.postReceiveScripts"), postReceivePanel); JButton createButton = new JButton(Translation.get("gb.save")); createButton.addActionListener(new ActionListener() { @@ -352,8 +370,9 @@ public class EditRepositoryDialog extends JDialog { repository.skipSizeCalculation = skipSizeCalculation.isSelected(); repository.skipSummaryMetrics = skipSummaryMetrics.isSelected(); repository.isFrozen = isFrozen.isSelected(); - - repository.mailRecipients = StringUtils.getStringsFromValue(mailRecipientsField.getText().trim(), " "); + + repository.mailRecipients = StringUtils.getStringsFromValue(mailRecipientsField.getText() + .trim(), " "); repository.accessRestriction = (AccessRestrictionType) accessRestriction.getSelectedItem(); repository.federationStrategy = (FederationStrategy) federationStrategy.getSelectedItem(); @@ -361,6 +380,9 @@ public class EditRepositoryDialog extends JDialog { if (repository.federationStrategy.exceeds(FederationStrategy.EXCLUDE)) { repository.federationSets = setsPalette.getSelections(); } + + repository.preReceiveScripts = preReceivePalette.getSelections(); + repository.postReceiveScripts = postReceivePalette.getSelections(); return true; } @@ -376,7 +398,7 @@ public class EditRepositoryDialog extends JDialog { } usersPalette.setObjects(all, selected); } - + public void setTeams(List all, List selected) { teamsPalette.setObjects(all, selected); } @@ -396,6 +418,14 @@ public class EditRepositoryDialog extends JDialog { setsPalette.setObjects(all, selected); } + public void setPreReceiveScripts(List all, List selected) { + preReceivePalette.setObjects(all, selected); + } + + public void setPostReceiveScripts(List all, List selected) { + postReceivePalette.setObjects(all, selected); + } + public RepositoryModel getRepository() { if (canceled) { return null; diff --git a/src/com/gitblit/client/GitblitClient.java b/src/com/gitblit/client/GitblitClient.java index b9444861..f9af8dfe 100644 --- a/src/com/gitblit/client/GitblitClient.java +++ b/src/com/gitblit/client/GitblitClient.java @@ -183,6 +183,13 @@ public class GitblitClient implements Serializable { } } + public List getAvailableScripts() { + if (settings.pushScripts == null) { + return new ArrayList(); + } + return settings.pushScripts; + } + public ServerSettings getSettings() { return settings; } diff --git a/src/com/gitblit/client/JPalette.java b/src/com/gitblit/client/JPalette.java index eb445b45..699b271e 100644 --- a/src/com/gitblit/client/JPalette.java +++ b/src/com/gitblit/client/JPalette.java @@ -40,6 +40,10 @@ public class JPalette extends JPanel { private PaletteModel selectedModel; public JPalette() { + this(false); + } + + public JPalette(boolean controlOrder) { super(new BorderLayout(5, 5)); availableModel = new PaletteModel(); @@ -86,9 +90,37 @@ public class JPalette extends JPanel { } }); + JButton up = new JButton("\u2191"); + up.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + int row = selected.getSelectedRow(); + if (row > 0) { + T o = selectedModel.list.remove(row); + selectedModel.list.add(row - 1, o); + selectedModel.fireTableDataChanged(); + } + } + }); + + JButton down = new JButton("\u2193"); + down.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + int row = selected.getSelectedRow(); + if (row < selected.getRowCount() - 1) { + T o = selectedModel.list.remove(row); + selectedModel.list.add(row + 1, o); + selectedModel.fireTableDataChanged(); + } + } + }); + JPanel controls = new JPanel(new GridLayout(0, 1, 0, 5)); controls.add(add); controls.add(subtract); + if (controlOrder) { + controls.add(up); + controls.add(down); + } JPanel center = new JPanel(new GridBagLayout()); center.add(controls); diff --git a/src/com/gitblit/client/RepositoriesPanel.java b/src/com/gitblit/client/RepositoriesPanel.java index cd3f46be..2994b763 100644 --- a/src/com/gitblit/client/RepositoriesPanel.java +++ b/src/com/gitblit/client/RepositoriesPanel.java @@ -277,7 +277,7 @@ public abstract class RepositoriesPanel extends JPanel { protected abstract void subscribeFeeds(List feeds); protected abstract void updateUsersTable(); - + protected abstract void updateTeamsTable(); protected void disableManagement() { @@ -357,6 +357,8 @@ public abstract class RepositoriesPanel extends JPanel { dialog.setTeams(gitblit.getTeamnames(), null); dialog.setRepositories(gitblit.getRepositories()); dialog.setFederationSets(gitblit.getFederationSets(), null); + dialog.setPreReceiveScripts(gitblit.getAvailableScripts(), null); + dialog.setPostReceiveScripts(gitblit.getAvailableScripts(), null); dialog.setVisible(true); final RepositoryModel newRepository = dialog.getRepository(); final List permittedUsers = dialog.getPermittedUsers(); @@ -369,7 +371,8 @@ public abstract class RepositoriesPanel extends JPanel { @Override protected Boolean doRequest() throws IOException { - boolean success = gitblit.createRepository(newRepository, permittedUsers, permittedTeams); + boolean success = gitblit.createRepository(newRepository, permittedUsers, + permittedTeams); if (success) { gitblit.refreshRepositories(); if (permittedUsers.size() > 0) { @@ -405,7 +408,8 @@ public abstract class RepositoriesPanel extends JPanel { * @param repository */ protected void editRepository(final RepositoryModel repository) { - EditRepositoryDialog dialog = new EditRepositoryDialog(gitblit.getProtocolVersion(), repository); + EditRepositoryDialog dialog = new EditRepositoryDialog(gitblit.getProtocolVersion(), + repository); dialog.setLocationRelativeTo(RepositoriesPanel.this); List usernames = gitblit.getUsernames(); List members = gitblit.getPermittedUsernames(repository); @@ -413,6 +417,8 @@ public abstract class RepositoriesPanel extends JPanel { dialog.setTeams(gitblit.getTeamnames(), gitblit.getPermittedTeamnames(repository)); dialog.setRepositories(gitblit.getRepositories()); dialog.setFederationSets(gitblit.getFederationSets(), repository.federationSets); + dialog.setPreReceiveScripts(gitblit.getAvailableScripts(), repository.preReceiveScripts); + dialog.setPostReceiveScripts(gitblit.getAvailableScripts(), repository.postReceiveScripts); dialog.setVisible(true); final RepositoryModel revisedRepository = dialog.getRepository(); final List permittedUsers = dialog.getPermittedUsers(); diff --git a/src/com/gitblit/models/ServerSettings.java b/src/com/gitblit/models/ServerSettings.java index 3aae2e3b..72a7f007 100644 --- a/src/com/gitblit/models/ServerSettings.java +++ b/src/com/gitblit/models/ServerSettings.java @@ -35,6 +35,8 @@ public class ServerSettings implements Serializable { private static final long serialVersionUID = 1L; + public List pushScripts; + public ServerSettings() { settings = new TreeMap(); }