-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetDescriptionText.ts
31 lines (27 loc) · 978 Bytes
/
getDescriptionText.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import * as core from '@actions/core';
import { vars } from './constants';
import { getRepositoryFile } from './getRepositoryFile';
export async function getDescriptionText(
version: string
): Promise<string> {
const changelogPath = core
.getInput('notes-file', { required: false })
.replace(/^\//, '');
const changelog = await getRepositoryFile(changelogPath);
const findDesc = (descEndRegex: string) => {
const regex = new RegExp(
`^#+\\s.*${version}.*?\\n+((.*\\n)*)(${descEndRegex})`, 'gm'
);
return regex.exec(changelog);
};
const nextVersion = `#+\\s.*${vars.versionRegex}`; // means next version in file
const endOfFile = `[\r\n]?$(?![\r\n])`;
let description = findDesc(nextVersion);
if (!description) {
description = findDesc(endOfFile);
}
if (!description || description?.[1].match(/^\n*$/)) {
throw new Error(`🔍 No description for ${version} found`);
}
return description?.[1].replace(/\n*$/, '');
}