mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
124 lines
3.9 KiB
C#
124 lines
3.9 KiB
C#
|
using System.Text.RegularExpressions;
|
||
|
using System.Threading.Tasks;
|
||
|
using System.Windows;
|
||
|
using System.Windows.Controls;
|
||
|
|
||
|
namespace SourceGit.UI {
|
||
|
|
||
|
/// <summary>
|
||
|
/// Dialog to initialize git flow.
|
||
|
/// </summary>
|
||
|
public partial class GitFlowSetup : UserControl {
|
||
|
private Git.Repository repo = null;
|
||
|
private Regex regex = new Regex(@"^[\w\-/\.]+$");
|
||
|
|
||
|
/// <summary>
|
||
|
/// Constructor.
|
||
|
/// </summary>
|
||
|
/// <param name="opened"></param>
|
||
|
public GitFlowSetup(Git.Repository opened) {
|
||
|
repo = opened;
|
||
|
InitializeComponent();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Open this dialog.
|
||
|
/// </summary>
|
||
|
/// <param name="repo"></param>
|
||
|
public static void Show(Git.Repository repo) {
|
||
|
PopupManager.Show(new GitFlowSetup(repo));
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Start to initialize git-flow.
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private async void Sure(object sender, RoutedEventArgs e) {
|
||
|
PopupManager.Lock();
|
||
|
|
||
|
var master = txtMaster.Text;
|
||
|
var dev = txtDevelop.Text;
|
||
|
var feature = txtFeature.Text;
|
||
|
var release = txtRelease.Text;
|
||
|
var hotfix = txtHotfix.Text;
|
||
|
var version = txtVersion.Text;
|
||
|
|
||
|
await Task.Run(() => repo.EnableGitFlow(master, dev, feature, release, hotfix, version));
|
||
|
PopupManager.Close(true);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Cancel.
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void Cancel(object sender, RoutedEventArgs e) {
|
||
|
PopupManager.Close();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Validate input names.
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
private void ValidateNames(object sender, TextChangedEventArgs e) {
|
||
|
if (!IsLoaded) return;
|
||
|
|
||
|
var master = txtMaster.Text;
|
||
|
var dev = txtDevelop.Text;
|
||
|
var feature = txtFeature.Text;
|
||
|
var release = txtRelease.Text;
|
||
|
var hotfix = txtHotfix.Text;
|
||
|
|
||
|
if (!ValidateBranch("Production", master)) return;
|
||
|
if (!ValidateBranch("Development", dev)) return;
|
||
|
|
||
|
if (dev == master) {
|
||
|
txtValidation.Content = "Development branch is same with production!";
|
||
|
btnSure.IsEnabled = false;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (!ValidatePrefix("Feature", feature)) return;
|
||
|
if (!ValidatePrefix("Release", release)) return;
|
||
|
if (!ValidatePrefix("Hotfix", hotfix)) return;
|
||
|
|
||
|
txtValidation.Content = "";
|
||
|
btnSure.IsEnabled = true;
|
||
|
}
|
||
|
|
||
|
private bool ValidateBranch(string type, string name) {
|
||
|
if (string.IsNullOrEmpty(name)) {
|
||
|
txtValidation.Content = $"{type} branch name can't be empty";
|
||
|
btnSure.IsEnabled = false;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if (!regex.IsMatch(name)) {
|
||
|
txtValidation.Content = $"{type} branch name contains invalid characters.";
|
||
|
btnSure.IsEnabled = false;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
private bool ValidatePrefix(string type, string prefix) {
|
||
|
if (string.IsNullOrEmpty(prefix)) {
|
||
|
txtValidation.Content = $"{type} prefix is required!";
|
||
|
btnSure.IsEnabled = false;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if (!regex.IsMatch(prefix)) {
|
||
|
txtValidation.Content = $"{type} prefix contains invalid characters.";
|
||
|
btnSure.IsEnabled = false;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|