Control Panel update overhaul

We now always reset and remerge pull requests
This commit is contained in:
Cyberboss
2017-11-11 23:15:04 -05:00
parent 7059ce835d
commit bccabade23
5 changed files with 280 additions and 228 deletions
+36 -56
View File
@@ -31,7 +31,6 @@
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ControlPanel));
this.RepoBGW = new System.ComponentModel.BackgroundWorker();
this.FullUpdateWorker = new System.ComponentModel.BackgroundWorker();
this.ServerStartBGW = new System.ComponentModel.BackgroundWorker();
this.ChatPanel = new System.Windows.Forms.TabPage();
this.label5 = new System.Windows.Forms.Label();
@@ -83,15 +82,14 @@
this.WorldAnnounceLabel = new System.Windows.Forms.Label();
this.SecuritySelector = new System.Windows.Forms.ComboBox();
this.SecurityTitle = new System.Windows.Forms.Label();
this.ResetTestmerge = new System.Windows.Forms.Button();
this.RemoveAllTestMergesButton = new System.Windows.Forms.Button();
this.ServerPathLabel = new System.Windows.Forms.Label();
this.CompileCancelButton = new System.Windows.Forms.Button();
this.ProjectPathLabel = new System.Windows.Forms.Label();
this.PortLabel = new System.Windows.Forms.Label();
this.PortSelector = new System.Windows.Forms.NumericUpDown();
this.TestmergeButton = new System.Windows.Forms.Button();
this.UpdateMergeButton = new System.Windows.Forms.Button();
this.UpdateHardButton = new System.Windows.Forms.Button();
this.TestMergeManagerButton = new System.Windows.Forms.Button();
this.UpdateServerButton = new System.Windows.Forms.Button();
this.ServerGRestartButton = new System.Windows.Forms.Button();
this.ServerGStopButton = new System.Windows.Forms.CheckBox();
this.ServerRestartButton = new System.Windows.Forms.Button();
@@ -175,10 +173,6 @@
this.RepoBGW.WorkerReportsProgress = true;
this.RepoBGW.WorkerSupportsCancellation = true;
//
// FullUpdateWorker
//
this.FullUpdateWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.FullUpdateWorker_DoWork);
//
// ServerStartBGW
//
this.ServerStartBGW.DoWork += new System.ComponentModel.DoWorkEventHandler(this.ServerStartBGW_DoWork);
@@ -642,15 +636,14 @@
this.ServerPanel.Controls.Add(this.WorldAnnounceLabel);
this.ServerPanel.Controls.Add(this.SecuritySelector);
this.ServerPanel.Controls.Add(this.SecurityTitle);
this.ServerPanel.Controls.Add(this.ResetTestmerge);
this.ServerPanel.Controls.Add(this.RemoveAllTestMergesButton);
this.ServerPanel.Controls.Add(this.ServerPathLabel);
this.ServerPanel.Controls.Add(this.CompileCancelButton);
this.ServerPanel.Controls.Add(this.ProjectPathLabel);
this.ServerPanel.Controls.Add(this.PortLabel);
this.ServerPanel.Controls.Add(this.PortSelector);
this.ServerPanel.Controls.Add(this.TestmergeButton);
this.ServerPanel.Controls.Add(this.UpdateMergeButton);
this.ServerPanel.Controls.Add(this.UpdateHardButton);
this.ServerPanel.Controls.Add(this.TestMergeManagerButton);
this.ServerPanel.Controls.Add(this.UpdateServerButton);
this.ServerPanel.Controls.Add(this.ServerGRestartButton);
this.ServerPanel.Controls.Add(this.ServerGStopButton);
this.ServerPanel.Controls.Add(this.ServerRestartButton);
@@ -828,16 +821,16 @@
this.SecurityTitle.Text = "Security:";
this.SecurityTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// ResetTestmerge
// RemoveAllTestMergesButton
//
this.ResetTestmerge.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.ResetTestmerge.Location = new System.Drawing.Point(602, 95);
this.ResetTestmerge.Name = "ResetTestmerge";
this.ResetTestmerge.Size = new System.Drawing.Size(142, 28);
this.ResetTestmerge.TabIndex = 36;
this.ResetTestmerge.Text = "Reset and Recompile";
this.ResetTestmerge.UseVisualStyleBackColor = true;
this.ResetTestmerge.Click += new System.EventHandler(this.ResetTestmerge_Click);
this.RemoveAllTestMergesButton.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.RemoveAllTestMergesButton.Location = new System.Drawing.Point(489, 94);
this.RemoveAllTestMergesButton.Name = "RemoveAllTestMergesButton";
this.RemoveAllTestMergesButton.Size = new System.Drawing.Size(142, 28);
this.RemoveAllTestMergesButton.TabIndex = 36;
this.RemoveAllTestMergesButton.Text = "Remove All Test Merges";
this.RemoveAllTestMergesButton.UseVisualStyleBackColor = true;
this.RemoveAllTestMergesButton.Click += new System.EventHandler(this.RemoveAllTestMergesButton_Click);
//
// ServerPathLabel
//
@@ -912,38 +905,27 @@
0});
this.PortSelector.ValueChanged += new System.EventHandler(this.PortSelector_ValueChanged);
//
// TestmergeButton
// TestMergeManagerButton
//
this.TestmergeButton.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.TestmergeButton.Location = new System.Drawing.Point(456, 95);
this.TestmergeButton.Name = "TestmergeButton";
this.TestmergeButton.Size = new System.Drawing.Size(142, 28);
this.TestmergeButton.TabIndex = 24;
this.TestmergeButton.Text = "Test Merge Manager";
this.TestmergeButton.UseVisualStyleBackColor = true;
this.TestmergeButton.Click += new System.EventHandler(this.TestmergeButton_Click);
this.TestMergeManagerButton.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.TestMergeManagerButton.Location = new System.Drawing.Point(343, 94);
this.TestMergeManagerButton.Name = "TestMergeManagerButton";
this.TestMergeManagerButton.Size = new System.Drawing.Size(142, 28);
this.TestMergeManagerButton.TabIndex = 24;
this.TestMergeManagerButton.Text = "Test Merge Manager";
this.TestMergeManagerButton.UseVisualStyleBackColor = true;
this.TestMergeManagerButton.Click += new System.EventHandler(this.TestMergeManagerButton_Click);
//
// UpdateMergeButton
// UpdateServerButton
//
this.UpdateMergeButton.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.UpdateMergeButton.Location = new System.Drawing.Point(293, 95);
this.UpdateMergeButton.Name = "UpdateMergeButton";
this.UpdateMergeButton.Size = new System.Drawing.Size(157, 28);
this.UpdateMergeButton.TabIndex = 22;
this.UpdateMergeButton.Text = "Update (Keep Test Merges)";
this.UpdateMergeButton.UseVisualStyleBackColor = true;
this.UpdateMergeButton.Click += new System.EventHandler(this.UpdateMergeButton_Click);
//
// UpdateHardButton
//
this.UpdateHardButton.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.UpdateHardButton.Location = new System.Drawing.Point(130, 95);
this.UpdateHardButton.Name = "UpdateHardButton";
this.UpdateHardButton.Size = new System.Drawing.Size(157, 28);
this.UpdateHardButton.TabIndex = 21;
this.UpdateHardButton.Text = "Update (Reset Test Merges)";
this.UpdateHardButton.UseVisualStyleBackColor = true;
this.UpdateHardButton.Click += new System.EventHandler(this.UpdateHardButton_Click);
this.UpdateServerButton.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.UpdateServerButton.Location = new System.Drawing.Point(180, 94);
this.UpdateServerButton.Name = "UpdateServerButton";
this.UpdateServerButton.Size = new System.Drawing.Size(157, 28);
this.UpdateServerButton.TabIndex = 21;
this.UpdateServerButton.Text = "Update Server";
this.UpdateServerButton.UseVisualStyleBackColor = true;
this.UpdateServerButton.Click += new System.EventHandler(this.UpdateServerButton_Click);
//
// ServerGRestartButton
//
@@ -1775,7 +1757,6 @@
#endregion
private System.ComponentModel.BackgroundWorker RepoBGW;
private System.ComponentModel.BackgroundWorker FullUpdateWorker;
private System.ComponentModel.BackgroundWorker ServerStartBGW;
private System.Windows.Forms.TabPage ChatPanel;
private System.Windows.Forms.Label label5;
@@ -1822,15 +1803,14 @@
private System.Windows.Forms.Label WorldAnnounceLabel;
private System.Windows.Forms.ComboBox SecuritySelector;
private System.Windows.Forms.Label SecurityTitle;
private System.Windows.Forms.Button ResetTestmerge;
private System.Windows.Forms.Button RemoveAllTestMergesButton;
private System.Windows.Forms.Label ServerPathLabel;
private System.Windows.Forms.Button CompileCancelButton;
private System.Windows.Forms.Label ProjectPathLabel;
private System.Windows.Forms.Label PortLabel;
private System.Windows.Forms.NumericUpDown PortSelector;
private System.Windows.Forms.Button TestmergeButton;
private System.Windows.Forms.Button UpdateMergeButton;
private System.Windows.Forms.Button UpdateHardButton;
private System.Windows.Forms.Button TestMergeManagerButton;
private System.Windows.Forms.Button UpdateServerButton;
private System.Windows.Forms.Button ServerGRestartButton;
private System.Windows.Forms.CheckBox ServerGStopButton;
private System.Windows.Forms.Button ServerRestartButton;
@@ -120,9 +120,6 @@
<metadata name="RepoBGW.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="FullUpdateWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>843, 18</value>
</metadata>
<metadata name="ServerStartBGW.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>993, 18</value>
</metadata>
+188 -141
View File
@@ -1,5 +1,9 @@
using System;
using Octokit;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using TGServiceInterface;
using TGServiceInterface.Components;
@@ -8,27 +12,23 @@ namespace TGControlPanel
{
partial class ControlPanel
{
enum FullUpdateAction
{
UpdateHard,
UpdateMerge,
UpdateHardTestmerge,
Reset,
Testmerge,
}
FullUpdateAction fuAction;
ushort testmergePR;
string updateError;
bool updatingFields = false;
/// <summary>
/// <see cref="GitHubClient"/> used for checking the merged state of <see cref="PullRequest"/>s
/// </summary>
GitHubClient ghclient;
void InitServerPage()
{
LoadServerPage();
FullUpdateWorker.RunWorkerCompleted += FullUpdateWorker_RunWorkerCompleted;
projectNameText.LostFocus += ProjectNameText_LostFocus;
projectNameText.KeyDown += ProjectNameText_KeyDown;
ServerStartBGW.RunWorkerCompleted += ServerStartBGW_RunWorkerCompleted;
ghclient = new GitHubClient(new ProductHeaderValue(Assembly.GetExecutingAssembly().GetName().Name));
var config = Properties.Settings.Default;
if (!String.IsNullOrWhiteSpace(config.GitHubAPIKey))
ghclient.Credentials = new Credentials(Helpers.DecryptData(config.GitHubAPIKey, config.GitHubAPIKeyEntropy));
}
private void ServerStartBGW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
@@ -44,16 +44,6 @@ namespace TGControlPanel
UpdateProjectName();
}
private void FullUpdateWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (updateError != null)
MessageBox.Show(updateError);
UpdateHardButton.Enabled = true;
UpdateMergeButton.Enabled = true;
TestmergeButton.Enabled = true;
LoadServerPage();
}
private void CompileCancelButton_Click(object sender, EventArgs e)
{
var res = Interface.GetComponent<ITGCompiler>().Cancel();
@@ -82,10 +72,9 @@ namespace TGControlPanel
ServerRestartButton.Visible = RepoExists;
PortLabel.Visible = RepoExists;
ServerStopButton.Visible = RepoExists;
TestmergeButton.Visible = RepoExists;
UpdateHardButton.Visible = RepoExists;
UpdateMergeButton.Visible = RepoExists;
ResetTestmerge.Visible = RepoExists;
TestMergeManagerButton.Visible = RepoExists;
UpdateServerButton.Visible = RepoExists;
RemoveAllTestMergesButton.Visible = RepoExists;
WorldAnnounceField.Visible = RepoExists;
WorldAnnounceButton.Visible = RepoExists;
WorldAnnounceLabel.Visible = RepoExists;
@@ -151,6 +140,9 @@ namespace TGControlPanel
if (!projectNameText.Focused)
projectNameText.Text = DM.ProjectName();
UpdateServerButton.Enabled = false;
TestMergeManagerButton.Enabled = false;
RemoveAllTestMergesButton.Enabled = false;
switch (DM.GetStatus())
{
case CompilerStatus.Compiling:
@@ -170,6 +162,9 @@ namespace TGControlPanel
initializeButton.Enabled = true;
compileButton.Enabled = true;
CompileCancelButton.Enabled = false;
UpdateServerButton.Enabled = true;
TestMergeManagerButton.Enabled = true;
RemoveAllTestMergesButton.Enabled = true;
break;
case CompilerStatus.Uninitialized:
CompilerStatusLabel.Text = "Uninitialized";
@@ -211,35 +206,6 @@ namespace TGControlPanel
Interface.GetComponent<ITGDreamDaemon>().SetPort((ushort)PortSelector.Value);
}
private void RunServerUpdate(FullUpdateAction fua, ushort tm = 0)
{
if (FullUpdateWorker.IsBusy)
return;
testmergePR = tm;
fuAction = fua;
initializeButton.Enabled = false;
compileButton.Enabled = false;
UpdateHardButton.Enabled = false;
UpdateMergeButton.Enabled = false;
TestmergeButton.Enabled = false;
switch (fuAction)
{
case FullUpdateAction.Testmerge:
CompilerStatusLabel.Text = String.Format("Testmerging pull request #{0}...", testmergePR);
break;
case FullUpdateAction.UpdateHard:
CompilerStatusLabel.Text = String.Format("Updating Server (RESET)...");
break;
case FullUpdateAction.UpdateMerge:
CompilerStatusLabel.Text = String.Format("Updating Server (MERGE)...");
break;
case FullUpdateAction.UpdateHardTestmerge:
CompilerStatusLabel.Text = String.Format("Updating and testmerging pull request #{0}...", testmergePR);
break;
}
FullUpdateWorker.RunWorkerAsync();
}
private void ServerPageRefreshButton_Click(object sender, EventArgs e)
{
LoadServerPage();
@@ -320,100 +286,181 @@ namespace TGControlPanel
Interface.GetComponent<ITGDreamDaemon>().RequestRestart();
}
private void FullUpdateWorker_DoWork(object sender, DoWorkEventArgs e)
{
try
{
var Repo = Interface.GetComponent<ITGRepository>();
var DM = Interface.GetComponent<ITGCompiler>();
switch (fuAction)
{
case FullUpdateAction.Testmerge:
updateError = Repo.MergePullRequest(testmergePR);
if (updateError == null)
{
Repo.GenerateChangelog(out updateError);
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
}
break;
case FullUpdateAction.UpdateHard:
updateError = Repo.Update(true);
if (updateError == null)
{
Repo.GenerateChangelog(out updateError);
if (updateError == null)
updateError = Repo.SynchronizePush();
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
}
break;
case FullUpdateAction.UpdateHardTestmerge:
updateError = Repo.Update(true);
if (updateError == null)
{
Repo.GenerateChangelog(out updateError);
if (updateError == null)
updateError = Repo.SynchronizePush();
updateError = Repo.MergePullRequest(testmergePR);
if (updateError == null)
{
Repo.GenerateChangelog(out updateError);
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
}
}
break;
case FullUpdateAction.UpdateMerge:
updateError = Repo.Update(false);
if (updateError == null)
{
Repo.GenerateChangelog(out updateError);
if (updateError == null)
Repo.SynchronizePush(); //not an error 99% of the time if this fails, just a dirty tree
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
}
break;
case FullUpdateAction.Reset:
updateError = Repo.Reset(true);
if (updateError == null)
{
Repo.GenerateChangelog(out updateError);
updateError = DM.Compile(true) ? updateError : "Compilation failed!";
}
break;
}
}
catch (Exception ex)
{
Program.ServiceDisconnectException(ex);
}
}
private void ResetTestmerge_Click(object sender, EventArgs e)
{
RunServerUpdate(FullUpdateAction.Reset);
}
private void UpdateHardButton_Click(object sender, System.EventArgs e)
{
RunServerUpdate(FullUpdateAction.UpdateHard);
}
private void UpdateMergeButton_Click(object sender, System.EventArgs e)
{
RunServerUpdate(FullUpdateAction.UpdateMerge);
}
/// <summary>
/// Launches the <see cref="TestMergeManager"/>
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The <see cref="EventArgs"/></param>
void TestmergeButton_Click(object sender, System.EventArgs e)
void TestMergeManagerButton_Click(object sender, System.EventArgs e)
{
using (var TMM = new TestMergeManager(Interface))
using (var TMM = new TestMergeManager(Interface, ghclient))
TMM.ShowDialog();
LoadServerPage();
}
/// <summary>
/// Calls <see cref="UpdateServer"/>
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The <see cref="EventArgs"/></param>
void UpdateServerButton_Click(object sender, EventArgs e)
{
UpdateServer();
}
/// <summary>
/// Calls <see cref="ITGRepository.Update(bool)"/> with a <see langword="true"/> parameter, re-merging any current <see cref="PullRequest"/>s at their current commit, calls <see cref="ITGRepository.GenerateChangelog(out string)"/> and <see cref="ITGRepository.SynchronizePush"/>, and starts the <see cref="ITGCompiler.Compile(bool)"/> prompting the user with any errors that may occur. Merged <see cref="PullRequest"/>s are not remerged
/// </summary>
async void UpdateServer()
{
try
{
UseWaitCursor = true;
Enabled = false;
try
{
string res = null;
var repo = Interface.GetComponent<ITGRepository>();
var pulls = await Task.Factory.StartNew(() => repo.MergedPullRequests(out res));
if (pulls == null)
{
MessageBox.Show(res);
return;
}
List<Task<PullRequest>> pullsRequests = null;
if(Program.GetRepositoryRemote(repo, out string remoteOwner, out string remoteName)) {
//find out which of the PRs have been merged
pullsRequests = new List<Task<PullRequest>>();
foreach (var I in pulls)
pullsRequests.Add(ghclient.PullRequest.Get(remoteOwner, remoteName, I.Number));
}
res = await Task.Factory.StartNew(() => repo.Update(true));
if(res != null)
{
MessageBox.Show(res, "Error updating repository");
return;
}
await Task.Factory.StartNew(() => repo.GenerateChangelog(out res));
if (res != null)
{
MessageBox.Show(res, "Error generating changelog");
return;
}
res = await Task.Factory.StartNew(() => repo.SynchronizePush());
if (res != null)
{
MessageBox.Show(res, "Error synchronizing commits");
return;
}
if (pullsRequests != null)
Task.WaitAll(pullsRequests.ToArray());
foreach (var I in pullsRequests)
if (I.Result.Merged)
pulls.RemoveAll(x => x.Number == I.Result.Number);
var results = new List<string>();
foreach (var I in pulls) {
retry:
await Task.Factory.StartNew(() => res = repo.MergePullRequest(I.Number, I.Sha));
if (res != null)
switch(MessageBox.Show(res, "Error Re-merging Pull Request", MessageBoxButtons.AbortRetryIgnore))
{
case DialogResult.Abort:
return;
case DialogResult.Retry:
goto retry;
}
}
await Task.Factory.StartNew(() => Interface.GetComponent<ITGCompiler>().Compile(pulls.Count != 1));
if (res != null)
MessageBox.Show(res, "Error starting compile!");
}
finally
{
UseWaitCursor = false;
Enabled = true;
}
}
catch (ForbiddenException)
{
if (ghclient.Credentials.AuthenticationType == AuthenticationType.Anonymous)
{
if (Program.RateLimitPrompt(ghclient))
UpdateServer();
return;
}
else
throw;
}
LoadServerPage();
}
/// <summary>
/// Calls <see cref="ITGRepository.Reset(bool)"/> with a <see langword="true"/> parameter, calls <see cref="ITGRepository.GenerateChangelog(out string)"/>, and starts the <see cref="ITGCompiler.Compile(bool)"/> prompting the user with any errors that may occur.
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The <see cref="EventArgs"/></param>
async void RemoveAllTestMergesButton_Click(object sender, EventArgs e)
{
try
{
UseWaitCursor = true;
Enabled = false;
try
{
var repo = Interface.GetComponent<ITGRepository>();
var res = await Task.Factory.StartNew(() => repo.Reset(true));
if (res != null)
{
MessageBox.Show(res, "Error resetting repository");
return;
}
await Task.Factory.StartNew(() => repo.GenerateChangelog(out res));
if (res != null)
{
MessageBox.Show(res, "Error generating changelog");
return;
}
await Task.Factory.StartNew(() => Interface.GetComponent<ITGCompiler>().Compile(false));
if (res != null)
MessageBox.Show(res, "Error starting compile!");
}
finally
{
UseWaitCursor = false;
Enabled = true;
}
}
catch (ForbiddenException)
{
if (ghclient.Credentials.AuthenticationType == AuthenticationType.Anonymous)
{
if (Program.RateLimitPrompt(ghclient))
UpdateServer();
return;
}
else
throw;
}
LoadServerPage();
}
private void SecuritySelector_SelectedIndexChanged(object sender, EventArgs e)
{
if (!updatingFields)