Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Zanker2013-12-28 13:33:01 +0000
committerMatthias Sohn2014-04-02 13:01:43 +0000
commita466e17eee26dd5c1e107ca68639eee836f26a30 (patch)
tree8343d7e51da3e07ba39cbd0b9b5745061556e1c2 /org.eclipse.egit.mylyn.ui/src/org
parent8bf175abbb5f5a7b8faf62b1958b3894dc6f67e7 (diff)
downloadegit-a466e17eee26dd5c1e107ca68639eee836f26a30.tar.gz
egit-a466e17eee26dd5c1e107ca68639eee836f26a30.tar.xz
egit-a466e17eee26dd5c1e107ca68639eee836f26a30.zip
Provide extensibility for suggesting branch names
* Add new extension point for branch name suggestions * Add new extension to provide branch name suggestion from Mylyn task This change is needed to enable the automatic creation and checkout of branches based on the active task. Bug: 309578 Change-Id: I9e26d668617481026c81a05b6ea08b97e28f620b AlsoBy: Steffen Pingel <steffen.pingel@tasktop.com> AlsoBy: Manuel Doninger <manuel.doninger@googlemail.com> Signed-off-by: Steffen Pingel <steffen.pingel@tasktop.com> Signed-off-by: Gerd Zanker <gerd.zanker@web.de> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.mylyn.ui/src/org')
-rw-r--r--org.eclipse.egit.mylyn.ui/src/org/eclipse/egit/internal/mylyn/ui/commit/ActiveTaskBranchNameProvider.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/org.eclipse.egit.mylyn.ui/src/org/eclipse/egit/internal/mylyn/ui/commit/ActiveTaskBranchNameProvider.java b/org.eclipse.egit.mylyn.ui/src/org/eclipse/egit/internal/mylyn/ui/commit/ActiveTaskBranchNameProvider.java
new file mode 100644
index 0000000000..c45532beca
--- /dev/null
+++ b/org.eclipse.egit.mylyn.ui/src/org/eclipse/egit/internal/mylyn/ui/commit/ActiveTaskBranchNameProvider.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Chris Aniszczyk and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chris Aniszczyk <caniszczyk@gmail.com> - initial API and implementation
+ * Manuel Doninger <manuel.doninger@googlemail.com>
+ * Benjamin Muskalla <benjamin.muskalla@tasktop.com>
+ * Thorsten Kamann <thorsten@kamann.info>
+ * Steffen Pingel <steffen.pingel@tasktop.com>
+ *******************************************************************************/
+package org.eclipse.egit.internal.mylyn.ui.commit;
+
+import org.eclipse.egit.ui.IBranchNameProvider;
+import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.ui.TasksUi;
+
+/**
+ * A BranchNameProvider using description and title of the currently active task
+ * to suggest a branch name.
+ */
+public class ActiveTaskBranchNameProvider implements IBranchNameProvider {
+
+ /**
+ * @return the currently activated task or <code>null</code> if no task is
+ * activated
+ */
+ protected ITask getCurrentTask() {
+ return TasksUi.getTaskActivityManager().getActiveTask();
+ }
+
+ public String getBranchNameSuggestion() {
+ ITask task = getCurrentTask();
+ if (task == null)
+ return null;
+
+ String taskKey = task.getTaskKey();
+ if (taskKey == null)
+ taskKey = task.getTaskId();
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(TasksUiInternal.getTaskPrefix(task.getConnectorKind()));
+ sb.append(taskKey);
+ sb.append('-');
+ sb.append(task.getSummary());
+ return normalizeBranchName(sb.toString());
+ }
+
+ private String normalizeBranchName(String name) {
+ String normalized = name.trim()
+ .replaceAll("\\s+", "_").replaceAll("[^\\w-]", ""); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ if (normalized.length() > 30)
+ normalized = normalized.substring(0, 30);
+ return normalized;
+ }
+
+}
+

Back to the top