Skip to content

Commit 055b2ec

Browse files
v1.0.0-beta
1 parent 7452c14 commit 055b2ec

File tree

13 files changed

+401
-147
lines changed

13 files changed

+401
-147
lines changed

GitHubDeployMonitor/App.config

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313
<setting name="RepoDirectory" serializeAs="String">
1414
<value>octocat/octocat.github.io</value>
1515
</setting>
16+
<setting name="ApiKey" serializeAs="String">
17+
<value>github_pat_ilovegithubapi</value>
18+
</setting>
19+
<setting name="UsePrivateKey" serializeAs="String">
20+
<value>False</value>
21+
</setting>
22+
<setting name="NamesToIgnore" serializeAs="Xml">
23+
<value>
24+
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
25+
<string>bot</string>
26+
</ArrayOfString>
27+
</value>
28+
</setting>
1629
</GitHubDeployMonitor.Properties.Settings>
1730
</userSettings>
1831
</configuration>

GitHubDeployMonitor/AppConfig.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

GitHubDeployMonitor/Form1.cs

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public partial class Form1 : Form
1212
{
1313
private readonly NotifyIcon trayIcon;
1414
private readonly System.Windows.Forms.Timer checkTimer;
15-
private readonly AppConfig config;
1615
private string lastSha = string.Empty;
1716

1817
protected override void OnLoad(EventArgs e)
@@ -22,9 +21,8 @@ protected override void OnLoad(EventArgs e)
2221
this.ShowInTaskbar = false;
2322
}
2423

25-
public Form1(AppConfig loadedConfig)
24+
public Form1()
2625
{
27-
config = loadedConfig;
2826
InitializeComponent();
2927

3028
trayIcon = new NotifyIcon
@@ -48,9 +46,9 @@ public Form1(AppConfig loadedConfig)
4846
private async Task InitializeMonitorAsync()
4947
{
5048
using var client = new HttpClient();
51-
client.DefaultRequestHeaders.Add("User-Agent", "GitHubDeployMonitor");
52-
if (config.UsePrivateKey && !string.IsNullOrWhiteSpace(config.ApiKey))
53-
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {config.ApiKey}");
49+
client.DefaultRequestHeaders.Add("User-Agent", "GitHubPagesDeployMonitor");
50+
if (Properties.Settings.Default.UsePrivateKey && !string.IsNullOrWhiteSpace(Properties.Settings.Default.ApiKey))
51+
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {Properties.Settings.Default.ApiKey}");
5452

5553
try
5654
{
@@ -79,18 +77,18 @@ private async Task InitializeMonitorAsync()
7977
private void OpenSettings(object? sender, EventArgs e)
8078
{
8179
checkTimer.Stop();
82-
using var form = new SettingsForm(config);
80+
using var form = new SettingsForm();
8381
form.ShowDialog();
8482
InitializeMonitorAsync().ConfigureAwait(false);
8583
}
8684

8785
private async Task CheckGitHub()
8886
{
8987
using var client = new HttpClient();
90-
client.DefaultRequestHeaders.Add("User-Agent", "GitHubDeployMonitor");
88+
client.DefaultRequestHeaders.Add("User-Agent", "GitHubPagesDeployMonitor");
9189

92-
if (config.UsePrivateKey && !string.IsNullOrWhiteSpace(config.ApiKey))
93-
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {config.ApiKey}");
90+
if (Properties.Settings.Default.UsePrivateKey && !string.IsNullOrWhiteSpace(Properties.Settings.Default.ApiKey))
91+
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {Properties.Settings.Default.ApiKey}");
9492

9593
try
9694
{
@@ -110,9 +108,26 @@ private async Task CheckGitHub()
110108
var content = await response.Content.ReadAsStringAsync();
111109
var doc = JsonDocument.Parse(content);
112110
var sha = doc.RootElement.GetProperty("sha").GetString();
113-
111+
var author = doc.RootElement.GetProperty("commit")
112+
.GetProperty("author")
113+
.GetProperty("name")
114+
.GetString();
115+
if (author != null)
116+
{
117+
foreach (var item in Properties.Settings.Default.NamesToIgnore)
118+
{
119+
if (item != null)
120+
{
121+
if (author.Contains(item))
122+
{
123+
return;
124+
}
125+
}
126+
}
127+
}
114128
if (!string.IsNullOrEmpty(sha) && sha != lastSha)
115129
{
130+
Console.WriteLine($"New commit detected with sha f{sha}");
116131
lastSha = sha;
117132
trayIcon.ShowBalloonTip(1000, "📦 New Push", "New push detected.", ToolTipIcon.Info);
118133
_ = MonitorChecksAsync(sha);
@@ -134,25 +149,33 @@ private void ShowRepoError()
134149
private async Task MonitorChecksAsync(string sha)
135150
{
136151
using var client = new HttpClient();
137-
client.DefaultRequestHeaders.Add("User-Agent", "GitHubDeployMonitor");
138-
if (config.UsePrivateKey && !string.IsNullOrWhiteSpace(config.ApiKey))
139-
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {config.ApiKey}");
152+
client.DefaultRequestHeaders.Add("User-Agent", "GitHubPagesDeployMonitor");
153+
if (Properties.Settings.Default.UsePrivateKey && !string.IsNullOrWhiteSpace(Properties.Settings.Default.ApiKey))
154+
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {Properties.Settings.Default.ApiKey}");
140155

141156
while (true)
142157
{
143-
await Task.Delay(5000);
158+
await Task.Delay(Properties.Settings.Default.CheckInterval);
144159
try
145160
{
146161
var url = $"https://api.github.com/repos/{Properties.Settings.Default.RepoDirectory}/commits/{sha}/check-runs";
147162
var resp = await client.GetStringAsync(url);
148163
var doc = JsonDocument.Parse(resp);
149164
var checks = doc.RootElement.GetProperty("check_runs");
150-
int total = checks.GetArrayLength();
151-
int completed = checks.EnumerateArray().Count(c => c.GetProperty("status").GetString() == "completed");
152-
if (completed == total && total > 0)
165+
foreach (var check in checks.EnumerateArray())
153166
{
154-
trayIcon.ShowBalloonTip(1000, "✅ Deploy Complete", "Your GitHub Page has been updated.", ToolTipIcon.Info);
155-
break;
167+
if (check.GetProperty("name").GetString() == "deploy")
168+
{
169+
var status = check.GetProperty("status").GetString();
170+
var conclusion = check.GetProperty("conclusion").GetString();
171+
172+
if (status == "completed" && conclusion == "success")
173+
{
174+
Console.WriteLine("Checks completed");
175+
trayIcon.ShowBalloonTip(1000, "✅ Deploy Complete", "Your GitHub Page has been updated.", ToolTipIcon.Info);
176+
return;
177+
}
178+
}
156179
}
157180
}
158181
catch

GitHubDeployMonitor/Program.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ static void Main()
1212
Application.SetCompatibleTextRenderingDefault(false);
1313

1414
// Load config and show settings first
15-
var config = AppConfig.Load();
16-
using (var settings = new SettingsForm(config))
15+
using (var settings = new SettingsForm())
1716
{
1817
Application.Run(settings);
1918
}
2019

2120
// Start tray monitor
22-
Application.Run(new Form1(config));
21+
Application.Run(new Form1());
2322
}
2423
}
2524
}

GitHubDeployMonitor/Properties/Settings.Designer.cs

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GitHubDeployMonitor/Properties/Settings.settings

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,17 @@
88
<Setting Name="RepoDirectory" Type="System.String" Scope="User">
99
<Value Profile="(Default)">octocat/octocat.github.io</Value>
1010
</Setting>
11+
<Setting Name="ApiKey" Type="System.String" Scope="User">
12+
<Value Profile="(Default)">github_pat_ilovegithubapi</Value>
13+
</Setting>
14+
<Setting Name="UsePrivateKey" Type="System.Boolean" Scope="User">
15+
<Value Profile="(Default)">False</Value>
16+
</Setting>
17+
<Setting Name="NamesToIgnore" Type="System.Collections.Specialized.StringCollection" Scope="User">
18+
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
19+
&lt;ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
20+
&lt;string&gt;bot&lt;/string&gt;
21+
&lt;/ArrayOfString&gt;</Value>
22+
</Setting>
1123
</Settings>
1224
</SettingsFile>

GitHubDeployMonitor/SettingsForm.cs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ namespace GitHubDeployMonitor
66
{
77
public partial class SettingsForm : Form
88
{
9-
private readonly AppConfig config;
109

11-
public SettingsForm(AppConfig currentConfig)
10+
public SettingsForm()
1211
{
13-
config = currentConfig;
1412
InitializeComponent();
15-
16-
apiKeyTextBox.Text = config.ApiKey;
17-
privateKeyRadio.Checked = config.UsePrivateKey;
18-
publicKeyRadio.Checked = !config.UsePrivateKey;
13+
14+
repoTextBox.Text = Properties.Settings.Default.RepoDirectory;
15+
apiKeyTextBox.Text = Properties.Settings.Default.ApiKey;
16+
privateKeyRadio.Checked = Properties.Settings.Default.UsePrivateKey;
17+
publicKeyRadio.Checked = !Properties.Settings.Default.UsePrivateKey;
18+
listBox.Items.Clear();
19+
if (Properties.Settings.Default.NamesToIgnore != null)
20+
{
21+
foreach (var item in Properties.Settings.Default.NamesToIgnore)
22+
{
23+
listBox.Items.Add(item);
24+
}
25+
}
1926
}
2027

2128
private void saveButton_Click(object sender, EventArgs e)
@@ -27,16 +34,22 @@ private void saveButton_Click(object sender, EventArgs e)
2734
}
2835
if (privateKeyRadio.Checked && string.IsNullOrWhiteSpace(apiKeyTextBox.Text))
2936
{
30-
MessageBox.Show("Please enter your GitHub API key when using private mode.");
37+
MessageBox.Show("Please enter your GitHub API key.");
3138
return;
3239
}
3340

41+
var ignoreList = new System.Collections.Specialized.StringCollection();
42+
foreach (var item in listBox.Items)
43+
{
44+
ignoreList.Add(item.ToString());
45+
}
46+
47+
Properties.Settings.Default.NamesToIgnore = ignoreList;
3448
Properties.Settings.Default.RepoDirectory = repoTextBox.Text.Trim();
3549
Properties.Settings.Default.CheckInterval = (int)numInterval.Value;
50+
Properties.Settings.Default.ApiKey = apiKeyTextBox.Text.Trim();
51+
Properties.Settings.Default.UsePrivateKey = privateKeyRadio.Checked;
3652
Properties.Settings.Default.Save();
37-
config.ApiKey = apiKeyTextBox.Text.Trim();
38-
config.UsePrivateKey = privateKeyRadio.Checked;
39-
config.Save();
4053

4154
MessageBox.Show("Settings saved and program started monitoring!");
4255
Close();
@@ -47,5 +60,22 @@ private void infoButton_Click(object sender, EventArgs e)
4760
using (var info = new infoForm())
4861
info.ShowDialog();
4962
}
63+
64+
private void removeButton_Click(object sender, EventArgs e)
65+
{
66+
if (listBox.SelectedItem != null)
67+
{
68+
listBox.Items.Remove(listBox.SelectedItem);
69+
}
70+
}
71+
72+
private void addButton_Click(object sender, EventArgs e)
73+
{
74+
if (!string.IsNullOrEmpty(addString.Text))
75+
{
76+
listBox.Items.Add(addString.Text.Trim());
77+
addString.Clear();
78+
}
79+
}
5080
}
5181
}

0 commit comments

Comments
 (0)