From 8c2ebfdb6e1b439d3a31d35772b3f0f489d688c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20A=20Mart=C3=ADnez=20Andr=C3=A9s?= Date: Tue, 21 Sep 2021 18:26:56 +0200 Subject: [PATCH] Fix: Support BCP 47 language codes without contry code (#73) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Updated regex to support BCP 47 language codes without country code * Updated whatsnew tests Co-authored-by: Pablo A. Martínez --- __tests__/whatsnew-ca | 1 + __tests__/whatsnew-es-ES | 1 + __tests__/whatsnew-et | 1 + __tests__/whatsnew.test.ts | 14 +++++++++++++- src/whatsnew.ts | 7 ++++--- 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 __tests__/whatsnew-ca create mode 100644 __tests__/whatsnew-es-ES create mode 100644 __tests__/whatsnew-et diff --git a/__tests__/whatsnew-ca b/__tests__/whatsnew-ca new file mode 100644 index 00000000..db8f2084 --- /dev/null +++ b/__tests__/whatsnew-ca @@ -0,0 +1 @@ +test_changelog_file_catalan \ No newline at end of file diff --git a/__tests__/whatsnew-es-ES b/__tests__/whatsnew-es-ES new file mode 100644 index 00000000..66a69be8 --- /dev/null +++ b/__tests__/whatsnew-es-ES @@ -0,0 +1 @@ +test_changelog_file_spanish \ No newline at end of file diff --git a/__tests__/whatsnew-et b/__tests__/whatsnew-et new file mode 100644 index 00000000..1dbd0d33 --- /dev/null +++ b/__tests__/whatsnew-et @@ -0,0 +1 @@ +test_changelog_file_estonian \ No newline at end of file diff --git a/__tests__/whatsnew.test.ts b/__tests__/whatsnew.test.ts index cc76174e..13257cfa 100644 --- a/__tests__/whatsnew.test.ts +++ b/__tests__/whatsnew.test.ts @@ -7,7 +7,7 @@ import LocalizedText = androidpublisher_v3.Schema$LocalizedText; test("read localized whatsnew files", async () => { let texts = await readLocalizedReleaseNotes("./__tests__"); - expect(texts).toHaveLength(3); + expect(texts).toHaveLength(6); expect(texts).toContainEqual({ language: "en-US", text: "test_changelog_file" @@ -20,4 +20,16 @@ test("read localized whatsnew files", async () => { language: "ja-JP", text: "test_changelog_file_japanese" }); + expect(texts).toContainEqual({ + language: "ca", + text: "test_changelog_file_catalan" + }); + expect(texts).toContainEqual({ + language: "es-ES", + text: "test_changelog_file_spanish" + }); + expect(texts).toContainEqual({ + language: "et", + text: "test_changelog_file_estonian" + }); }); \ No newline at end of file diff --git a/src/whatsnew.ts b/src/whatsnew.ts index a5c7e1c2..7db3894d 100644 --- a/src/whatsnew.ts +++ b/src/whatsnew.ts @@ -6,10 +6,11 @@ import {androidpublisher_v3} from "googleapis"; import LocalizedText = androidpublisher_v3.Schema$LocalizedText; export async function readLocalizedReleaseNotes(whatsNewDir: string | undefined): Promise { + core.debug(`Executing readLocalizedReleaseNotes`); if (whatsNewDir != undefined && whatsNewDir.length > 0) { const releaseNotes = fs.readdirSync(whatsNewDir) - .filter(value => /whatsnew-.*-.{2,3}\b/.test(value)); - const pattern = /whatsnew-(?.*-.*)/; + .filter(value => /whatsnew-((.*-.*)|(.*))\b/.test(value)); + const pattern = /whatsnew-(?(.*-.*)|(.*))/; let localizedReleaseNotes: LocalizedText[] = []; @@ -17,7 +18,7 @@ export async function readLocalizedReleaseNotes(whatsNewDir: string | undefined) releaseNotes.forEach(value => { const matches = value.match(pattern); core.debug(`Matches for ${value} = ${matches}`); - if (matches != undefined && matches.length == 2) { + if (matches != undefined && matches.length == 4) { const lang = matches[1]; const filePath = path.join(whatsNewDir, value); const content = readFileSync(filePath, 'utf-8');