Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions actions/update-draft-pr/src/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading