Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit c14fb8d

Browse files
authored
Merge pull request #361 from github-for-unity/fixes/long-publish-error-message
Fixing PublishView to support long error messages
2 parents 090f950 + 2dad144 commit c14fb8d

File tree

2 files changed

+33
-76
lines changed

2 files changed

+33
-76
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/InitProjectView.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class InitProjectView : Subview
1313

1414
[SerializeField] private UserSettingsView userSettingsView = new UserSettingsView();
1515
[SerializeField] private GitPathView gitPathView = new GitPathView();
16-
[SerializeField] private bool isBusy;
16+
17+
[NonSerialized] private bool isBusy;
1718

1819
[NonSerialized] private string errorMessage;
1920
[NonSerialized] private bool isUserDataPresent;

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PublishView.cs

Lines changed: 31 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace GitHub.Unity
99
{
1010
class PublishView : Subview
1111
{
12-
private static readonly Vector2 viewSize = new Vector2(300, 250);
12+
private static readonly Vector2 viewSize = new Vector2(400, 350);
1313

1414
private const string WindowTitle = "Publish";
1515
private const string Header = "Publish this repository to GitHub";
@@ -20,7 +20,9 @@ class PublishView : Subview
2020
private const string SelectedOwnerLabel = "Owner";
2121
private const string RepositoryNameLabel = "Repository Name";
2222
private const string DescriptionLabel = "Description";
23-
private const string CreatePrivateRepositoryLabel = "Create as a private repository";
23+
private const string CreatePrivateRepositoryLabel = "Make repository private";
24+
private const string PublishLimitPrivateRepositoriesError = "You are currently at your limit of private repositories";
25+
private const string PublishToGithubLabel = "Publish to GitHub";
2426

2527
[SerializeField] private string username;
2628
[SerializeField] private string[] owners = { OwnersDefaultText };
@@ -139,81 +141,18 @@ private void LoadOrganizations()
139141

140142
public override void OnGUI()
141143
{
142-
GUILayout.BeginHorizontal(Styles.AuthHeaderBoxStyle);
143-
{
144-
GUILayout.BeginVertical(GUILayout.Width(16));
145-
{
146-
GUILayout.Space(9);
147-
GUILayout.Label(Styles.BigLogo, GUILayout.Height(20), GUILayout.Width(20));
148-
}
149-
GUILayout.EndVertical();
150-
151-
GUILayout.BeginVertical();
152-
{
153-
GUILayout.Space(11);
154-
GUILayout.Label(Title, EditorStyles.boldLabel);
155-
}
156-
GUILayout.EndVertical();
157-
}
158-
GUILayout.EndHorizontal();
159-
160-
GUILayout.Space(Styles.PublishViewSpacingHeight);
144+
GUILayout.Label(PublishToGithubLabel, EditorStyles.boldLabel);
161145

162146
EditorGUI.BeginDisabledGroup(isBusy);
163147
{
164-
GUILayout.BeginHorizontal();
165-
{
166-
GUILayout.BeginVertical();
167-
{
168-
GUILayout.Label(SelectedOwnerLabel);
169-
selectedOwner = EditorGUILayout.Popup(selectedOwner, owners);
170-
}
171-
GUILayout.EndVertical();
172-
173-
GUILayout.BeginVertical(GUILayout.Width(8));
174-
{
175-
GUILayout.Space(20);
176-
GUILayout.Label("/");
177-
}
178-
GUILayout.EndVertical();
179-
180-
GUILayout.BeginVertical();
181-
{
182-
GUILayout.Label(RepositoryNameLabel);
183-
repoName = EditorGUILayout.TextField(repoName);
184-
}
185-
GUILayout.EndVertical();
186-
}
187-
GUILayout.EndHorizontal();
188-
189-
GUILayout.Label(DescriptionLabel);
190-
repoDescription = EditorGUILayout.TextField(repoDescription);
191-
GUILayout.Space(Styles.PublishViewSpacingHeight);
192-
193-
GUILayout.BeginVertical();
194-
{
195-
GUILayout.BeginHorizontal();
196-
{
197-
togglePrivate = GUILayout.Toggle(togglePrivate, CreatePrivateRepositoryLabel);
198-
}
199-
GUILayout.EndHorizontal();
148+
selectedOwner = EditorGUILayout.Popup(SelectedOwnerLabel, selectedOwner, owners);
149+
repoName = EditorGUILayout.TextField(RepositoryNameLabel, repoName);
150+
repoDescription = EditorGUILayout.TextField(DescriptionLabel, repoDescription);
200151

201-
GUILayout.BeginHorizontal();
202-
{
203-
GUILayout.Space(Styles.PublishViewSpacingHeight);
204-
var repoPrivacyExplanation = togglePrivate ? PrivateRepoMessage : PublicRepoMessage;
205-
GUILayout.Label(repoPrivacyExplanation, Styles.LongMessageStyle);
206-
}
207-
GUILayout.EndHorizontal();
208-
}
209-
GUILayout.EndVertical();
152+
togglePrivate = EditorGUILayout.Toggle(CreatePrivateRepositoryLabel, togglePrivate);
210153

211-
GUILayout.Space(Styles.PublishViewSpacingHeight);
212-
213-
if (error != null)
214-
GUILayout.Label(error, Styles.ErrorLabel);
215-
216-
GUILayout.FlexibleSpace();
154+
var repoPrivacyExplanation = togglePrivate ? PrivateRepoMessage : PublicRepoMessage;
155+
EditorGUILayout.HelpBox(repoPrivacyExplanation, MessageType.None);
217156

218157
GUILayout.BeginHorizontal();
219158
{
@@ -235,11 +174,11 @@ public override void OnGUI()
235174
Description = cleanRepoDescription
236175
}, (repository, ex) =>
237176
{
238-
Logger.Trace("Create Repository Callback");
239-
240177
if (ex != null)
241178
{
242-
error = ex.Message;
179+
Logger.Error(ex, "Repository Create Error Type:{0}", ex.GetType().ToString());
180+
181+
error = GetPublishErrorMessage(ex);
243182
isBusy = false;
244183
return;
245184
}
@@ -251,6 +190,8 @@ public override void OnGUI()
251190
return;
252191
}
253192

193+
Logger.Trace("Repository Created");
194+
254195
GitClient.RemoteAdd("origin", repository.CloneUrl)
255196
.Then(GitClient.Push("origin", Repository.CurrentBranch.Value.Name))
256197
.ThenInUI(Finish)
@@ -261,10 +202,25 @@ public override void OnGUI()
261202
}
262203
GUILayout.EndHorizontal();
263204
GUILayout.Space(10);
205+
206+
if (error != null)
207+
EditorGUILayout.HelpBox(error, MessageType.Error);
208+
209+
GUILayout.FlexibleSpace();
264210
}
265211
EditorGUI.EndDisabledGroup();
266212
}
267213

214+
private string GetPublishErrorMessage(Exception ex)
215+
{
216+
if (ex.Message.StartsWith(PublishLimitPrivateRepositoriesError))
217+
{
218+
return PublishLimitPrivateRepositoriesError;
219+
}
220+
221+
return ex.Message;
222+
}
223+
268224
public override bool IsBusy
269225
{
270226
get { return isBusy; }

0 commit comments

Comments
 (0)