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)
+47
View File
@@ -1,6 +1,7 @@
using System;
using System.Windows.Forms;
using TGServiceInterface;
using TGServiceInterface.Components;
namespace TGControlPanel
{
@@ -73,5 +74,51 @@ namespace TGControlPanel
return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : null;
}
/// <summary>
/// Prompts the user to open the <see cref="GitHubLoginPrompt"/> explaining the API rate limit
/// </summary>
/// <param name="client">The <see cref="Octokit.GitHubClient"/> to use</param>
/// <returns><see langword="true"/> if the <see cref="GitHubLoginPrompt"/> ran and returned a <see cref="DialogResult.OK"/>, <see langword="false"/> otherwise</returns>
public static bool RateLimitPrompt(Octokit.GitHubClient client)
{
if (MessageBox.Show("You seem to have hit the rate limit of 60 requests per hour of the GitHub API for anonymous requests. Would you like to enter credentials to bypass this?", "Rate limited", MessageBoxButtons.YesNo) != DialogResult.Yes)
return false;
using (var D = new GitHubLoginPrompt(client))
return D.ShowDialog() == DialogResult.OK;
}
/// <summary>
/// Gets the <paramref name="owner"/> and <paramref name="name"/> of a given <paramref name="repo"/>'s remote. Shows an error if the target remote isn't GitHub
/// </summary>
/// <param name="repo">The <see cref="ITGRepository"/> to get the remote of</param>
/// <param name="owner">The owner of the remote <see cref="Octokit.Repository"/></param>
/// <param name="name">The remote <see cref="Octokit.Repository.Name"/></param>
/// <returns><see langword="true"/> if <paramref name="repo"/>'s remote was a valid GitHub <see cref="Octokit.Repository"/>, <see langword="false"/> otherwise and the user was prompted</returns>
public static bool GetRepositoryRemote(ITGRepository repo, out string owner, out string name)
{
string remote = null;
remote = repo.GetRemote(out string error);
if (remote == null)
{
MessageBox.Show(String.Format("Error retrieving remote repository: {0}", error));
owner = null;
name = null;
return false;
}
if (!remote.Contains("github.com"))
{
MessageBox.Show("Pull request support is only available for github based repositories!", "Error");
owner = null;
name = null;
return false;
}
//Assume standard gh format: [(git)|(https)]://github.com/owner/repo(.git)[0-1]
var splits = remote.Split('/');
name = splits[splits.Length - 1];
owner = splits[splits.Length - 2];
return true;
}
}
}
+9 -28
View File
@@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using TGServiceInterface;
@@ -39,13 +38,15 @@ namespace TGControlPanel
/// <summary>
/// Construct a <see cref="TestMergeManager"/>
/// </summary>
public TestMergeManager(IInterface interfaceToUse)
/// <param name="interfaceToUse">The <see cref="IInterface"/> to use for managing the <see cref="ITGInstance"/></param>
/// <param name="clientToUse">The <see cref="GitHubClient"/> to use for getting pull request information</param>
public TestMergeManager(IInterface interfaceToUse, GitHubClient clientToUse)
{
InitializeComponent();
DialogResult = DialogResult.Cancel;
UpdateToRemoteRadioButton.Checked = true;
currentInterface = interfaceToUse;
client = new GitHubClient(new ProductHeaderValue(Assembly.GetExecutingAssembly().GetName().Name));
client = clientToUse;
Load += PullRequestManager_Load;
}
@@ -54,9 +55,6 @@ namespace TGControlPanel
/// </summary>
async void LoadPullRequests()
{
var config = Properties.Settings.Default;
if (!String.IsNullOrWhiteSpace(config.GitHubAPIKey))
client.Credentials = new Credentials(Helpers.DecryptData(config.GitHubAPIKey, config.GitHubAPIKeyEntropy));
try
{
Enabled = false;
@@ -112,13 +110,10 @@ namespace TGControlPanel
}
catch (ForbiddenException)
{
if (client.Credentials.AuthenticationType == AuthenticationType.Anonymous) //assume request limit hit
if (client.Credentials.AuthenticationType == AuthenticationType.Anonymous) //assume request limit hit
{
if (MessageBox.Show("You seem to have hit the rate limit of 60 requests per hour of the GitHub API for anonymous requests. Would you like to enter credentials to bypass this?", "Rate limited", MessageBoxButtons.YesNo) != DialogResult.Yes)
return;
using (var D = new GitHubLoginPrompt(client))
if (D.ShowDialog() == DialogResult.OK)
LoadPullRequests();
if(Program.RateLimitPrompt(client))
LoadPullRequests();
}
else
throw;
@@ -167,28 +162,14 @@ namespace TGControlPanel
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The <see cref="EventArgs"/></param>
async void PullRequestManager_Load(object sender, EventArgs e)
void PullRequestManager_Load(object sender, EventArgs e)
{
var repo = currentInterface.GetComponent<ITGRepository>();
string remote = null, error = null;
await WrapServerOp(() => remote = repo.GetRemote(out error));
if (remote == null)
if(!Program.GetRepositoryRemote(repo, out repoOwner, out repoName))
{
MessageBox.Show(String.Format("Error retrieving remote repository: {0}", error));
Close();
return;
}
if (!remote.Contains("github.com"))
{
MessageBox.Show("Pull request support is only available for github based repositories!", "Error");
Close();
return;
}
//Assume standard gh format: [(git)|(https)]://github.com/owner/repo(.git)[0-1]
var splits = remote.Split('/');
repoName = splits[splits.Length - 1];
repoOwner = splits[splits.Length - 2];
Enabled = true;
UseWaitCursor = true;