Fix: Support BCP 47 language codes without contry code (#73)

* Updated regex to support BCP 47 language codes without country code

* Updated whatsnew tests

Co-authored-by: Pablo A. Martínez <pamartinez@boiradev.com>
This commit is contained in:
Pablo A Martínez Andrés
2021-09-21 18:26:56 +02:00
committed by GitHub
parent 060a2efa0e
commit 8c2ebfdb6e
5 changed files with 20 additions and 4 deletions

1
__tests__/whatsnew-ca Normal file
View File

@@ -0,0 +1 @@
test_changelog_file_catalan

1
__tests__/whatsnew-es-ES Normal file
View File

@@ -0,0 +1 @@
test_changelog_file_spanish

1
__tests__/whatsnew-et Normal file
View File

@@ -0,0 +1 @@
test_changelog_file_estonian

View File

@@ -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"
});
});

View File

@@ -6,10 +6,11 @@ import {androidpublisher_v3} from "googleapis";
import LocalizedText = androidpublisher_v3.Schema$LocalizedText;
export async function readLocalizedReleaseNotes(whatsNewDir: string | undefined): Promise<LocalizedText[] | undefined> {
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-(?<local>.*-.*)/;
.filter(value => /whatsnew-((.*-.*)|(.*))\b/.test(value));
const pattern = /whatsnew-(?<local>(.*-.*)|(.*))/;
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');