From 89d83adb43c8b15de072c8c52e62145fd69abfd7 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 15 Apr 2026 11:28:29 +0000 Subject: [PATCH] fix: skip headline overwrite when content already has headline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ドラフトPRのbodyからヘッドラインを埋め込む処理で、すでにファイル側に ヘッドラインが書かれている場合は上書きしないようにする。 Co-authored-by: azu --- actions/update-draft-pr/src/rename.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/actions/update-draft-pr/src/rename.ts b/actions/update-draft-pr/src/rename.ts index cc627dfa519..d36e081d6e9 100644 --- a/actions/update-draft-pr/src/rename.ts +++ b/actions/update-draft-pr/src/rename.ts @@ -20,11 +20,25 @@ interface EmbedHeadlineParams { headline?: string; } +const HEADLINE_SECTION_PATTERN = /---\s+JSer\.info #\d+(?:\s+-\s+)?\s*([\s\S]*?)\s*----/; + +const hasExistingHeadline = (content: string): boolean => { + const match = content.match(HEADLINE_SECTION_PATTERN); + if (!match) { + return false; + } + return match[1].trim().length > 0; +}; + const embedHeadline = ({ content, headline }: EmbedHeadlineParams): string => { if (!headline) { console.log("headline is not defined"); return content; } + if (hasExistingHeadline(content)) { + console.log("headline is already written in content; skip overwrite"); + return content; + } console.log("# headline") console.log(headline); console.log("# content")