Skip to content

Commit 8c549c2

Browse files
azuclaude
andauthored
PR bodyの上書きを修正 (#1371)
fix: skip headline overwrite when content already has headline ドラフトPRのbodyからヘッドラインを埋め込む処理で、すでにファイル側に ヘッドラインが書かれている場合は上書きしないようにする。 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 92e69a9 commit 8c549c2

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

actions/update-draft-pr/src/rename.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,25 @@ interface EmbedHeadlineParams {
2020
headline?: string;
2121
}
2222

23+
const HEADLINE_SECTION_PATTERN = /---\s+JSer\.info #\d+(?:\s+-\s+)?\s*([\s\S]*?)\s*----/;
24+
25+
const hasExistingHeadline = (content: string): boolean => {
26+
const match = content.match(HEADLINE_SECTION_PATTERN);
27+
if (!match) {
28+
return false;
29+
}
30+
return match[1].trim().length > 0;
31+
};
32+
2333
const embedHeadline = ({ content, headline }: EmbedHeadlineParams): string => {
2434
if (!headline) {
2535
console.log("headline is not defined");
2636
return content;
2737
}
38+
if (hasExistingHeadline(content)) {
39+
console.log("headline is already written in content; skip overwrite");
40+
return content;
41+
}
2842
console.log("# headline")
2943
console.log(headline);
3044
console.log("# content")

0 commit comments

Comments
 (0)