Skip to content

Commit

Permalink
fixed really bad logic - lack of sleep will do that to ya
Browse files Browse the repository at this point in the history
  • Loading branch information
Crash0v3r1de committed May 14, 2022
1 parent e000ca9 commit eafbbff
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
22 changes: 13 additions & 9 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
new LoadingUnloading().Save();
Environment.Exit(0); // User canceled program
};
Console.WriteLine($"{DateTime.Now} | Program started...");
ConsoleHelp con = new ConsoleHelp();
Github git = new Github();
Balena bel = new Balena();
Expand All @@ -18,18 +19,21 @@

while (true) {
// Version checking with github logic - may be organized into it's own class down the road
bool updated = false;
if (git.NeedsCloned())
{
if (git.NeedsPulled())
{
git.PullRepo(); // Update
if (BalenaStatus.NeedsAuth) bel.BalenaLogin(); // Prompt for login if initial run
bel.FleetPush(); // Push update to balena for building
if (!String.IsNullOrEmpty(SettingsStatic.Settings.webhook)) Discord.SendWebhook();
Console.WriteLine($"{DateTime.Now} | Fleet updated!");
}
Console.WriteLine($"{DateTime.Now} | Update not needed");
git.CloneRepo();
}
if (git.NeedsPulled())
{
git.PullRepo(); // Update
if (BalenaStatus.NeedsAuth) bel.BalenaLogin(); // Prompt for login if initial run
bel.FleetPush(); // Push update to balena for building
if (!String.IsNullOrEmpty(SettingsStatic.Settings.webhook)) Discord.SendWebhook();
Console.WriteLine($"{DateTime.Now} | Fleet updated!");
updated = true;
}
if (!updated) { Console.WriteLine($"{DateTime.Now} | Update not needed"); }
Thread.Sleep(60000);
}

Expand Down
27 changes: 18 additions & 9 deletions Tools/Github.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,34 @@ public bool PullRepo() {
}
private string CurrentCommitHash() {
string current = "";
using (var repo = new Repository(_gitLoc))
{
foreach (Branch b in repo.Branches.Where(b => !b.IsRemote))
try {
using (var repo = new Repository(_gitLoc))
{
if (b.FriendlyName.Contains("master")) {
var logs = b.TrackedBranch.Commits;
foreach (var item in logs)
foreach (Branch b in repo.Branches.Where(b => !b.IsRemote))
{
if (b.FriendlyName.Contains("master"))
{
var tmp = item.Id;
current = tmp.Sha;
var logs = b.TrackedBranch.Commits;
foreach (var item in logs)
{
var tmp = item.Id;
current = tmp.Sha;
break; // we just want the newest (first listed)
}
}
}
}
} catch { // repo needs cloned
}

return current;
}
public bool NeedsPulled() {
if (CurrentCommitHash() != SettingsStatic.Settings.CurrentCommit) return true;
var curHash = CurrentCommitHash();
if (curHash != SettingsStatic.Settings.CurrentCommit) {
SettingsStatic.Settings.CurrentCommit = curHash;
return true;
}
return false;
}
}
Expand Down

0 comments on commit eafbbff

Please sign in to comment.