Skip to content

Commit 39f366e

Browse files
CopilotMalcolmnixon
andcommitted
Add using System.Text.Json directive to simplify code
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
1 parent 906b96f commit 39f366e

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/DemaConsulting.BuildMark/RepoConnectors/GitHubRepoConnector.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020

21+
using System.Text.Json;
2122
using System.Text.RegularExpressions;
2223

2324
namespace DemaConsulting.BuildMark;
@@ -140,13 +141,13 @@ public override async Task<List<ItemInfo>> GetChangesBetweenTagsAsync(Version? f
140141
}
141142

142143
// Parse the JSON array output
143-
List<System.Text.Json.JsonElement> prArray;
144+
List<JsonElement> prArray;
144145
try
145146
{
146-
var jsonDoc = System.Text.Json.JsonDocument.Parse(prDataOutput);
147+
var jsonDoc = JsonDocument.Parse(prDataOutput);
147148
prArray = jsonDoc.RootElement.EnumerateArray().ToList();
148149
}
149-
catch (System.Text.Json.JsonException)
150+
catch (JsonException)
150151
{
151152
// Fallback to empty result if JSON parsing fails
152153
return new List<ItemInfo>();
@@ -166,7 +167,7 @@ public override async Task<List<ItemInfo>> GetChangesBetweenTagsAsync(Version? f
166167

167168
// Get closing issues if any
168169
var hasIssues = false;
169-
if (prElement.TryGetProperty("closingIssuesReferences", out var issuesElement) && issuesElement.ValueKind == System.Text.Json.JsonValueKind.Array)
170+
if (prElement.TryGetProperty("closingIssuesReferences", out var issuesElement) && issuesElement.ValueKind == JsonValueKind.Array)
170171
{
171172
foreach (var issue in issuesElement.EnumerateArray())
172173
{
@@ -191,7 +192,7 @@ public override async Task<List<ItemInfo>> GetChangesBetweenTagsAsync(Version? f
191192

192193
// Determine type from issue labels
193194
var issueType = "other";
194-
if (issue.TryGetProperty("labels", out var issueLabelsElement) && issueLabelsElement.ValueKind == System.Text.Json.JsonValueKind.Array)
195+
if (issue.TryGetProperty("labels", out var issueLabelsElement) && issueLabelsElement.ValueKind == JsonValueKind.Array)
195196
{
196197
var labels = new List<string>();
197198
foreach (var label in issueLabelsElement.EnumerateArray())
@@ -227,7 +228,7 @@ public override async Task<List<ItemInfo>> GetChangesBetweenTagsAsync(Version? f
227228
{
228229
// Determine type from PR labels
229230
var prType = "other";
230-
if (prElement.TryGetProperty("labels", out var labelsElement) && labelsElement.ValueKind == System.Text.Json.JsonValueKind.Array)
231+
if (prElement.TryGetProperty("labels", out var labelsElement) && labelsElement.ValueKind == JsonValueKind.Array)
231232
{
232233
var labels = new List<string>();
233234
foreach (var label in labelsElement.EnumerateArray())
@@ -255,7 +256,7 @@ public override async Task<List<ItemInfo>> GetChangesBetweenTagsAsync(Version? f
255256
changes.Add(new ItemInfo($"#{prNumber}", prTitle, prUrl, prType));
256257
}
257258
}
258-
catch (System.Text.Json.JsonException)
259+
catch (JsonException)
259260
{
260261
// Skip malformed JSON
261262
}
@@ -311,13 +312,13 @@ public override async Task<List<ItemInfo>> GetOpenIssuesAsync()
311312
var output = await RunCommandAsync("gh", "issue list --state open --json number,title,url,labels");
312313

313314
// Parse the JSON array output
314-
List<System.Text.Json.JsonElement> issueArray;
315+
List<JsonElement> issueArray;
315316
try
316317
{
317-
var jsonDoc = System.Text.Json.JsonDocument.Parse(output);
318+
var jsonDoc = JsonDocument.Parse(output);
318319
issueArray = jsonDoc.RootElement.EnumerateArray().ToList();
319320
}
320-
catch (System.Text.Json.JsonException)
321+
catch (JsonException)
321322
{
322323
// Return empty list if JSON parsing fails
323324
return new List<ItemInfo>();
@@ -335,7 +336,7 @@ public override async Task<List<ItemInfo>> GetOpenIssuesAsync()
335336

336337
// Determine type from labels
337338
var issueType = "other";
338-
if (issueElement.TryGetProperty("labels", out var labelsElement) && labelsElement.ValueKind == System.Text.Json.JsonValueKind.Array)
339+
if (issueElement.TryGetProperty("labels", out var labelsElement) && labelsElement.ValueKind == JsonValueKind.Array)
339340
{
340341
var labels = new List<string>();
341342
foreach (var label in labelsElement.EnumerateArray())
@@ -380,7 +381,7 @@ private static string ExtractShasFromCommitsJson(string json)
380381
{
381382
try
382383
{
383-
var doc = System.Text.Json.JsonDocument.Parse(json);
384+
var doc = JsonDocument.Parse(json);
384385
var shas = new List<string>();
385386

386387
foreach (var commit in doc.RootElement.EnumerateArray())
@@ -397,7 +398,7 @@ private static string ExtractShasFromCommitsJson(string json)
397398

398399
return string.Join('\n', shas);
399400
}
400-
catch (System.Text.Json.JsonException)
401+
catch (JsonException)
401402
{
402403
return string.Empty;
403404
}
@@ -412,7 +413,7 @@ private static string ExtractShasFromCompareJson(string json)
412413
{
413414
try
414415
{
415-
var doc = System.Text.Json.JsonDocument.Parse(json);
416+
var doc = JsonDocument.Parse(json);
416417
var shas = new List<string>();
417418

418419
if (doc.RootElement.TryGetProperty("commits", out var commitsElement))
@@ -432,7 +433,7 @@ private static string ExtractShasFromCompareJson(string json)
432433

433434
return string.Join('\n', shas);
434435
}
435-
catch (System.Text.Json.JsonException)
436+
catch (JsonException)
436437
{
437438
return string.Empty;
438439
}

0 commit comments

Comments
 (0)