blob: c45532beca1dc327bd73eb12155c521c050fccaf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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;
}
}
|