From 2003c488515c814a79e5c2f07ece600838575694 Mon Sep 17 00:00:00 2001 From: prozolic <42107886+prozolic@users.noreply.github.com> Date: Mon, 23 Feb 2026 14:07:14 +0900 Subject: [PATCH] Change item.pubData in RSS feed to merge-at --- src/PRDigest.NET/PullRequestAnalyzer.cs | 39 ++++++++++++++++++++++--- src/PRDigest.NET/RssFeedGenerator.cs | 11 +++---- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/PRDigest.NET/PullRequestAnalyzer.cs b/src/PRDigest.NET/PullRequestAnalyzer.cs index 62e567a..c3c0617 100644 --- a/src/PRDigest.NET/PullRequestAnalyzer.cs +++ b/src/PRDigest.NET/PullRequestAnalyzer.cs @@ -2,6 +2,7 @@ using Markdig.Syntax.Inlines; using System.Collections.Frozen; using System.Collections.Immutable; +using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -121,7 +122,8 @@ public static AnalysisResults Analyze(MarkdownDocument document) return !string.IsNullOrWhiteSpace(labelText) && !labelText.Contains("ラベル"); }); - currentMetadata = GetMetadata(nextPullRequestNumber, labels); + var mergedAt = ParseDate(metadataList[2]); + currentMetadata = GetMetadata(nextPullRequestNumber, labels, mergedAt); foreach (var label in labels ?? []) { @@ -190,7 +192,30 @@ public static AnalysisResults Analyze(MarkdownDocument document) pullRequestInfoTable.ToFrozenDictionary()); } - private static Metadata GetMetadata(HeadingBlock heading, IEnumerable? labels) + private static DateTimeOffset ParseDate(ListItemBlock block) + { + // example: "マージ日時: 2025年12月22日 20:19:50(UTC)" + var text = string.Concat(block.Descendants().Select(l => l.Content.ToString())); + + var textSpan = text.AsSpan(); + var startIndex = textSpan.IndexOf(": ", StringComparison.Ordinal); + if (startIndex < 0) + throw new FormatException($"Invalid date format: could not find ': ' separator in '{text}'."); + + var endIndex = textSpan.Slice(startIndex + 2).IndexOf("(UTC)", StringComparison.Ordinal); + if (endIndex < 0) + throw new FormatException($"Invalid date format: could not find '(UTC)' separator in '{text}'."); + + var dateTextSpan = textSpan.Slice(startIndex + 2, endIndex); + if (DateTimeOffset.TryParseExact(dateTextSpan, "yyyy年MM月dd日 HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var result)) + { + return result; + } + + throw new FormatException($"Invalid date format: could not parse date in '{text}'."); + } + + private static Metadata GetMetadata(HeadingBlock heading, IEnumerable? labels, DateTimeOffset mergedAt) { var pullRequestNumber = ""; var titleText = ""; @@ -233,7 +258,7 @@ private static Metadata GetMetadata(HeadingBlock heading, IEnumerable l.ToString()).ToImmutableArray() ?? ImmutableArray.Empty); + return new Metadata(anchorId, displayText, labels?.Select(l => l.ToString()).ToImmutableArray() ?? ImmutableArray.Empty, mergedAt); } private static string GetOverview(ContainerInline? inline) @@ -291,12 +316,18 @@ public readonly struct Summary(string overview) public string Overview => overview; } - public readonly struct Metadata(string pullRequestNumber, string titleText, ImmutableArray labels) + public readonly struct Metadata( + string pullRequestNumber, + string titleText, + ImmutableArray labels, + DateTimeOffset mergedAt) { public string PullRequestNumber => pullRequestNumber; public string TitleText => titleText; public ImmutableArray Labels => labels; + + public DateTimeOffset MergedAt => mergedAt; } } \ No newline at end of file diff --git a/src/PRDigest.NET/RssFeedGenerator.cs b/src/PRDigest.NET/RssFeedGenerator.cs index 2fe9414..bacd9b9 100644 --- a/src/PRDigest.NET/RssFeedGenerator.cs +++ b/src/PRDigest.NET/RssFeedGenerator.cs @@ -89,13 +89,10 @@ static void AppendItem(ref DefaultInterpolatedStringHandler builder, string targ builder.AppendLiteral(""); builder.AppendLiteral(Environment.NewLine); - if (DateTimeOffset.TryParseExact(target, "yyyy/MM/dd".AsSpan(), CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal, out var date)) - { - builder.AppendLiteral(" "); - builder.AppendFormatted(date, format: "R"); - builder.AppendLiteral(""); - builder.AppendLiteral(Environment.NewLine); - } + builder.AppendLiteral(" "); + builder.AppendFormatted(metadata.MergedAt, format: "R"); + builder.AppendLiteral(""); + builder.AppendLiteral(Environment.NewLine); if (summaryGroups.TryGetValue(metadata.PullRequestNumber, out var info)) {