This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathRepositoryFormViewModel.cs
More file actions
97 lines (85 loc) · 3.29 KB
/
RepositoryFormViewModel.cs
File metadata and controls
97 lines (85 loc) · 3.29 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Reactive.Linq;
using System.Text.RegularExpressions;
using System.Windows.Input;
using GitHub.Models;
using GitHub.Validation;
using ReactiveUI;
namespace GitHub.ViewModels
{
/// <summary>
/// Base class for the Repository publish/create dialogs. It represents the details about the repository itself.
/// </summary>
public abstract class RepositoryFormViewModel : ViewModelBase
{
readonly ObservableAsPropertyHelper<string> safeRepositoryName;
protected RepositoryFormViewModel()
{
safeRepositoryName = this.WhenAny(x => x.RepositoryName, x => x.Value)
.Select(x => x != null ? GetSafeRepositoryName(x) : null)
.ToProperty(this, x => x.SafeRepositoryName);
}
string description;
/// <summary>
/// Description to set on the repo (optional)
/// </summary>
public string Description
{
get { return description; }
set { this.RaiseAndSetIfChanged(ref description, value); }
}
bool keepPrivate;
/// <summary>
/// Make the new repository private
/// </summary>
public bool KeepPrivate
{
get { return keepPrivate; }
set { this.RaiseAndSetIfChanged(ref keepPrivate, value); }
}
string repositoryName;
/// <summary>
/// Name of the repository as typed by user
/// </summary>
public string RepositoryName
{
get { return repositoryName; }
set { this.RaiseAndSetIfChanged(ref repositoryName, value); }
}
public ReactivePropertyValidator<(string repositoryName, IConnection connection, IAccount account)> RepositoryNameValidator { get; protected set; }
/// <summary>
/// Name of the repository after fixing it to be safe (dashes instead of spaces, etc)
/// </summary>
public string SafeRepositoryName
{
get { return safeRepositoryName.Value; }
}
public ReactivePropertyValidator<(string repositoryName, IConnection connection, IAccount account)> SafeRepositoryNameWarningValidator { get; protected set; }
IAccount selectedAccount;
/// <summary>
/// Account where the repository is going to be created on
/// </summary>
public IAccount SelectedAccount
{
get { return selectedAccount; }
set { this.RaiseAndSetIfChanged(ref selectedAccount, value); }
}
// These are the characters which are permitted when creating a repository name on GitHub The Website
static readonly Regex invalidRepositoryCharsRegex = new Regex(@"[^0-9A-Za-z_\.\-]", RegexOptions.ECMAScript);
/// <summary>
/// Given a repository name, returns a safe version with invalid characters replaced with dashes.
/// </summary>
protected static string GetSafeRepositoryName(string name)
{
return invalidRepositoryCharsRegex.Replace(name, "-");
}
protected virtual Octokit.NewRepository GatherRepositoryInfo()
{
return new Octokit.NewRepository(RepositoryName)
{
Description = Description,
Private = KeepPrivate
};
}
}
}