Skip to content

Commit

Permalink
V3.1.18 - Github issues are now not created if they already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan committed Dec 13, 2022
1 parent 451bcd1 commit a499453
Show file tree
Hide file tree
Showing 25 changed files with 655 additions and 443 deletions.
21 changes: 19 additions & 2 deletions Business Logic Layer/BLIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ public static void StopSound()
}
}

public static string AnonymizePath(string input)
{
try
{
string newString = "";
foreach (string part in input.Split('\\'))
{
newString += @"*\";
}
return $"{Path.GetPathRoot(input)}{newString}{Path.GetFileName(input)}";
}
catch(Exception ex)
{
BLIO.WriteError(ex, $"Failed to anonymize input {input}");
return input;
}
}
/// <summary>
/// Plays a sound
/// </summary>
Expand Down Expand Up @@ -226,7 +243,7 @@ public static void WriteError(Exception ex, string message, [CallerMemberName] s
}
}

public static async Task<JObject> HttpRequest(string method, string uri, string headers = "{ }", string accept = "", string contentType = "", string body = "{ }")
public static async Task<object> HttpRequest(string method, string uri, string headers = "{ }", string accept = "", string contentType = "", string body = "{ }")
{
try
{
Expand Down Expand Up @@ -278,7 +295,7 @@ public static async Task<JObject> HttpRequest(string method, string uri, string
{
string bod = await reader.ReadToEndAsync();
Log(method + " succeeded with status code " + response.StatusCode.ToString());
return (JObject)JsonConvert.DeserializeObject(bod);
return JsonConvert.DeserializeObject(bod);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Business Logic Layer/BLReminder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ public static string ToString(Reminder rem)
mess += "DayOfMonth: " + rem.DayOfMonth + "\r\n";
mess += "EveryXCustom: " + rem.EveryXCustom + "\r\n";
mess += "RepeatDays: " + rem.RepeatDays + "\r\n";
mess += "SoundFilePath: "+ rem.SoundFilePath + "\r\n";
mess += "SoundFilePath: "+ BLIO.AnonymizePath(rem.SoundFilePath) + "\r\n";
mess += "PostponeDate: " + rem.PostponeDate + "\r\n";
mess += "Hide: " + rem.Hide + "\r\n";
mess += "Corrupted: " + rem.Corrupted + "\r\n";
Expand Down
4 changes: 2 additions & 2 deletions Business Logic Layer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.5.5")]
[assembly: AssemblyFileVersion("2.5.5")]
[assembly: AssemblyVersion("2.5.6")]
[assembly: AssemblyFileVersion("2.5.6")]
4 changes: 2 additions & 2 deletions Data Access Layer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.5.1")]
[assembly: AssemblyFileVersion("2.5.1")]
[assembly: AssemblyVersion("2.5.2")]
[assembly: AssemblyFileVersion("2.5.2")]
4 changes: 2 additions & 2 deletions MaterialSkin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.2")]
[assembly: AssemblyFileVersion("1.0.0.2")]
[assembly: AssemblyVersion("1.0.0.3")]
[assembly: AssemblyFileVersion("1.0.0.3")]
54 changes: 34 additions & 20 deletions RemindMe/Forms/MaterialForms/MaterialAdvancedReminderForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,47 @@ public partial class MaterialAdvancedReminderForm : MaterialForm
private MUCNewReminder ucParent;
public MaterialAdvancedReminderForm(MUCNewReminder parent)
{
this.Opacity = 0;
MaterialSkin.MaterialSkinManager.Instance.AddFormToManage(this);
InitializeComponent();
try
{
this.Opacity = 0;
MaterialSkin.MaterialSkinManager.Instance.AddFormToManage(this);
InitializeComponent();

ucParent = parent;
mucHttpRequest = new MUCHTTPRequest(parent);
tabHTTP.Controls.Add(mucHttpRequest);
ucParent = parent;
mucHttpRequest = new MUCHTTPRequest(parent);
tabHTTP.Controls.Add(mucHttpRequest);

this.MaximumSize = this.Size;
this.MinimumSize = this.Size;
BLIO.Log("Advanced reminder form created!");
this.MaximumSize = this.Size;
this.MinimumSize = this.Size;
BLIO.Log("Advanced reminder form created!");
}
catch (Exception ex)
{
BLIO.WriteError(ex, "Initialization of MaterialAdvancedReminderForm failed!");
}
}

private void MaterialAdvancedReminderForm_Load(object sender, EventArgs e)
{
BLIO.Log("Advanced Reminder Form loaded");
MaterialForm1 remindme = (MaterialForm1)Application.OpenForms["MaterialForm1"];
if (remindme != null)
{
try
{
BLIO.Log("Advanced Reminder Form loaded");
MaterialForm1 remindme = (MaterialForm1)Application.OpenForms["MaterialForm1"];
if (remindme != null)
{
//Place the message box in the middle of remindme
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(remindme.Location.X + ((remindme.Width / 2) - this.Width / 2), remindme.Location.Y + ((remindme.Height / 2) - (this.Height / 2)));
}
else
this.StartPosition = FormStartPosition.CenterScreen;

tmrFadeIn.Start();
}
catch (Exception ex)
{
//Place the message box in the middle of remindme
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(remindme.Location.X + ((remindme.Width / 2) - this.Width / 2), remindme.Location.Y + ((remindme.Height / 2) - (this.Height / 2)));
BLIO.WriteError(ex, "MaterialAdvancedReminderForm_Load failed!");
}
else
this.StartPosition = FormStartPosition.CenterScreen;

tmrFadeIn.Start();
}

public string BatchScript
Expand Down
85 changes: 64 additions & 21 deletions RemindMe/Forms/MaterialForms/MaterialExceptionPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,28 +188,71 @@ private void lblMessage_SizeChanged(object sender, EventArgs e)
tbFeedback.Location = new Point(tbFeedback.Location.X, (lblMessage.Location.Y + lblMessage.Height) + 5);
}

private bool CreateIssue(Exception ex, string description, string customMessage)
private string GitHeader
{
string t = "Au", tt = "thorization";
string x = "Be", xx = "arer ";
string y = "";
var headers = "{\""+ t + tt + "\": \""+ x + xx + y + "\"}";

BLIO.DumpLogTxt();
string log = System.IO.File.ReadAllText(IOVariables.systemLog).Replace(Environment.NewLine, "<br />");
string title = JsonConvert.ToString($"[Automatic] Error occured: {description}");
string body = JsonConvert.ToString($"**RemindMe version**: {IOVariables.RemindMeVersion}<br /><br />**Stacktrace**: {ex.StackTrace}<br /><br />**Custom user feedback**: {customMessage}<br /><br />**RemindMe Log:**<br />{log}");

var resp = BLIO.HttpRequest(
"POST",
"https://api.github.com/repos/Stefangansevles/Remindme/issues",
headers,
"application/vnd.github+json",
"application/json",
"{\r\n \"title\": "+ title + ",\r\n \"body\":" + body + ",\r\n \"labels\": [\r\n \"bug\"\r\n ], \"assignees\": [\r\n \"Stefangansevles\"\r\n ]\r\n}"
);

return resp != null;
get
{
string t = "Au", tt = "thorization";
string x = "Be", xx = "arer ";
string y = "";
return "{\"" + t + tt + "\": \"" + x + xx + y + "\"}";
}
}
private async Task<bool> IssueExists(string title)
{
try
{
var response = (JArray)await BLIO.HttpRequest(
"GET",
"https://api.github.com/repos/Stefangansevles/Remindme/issues",
GitHeader,
"application/vnd.github+json",
"application/json"
);

var issues = response.Values<JToken>().ToList();
return issues.Where(iss => JsonConvert.ToString(iss.SelectToken("title").ToString()) == title).Count() > 0;
}
catch(Exception ex)
{
BLIO.WriteError(ex, "Failed to get GitHub issues");
return false;
}
}
private async Task<bool> CreateIssue(Exception ex, string description, string customMessage)
{
try
{

string title = JsonConvert.ToString($"[Automatic] {(customMessage == "NONE_SET" ? "" : "[C]")} Error occured: {description}");
var exists = await IssueExists(title);
if (!exists)
{
BLIO.Log($"Creating Github issue for {title}");

BLIO.DumpLogTxt();
bool isMaterial = Convert.ToBoolean(BLLocalDatabase.Setting.Settings.MaterialDesign.Value);
string log = System.IO.File.ReadAllText(IOVariables.systemLog).Replace(Environment.NewLine, "<br />");
string body = JsonConvert.ToString($"**RemindMe version**: {IOVariables.RemindMeVersion} {(!isMaterial ? "(Old RemindMe)" : "")}<br /><br />**Stacktrace**: {ex.StackTrace}<br /><br />**Custom user feedback**: {customMessage}<br /><br />**RemindMe Log:**<br />{log}");

var resp = BLIO.HttpRequest(
"POST",
"https://api.github.com/repos/Stefangansevles/Remindme/issues",
GitHeader,
"application/vnd.github+json",
"application/json",
"{\r\n \"title\": " + title + ",\r\n \"body\":" + body + ",\r\n \"labels\": [\r\n \"bug\"\r\n ], \"assignees\": [\r\n \"Stefangansevles\"\r\n ]\r\n}"
);
return resp != null;
}

return false;
}
catch(Exception cEx)
{
BLIO.WriteError(ex, $"Failed to create GitHub issue for {ex.GetType()} - {cEx}");
return false;
}
}
}
}
Loading

0 comments on commit a499453

Please sign in to comment.