Skip to content

Commit 6ac0c6e

Browse files
Make label matching case-insensitive
1 parent 9608ef2 commit 6ac0c6e

3 files changed

Lines changed: 31 additions & 22 deletions

File tree

src/App.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ public async Task Run(Settings settings)
3333
if (repo.Archived)
3434
{
3535
_log($"(skipping archived {repo.Name})");
36-
continue;
36+
}
37+
else
38+
{
39+
await _sync.SyncRepo(repo, settings, labels);
3740
}
3841

39-
await _sync.SyncRepo(repo, settings, labels);
4042
_log(string.Empty);
4143
}
4244

src/Synchronizer.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ private void ShowSynchronizedLabels(Repository repo, IEnumerable<Label> accountL
124124
private IEnumerable<Label> GetLabelsToAdd(Repository repo, IEnumerable<Label> accountLabels, IEnumerable<Label> repoLabels)
125125
{
126126
_setStatus($"Finding labels to add to {repo.Name}...");
127-
var newLabels = accountLabels.Where(al => repoLabels.All(rl => rl.Name != al.Name && rl.Description != al.Description)).ToArray();
127+
var newLabels = accountLabels.Where(al => repoLabels
128+
.All(rl => !string.Equals(rl.Name, al.Name, StringComparison.CurrentCultureIgnoreCase)
129+
&& !string.Equals(rl.Description, al.Description, StringComparison.CurrentCultureIgnoreCase)))
130+
.ToArray();
128131
_log($"{newLabels.Length,3} {"to add",-9} : {LabelNames(newLabels)}");
129132
return newLabels;
130133
}
@@ -140,7 +143,10 @@ private IEnumerable<Label> GetLabelsToEdit(Repository repo, IEnumerable<Label> a
140143
private IEnumerable<Label> GetLabelsToDelete(Repository repo, IEnumerable<Label> accountLabels, IEnumerable<Label> repoLabels)
141144
{
142145
_setStatus($"Finding labels to delete from {repo.Name}...");
143-
var oldLabels = repoLabels.Where(rl => accountLabels.All(al => al.Name != rl.Name && al.Description != rl.Description)).ToArray();
146+
var oldLabels = repoLabels.Where(rl => accountLabels
147+
.All(al => !string.Equals(al.Name, rl.Name, StringComparison.InvariantCultureIgnoreCase)
148+
&& !string.Equals(al.Description, rl.Description, StringComparison.InvariantCultureIgnoreCase)))
149+
.ToArray();
144150
_log($"{oldLabels.Length,3} {"to delete",-9} : {LabelNames(oldLabels)}");
145151
return oldLabels;
146152
}
@@ -170,12 +176,13 @@ private async Task DeleteLabels(Repository repo, IEnumerable<Label> oldLabels)
170176
}
171177

172178
private static bool Matching(Label accountLabel, Label repoLabel)
173-
=> repoLabel.Name == accountLabel.Name
174-
&& repoLabel.Description == accountLabel.Description
175-
&& repoLabel.Color == accountLabel.Color;
179+
=> string.Equals(repoLabel.Name, accountLabel.Name, StringComparison.InvariantCultureIgnoreCase)
180+
&& string.Equals(repoLabel.Description, accountLabel.Description, StringComparison.InvariantCultureIgnoreCase)
181+
&& string.Equals(repoLabel.Color, accountLabel.Color, StringComparison.InvariantCultureIgnoreCase);
176182

177183
private static bool NeedsUpdating(Label accountLabel, Label repoLabel)
178-
=> accountLabel.Name == repoLabel.Name &&
179-
(accountLabel.Description != repoLabel.Description || accountLabel.Color != repoLabel.Color);
184+
=> string.Equals(accountLabel.Name, repoLabel.Name, StringComparison.InvariantCultureIgnoreCase) &&
185+
(!string.Equals(accountLabel.Description, repoLabel.Description, StringComparison.InvariantCultureIgnoreCase)
186+
|| !string.Equals(accountLabel.Color, repoLabel.Color, StringComparison.InvariantCultureIgnoreCase));
180187
}
181188
}

test/SynchronizerTests.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ public class SynchronizerTests
1111
{
1212
private readonly Stubs.Label[] _accountLabels =
1313
{
14-
new("t1", "test1", "000000"),
15-
new("t2", "test2", "000000"),
16-
new("t3", "test3", "000000"),
17-
new("t4", "test4", "000000"),
18-
new("t5", "test5", "000000"),
19-
new("t6", "test6", "000000")
14+
new("t1", "test1", "aaaaaa"),
15+
new("t2", "test2", "bbbbbb"),
16+
new("t3", "test3", "cccccc"),
17+
new("t4", "test4", "dddddd"),
18+
new("t5", "test5", "eeeeee"),
19+
new("t6", "test6", "ffffff")
2020
};
2121

2222
private readonly Stubs.Label[] _repoLabels =
2323
{
24-
new("t3", "", "000000"),
25-
new("t4", "test4", "FFFFFF"),
26-
new("t5", "", "FFFFFF"),
27-
new("t6", "test6", "000000"),
24+
new("T3", "", "cccccc"),
25+
new("t4", "Test4", "eeeeee"),
26+
new("T5", "", "dddddd"),
27+
new("t6", "Test6", "ffffff"),
2828
new("t7", "test7", "000000"),
29-
new("t8", "test8", "000000"),
30-
new("t9", "test9", "000000"),
31-
new("t0", "test0", "000000")
29+
new("t8", "test8", "111111"),
30+
new("t9", "test9", "222222"),
31+
new("t0", "test0", "333333")
3232
};
3333

3434
private readonly Action<string> _noOp = _ => { };

0 commit comments

Comments
 (0)