Skip to content

Commit 9555bf9

Browse files
committed
Codereview clean up
1 parent 2b8488f commit 9555bf9

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

build.fsx

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -427,28 +427,28 @@ let getReleaseNotes currentRelease (lastRelease: GithubRelease) =
427427
ghReleaseResult.ExitCode = 0
428428
&& not (String.IsNullOrWhiteSpace(ghReleaseResult.StandardOutput.Trim()))
429429
then
430-
try
431-
let jsonOutput = ghReleaseResult.StandardOutput.Trim()
432-
let jsonValue = FSharp.Data.JsonValue.Parse(jsonOutput)
433-
let releases = jsonValue.AsArray()
434-
if releases.Length > 0 then
435-
let createdAt = releases.[0].GetProperty("createdAt").AsString()
436-
let lastIdx = createdAt.LastIndexOf("Z", StringComparison.Ordinal)
437-
if lastIdx > 0 then
438-
let ghDate = createdAt.Substring(0, lastIdx)
439-
printfn $"Using most recent GitHub release date for author attribution: {ghDate}"
440-
ghDate
441-
else
442-
let fallbackDate = DateTime.UtcNow.ToString("yyyy-MM-dd")
443-
printfn $"Could not parse GitHub release date format, using current date: {fallbackDate}"
444-
fallbackDate
445-
else
430+
let jsonOutput = ghReleaseResult.StandardOutput.Trim()
431+
let jsonValue = FSharp.Data.JsonValue.Parse(jsonOutput)
432+
let releases = jsonValue.AsArray()
433+
if releases.Length > 0 then
434+
match releases.[0].TryGetProperty("createdAt") with
435+
| Some createdAtJson ->
436+
let createdAt = createdAtJson.AsString()
437+
// Parse ISO 8601 date and convert back to string format for the query
438+
let dateTime =
439+
DateTime
440+
.Parse(createdAt, null, System.Globalization.DateTimeStyles.RoundtripKind)
441+
.ToUniversalTime()
442+
let ghDate = dateTime.ToString("yyyy-MM-ddTHH:mm:ss")
443+
printfn $"Using most recent GitHub release date for author attribution: {ghDate}"
444+
ghDate
445+
| None ->
446446
let fallbackDate = DateTime.UtcNow.ToString("yyyy-MM-dd")
447-
printfn $"No GitHub releases found, using current date: {fallbackDate}"
447+
printfn $"GitHub release missing createdAt, using current date: {fallbackDate}"
448448
fallbackDate
449-
with ex ->
449+
else
450450
let fallbackDate = DateTime.UtcNow.ToString("yyyy-MM-dd")
451-
printfn $"Could not parse GitHub release JSON, using current date: {fallbackDate}"
451+
printfn $"No GitHub releases found, using current date: {fallbackDate}"
452452
fallbackDate
453453
else
454454
let fallbackDate = DateTime.UtcNow.ToString("yyyy-MM-dd")
@@ -478,52 +478,52 @@ let getReleaseNotes currentRelease (lastRelease: GithubRelease) =
478478
let jsonValue = FSharp.Data.JsonValue.Parse(jsonOutput)
479479
let prs = jsonValue.AsArray()
480480

481-
// Parse the last release published date as ISO timestamp for comparison
481+
// Parse the date as ISO 8601 format (GitHub always returns dates in this format: "2025-08-02T10:25:30Z")
482482
let cutoffTimestamp =
483-
try
484-
DateTime.Parse(date).ToUniversalTime()
485-
with _ ->
486-
// If parsing fails, try to parse as ISO format
487-
try
488-
DateTime.ParseExact(date, "yyyy-MM-ddTHH:mm:ss", null).ToUniversalTime()
489-
with _ ->
490-
DateTime.ParseExact(date, "yyyy-MM-dd", null).ToUniversalTime()
483+
DateTime.Parse(date, null, System.Globalization.DateTimeStyles.RoundtripKind).ToUniversalTime()
491484

492485
printfn $"Filtering PRs merged after: {cutoffTimestamp:O}"
493486

494487
let authors =
495488
prs
496489
|> Array.collect (fun (pr: FSharp.Data.JsonValue) ->
497490
let mergedAtOpt =
498-
try
499-
let mergedAtStr = pr.GetProperty("mergedAt").AsString()
500-
Some(DateTime.Parse(mergedAtStr).ToUniversalTime())
501-
with _ ->
502-
None
491+
match pr.TryGetProperty("mergedAt") with
492+
| Some mergedAtJson ->
493+
try
494+
let mergedAtStr = mergedAtJson.AsString()
495+
Some(
496+
DateTime
497+
.Parse(mergedAtStr, null, System.Globalization.DateTimeStyles.RoundtripKind)
498+
.ToUniversalTime()
499+
)
500+
with _ ->
501+
None
502+
| None -> None
503503

504504
match mergedAtOpt with
505505
| Some mergedAt when mergedAt > cutoffTimestamp ->
506-
try
507-
let commits = pr.GetProperty("commits").AsArray()
506+
match pr.TryGetProperty("commits") with
507+
| Some commitsJson ->
508+
let commits = commitsJson.AsArray()
508509
commits
509510
|> Array.collect (fun (commit: FSharp.Data.JsonValue) ->
510-
try
511-
let commitAuthors = commit.GetProperty("authors").AsArray()
511+
match commit.TryGetProperty("authors") with
512+
| Some authorsJson ->
513+
let commitAuthors = authorsJson.AsArray()
512514
commitAuthors
513515
|> Array.choose (fun (author: FSharp.Data.JsonValue) ->
514-
try
515-
let login = author.GetProperty("login").AsString()
516+
match author.TryGetProperty("login") with
517+
| Some loginJson ->
518+
let login = loginJson.AsString()
516519
// Filter out bots
517520
if login.EndsWith("[bot]", StringComparison.Ordinal) then
518521
None
519522
else
520523
Some(login)
521-
with _ ->
522-
None)
523-
with _ ->
524-
[||])
525-
with _ ->
526-
[||]
524+
| None -> None)
525+
| None -> [||])
526+
| None -> [||]
527527
| _ -> [||])
528528
|> Array.distinct
529529
|> Array.sort

0 commit comments

Comments
 (0)