Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update readme parser to support markdown tags #375

Merged
merged 1 commit into from
Jan 23, 2024
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
22 changes: 15 additions & 7 deletions scripts/sdk-compatibility-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ export class SdkCompatibilityGenerator {
* Extracts the release version and a link to the release notes from a badge
* on the SDKs readme. The RegEx is looking for an <a> tag that looks like
* <a href="https://github.com/open-feature/SDK_REPO_NAME/releases/tag/TAG_VERSION">
* or a markdown link that looks like (https://github.com/open-feature/SDK_REPO_NAME/releases/tag/TAG_VERSION).
*/
private getReleaseInfo(name: string, url: string, content: string): SdkCompatibility['release'] {
const releaseRegex = new RegExp(
`<a href="(${url.replaceAll('/', '\\/').replaceAll('.', '\\.')}\\/releases\\/tag\\/.*(v?\\d+\\.\\d+\\.\\d+))">`
const releaseHtmlRegex = new RegExp(
`<a href="(${url.replaceAll('/', '\\/').replaceAll('.', '\\.')}\\/releases\\/tag\\/.*(v?\\d+\\.\\d+\\.\\d+))">`,
beeme1mr marked this conversation as resolved.
Show resolved Hide resolved
);
const releaseInfo = releaseRegex.exec(content);
const releaseMarkdownRegex = new RegExp(
`\\((${url.replaceAll('/', '\\/').replaceAll('.', '\\.')}\\/releases\\/tag\\/.*(v?\\d+\\.\\d+\\.\\d+))\\)`,
);
const releaseInfo = releaseHtmlRegex.exec(content) ?? releaseMarkdownRegex.exec(content);
if (!releaseInfo) {
throw new Error(`Unable to extract spec information from ${name}`);
}
Expand All @@ -51,14 +55,18 @@ export class SdkCompatibilityGenerator {
/**
* Extracts the spec version and a link to the release notes from a badge
* on the SDKs readme. The RegEx is looking for an <a> tag that looks like
* <a href="https://github.com/open-feature/spec/releases/tag/TAG_VERSION">
* <a href="https://github.com/open-feature/spec/releases/tag/TAG_VERSION"> or
* a markdown link that looks like (https://github.com/open-feature/spec/releases/tag/TAG_VERSION).
*/
private getSpecInfo(name: string, content: string): SdkCompatibility['spec'] {
const specRegex = new RegExp(
'<a href="(https:\\/\\/github\\.com\\/open-feature\\/spec\\/releases\\/tag\\/v(\\d+\\.\\d+\\.\\d+))">'
const specHtmlRegex = new RegExp(
'<a href="(https:\\/\\/github\\.com\\/open-feature\\/spec\\/releases\\/tag\\/v(\\d+\\.\\d+\\.\\d+))">',
);
const specMarkdownRegex = new RegExp(
'\\((https:\\/\\/github\\.com\\/open-feature\\/spec\\/releases\\/tag\\/v(\\d+\\.\\d+\\.\\d+))\\)',
);

const specInfo = specRegex.exec(content);
const specInfo = specHtmlRegex.exec(content) ?? specMarkdownRegex.exec(content);
if (!specInfo) {
throw new Error(`Unable to extract spec information from ${name}`);
}
Expand Down