Skip to content

Commit c4314d6

Browse files
💡 run distinct on configuration
* To account for any duplicate team names in the configuration * Thanks PC for bringing this potential issue to my attention
1 parent d866b4d commit c4314d6

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

source/Gttsb.Core/SyncInput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Gttsb.Core
22
{
3-
public sealed class SyncInput
3+
public sealed record SyncInput
44
{
55
public IEnumerable<string> GitHubTeamNames { get; init; } = Enumerable.Empty<string>();
66
public string EmailAppend { get; init; } = String.Empty;

source/Gttsb.Gh/InstalledGitHubFacade.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Gttsb.Core;
2+
using Newtonsoft.Json;
23
using Octokit;
34
using Octokit.GraphQL;
45
using YamlDotNet.Serialization;
@@ -163,9 +164,27 @@ public async Task<SyncInput> GetConfigurationForInstallationAsync()
163164
var configurationAsString = System.Text.Encoding.Default.GetString(configurationContent);
164165

165166
var deserializer = new DeserializerBuilder().Build();
166-
var yamlObject = deserializer.Deserialize<SyncInput>(configurationAsString);
167167

168-
return yamlObject;
168+
// TODO: fix this nonsense
169+
// https://github.com/aaubry/YamlDotNet/issues/571
170+
var rawYamlObject = deserializer.Deserialize<object>(configurationAsString);
171+
var syncInput = JsonConvert.DeserializeObject<SyncInput>(JsonConvert.SerializeObject(rawYamlObject));
172+
173+
if(syncInput == null)
174+
{
175+
// TODO: throw proper custom exception
176+
throw new Exception("Configuration appears to be null");
177+
}
178+
179+
// One could argue that such logic is too many responsibilities for this method. I pose this is a fine tradeoff though...
180+
// Once we get around to implementing config file status checks, I will most likely change my mind.
181+
// This could also be turned into a Set.
182+
syncInput = syncInput with
183+
{
184+
GitHubTeamNames = syncInput.GitHubTeamNames.Distinct().ToList()
185+
};
186+
187+
return syncInput;
169188
}
170189
}
171190
}

0 commit comments

Comments
 (0)