Skip to content
This repository was archived by the owner on Dec 2, 2022. It is now read-only.

Commit 9c027b3

Browse files
author
Adam Warner
committed
Add LogOnlyErrors flag to each config section (default true). Messages succesfully posted to Mattermost will not be logged to the console, otherwise it gets too busy
1 parent c511ded commit 9c027b3

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

Matterhook.NET/Config.cs

+4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ public class Config
1111

1212
public class DiscourseConfig
1313
{
14+
public bool LogOnlyErrors { get; set; } = true;
1415
public string Secret { get; set; }
1516
public string[] IgnoredTopicTitles { get; set; }
1617
public bool IgnorePrivateMessages { get; set; }
1718
public MattermostConfig MattermostConfig { get; set; }
19+
1820
}
1921

2022
public class MattermostConfig
@@ -28,6 +30,7 @@ public class MattermostConfig
2830
//TODO: Look at configuring subscribed events
2931
public class GithubConfig
3032
{
33+
public bool LogOnlyErrors { get; set; } = true;
3134
public string Secret { get; set; }
3235
public MattermostConfig DefaultMattermostConfig { get; set; }
3336
public List<RepoConfig> RepoList { get; set; }
@@ -42,6 +45,7 @@ public class RepoConfig
4245

4346
public class DockerHubConfig
4447
{
48+
public bool LogOnlyErrors { get; set; } = true;
4549
public MattermostConfig DefaultMattermostConfig { get; set; }
4650
public List<RepoConfig> RepoList { get; set; }
4751
}

Matterhook.NET/Controllers/DiscourseHookController.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,18 @@ public async Task<IActionResult> Receive()
9797
? $"Unable to post to Mattermost {response.StatusCode}"
9898
: "Unable to post to Mattermost");
9999

100-
return StatusCode(500,response != null
101-
? $"Problem posting to Mattermost: {response.StatusCode}"
102-
: "Problem Posting to Mattermost");
100+
return StatusCode(500, response != null
101+
? $"Unable to post to Mattermost: {response.StatusCode}"
102+
: "Unable to post to Mattermost");
103103
}
104104

105-
if (message != null) stuffToLog.Add(message.Text);
106-
stuffToLog.Add("Succesfully posted to Mattermost");
107-
Util.LogList(stuffToLog);
105+
if (!_config.LogOnlyErrors)
106+
{
107+
if (message != null) stuffToLog.Add(message.Text);
108+
stuffToLog.Add("Succesfully posted to Mattermost");
109+
Util.LogList(stuffToLog);
110+
}
111+
108112
return StatusCode(200, "Succesfully posted to Mattermost");
109113
}
110114

Matterhook.NET/Controllers/DockerHubHookController.cs

+9-5
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,17 @@ public async Task<IActionResult> Receive()
7979
: "Unable to post to Mattermost");
8080

8181
return StatusCode(500, response != null
82-
? $"Problem posting to Mattermost: {response.StatusCode}"
83-
: "Problem Posting to Mattermost");
82+
? $"Unable to post to Mattermost: {response.StatusCode}"
83+
: "Unable to post to Mattermost");
8484
}
8585

86-
stuffToLog.Add(msg.Text);
87-
stuffToLog.Add("Succesfully posted to Mattermost");
88-
Util.LogList(stuffToLog);
86+
if (!_config.LogOnlyErrors)
87+
{
88+
stuffToLog.Add(msg.Text);
89+
stuffToLog.Add("Succesfully posted to Mattermost");
90+
Util.LogList(stuffToLog);
91+
}
92+
8993
return StatusCode(200, "Succesfully posted to Mattermost");
9094
}
9195
catch (Exception e)

Matterhook.NET/Controllers/GitHubHookController.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,17 @@ public async Task<IActionResult> Receive()
144144
: "Unable to post to Mattermost");
145145

146146
return StatusCode(500, response != null
147-
? $"Problem posting to Mattermost: {response.StatusCode}"
148-
: "Problem Posting to Mattermost");
147+
? $"Unable to post to Mattermost: {response.StatusCode}"
148+
: "Unable to post to Mattermost");
149149
}
150-
if (message != null) stuffToLog.Add(message.Text);
151-
stuffToLog.Add("Succesfully posted to Mattermost");
152-
Util.LogList(stuffToLog);
150+
151+
if (!_config.LogOnlyErrors)
152+
{
153+
if (message != null) stuffToLog.Add(message.Text);
154+
stuffToLog.Add("Succesfully posted to Mattermost");
155+
Util.LogList(stuffToLog);
156+
}
157+
153158
return StatusCode(200, "Succesfully posted to Mattermost");
154159
}
155160
stuffToLog.Add("Invalid Signature!");

0 commit comments

Comments
 (0)