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:
committed by
GitHub
parent
060a2efa0e
commit
8c2ebfdb6e
1
__tests__/whatsnew-ca
Normal file
1
__tests__/whatsnew-ca
Normal file
@@ -0,0 +1 @@
|
|||||||
|
test_changelog_file_catalan
|
||||||
1
__tests__/whatsnew-es-ES
Normal file
1
__tests__/whatsnew-es-ES
Normal file
@@ -0,0 +1 @@
|
|||||||
|
test_changelog_file_spanish
|
||||||
1
__tests__/whatsnew-et
Normal file
1
__tests__/whatsnew-et
Normal file
@@ -0,0 +1 @@
|
|||||||
|
test_changelog_file_estonian
|
||||||
@@ -7,7 +7,7 @@ import LocalizedText = androidpublisher_v3.Schema$LocalizedText;
|
|||||||
|
|
||||||
test("read localized whatsnew files", async () => {
|
test("read localized whatsnew files", async () => {
|
||||||
let texts = await readLocalizedReleaseNotes("./__tests__");
|
let texts = await readLocalizedReleaseNotes("./__tests__");
|
||||||
expect(texts).toHaveLength(3);
|
expect(texts).toHaveLength(6);
|
||||||
expect(texts).toContainEqual({
|
expect(texts).toContainEqual({
|
||||||
language: "en-US",
|
language: "en-US",
|
||||||
text: "test_changelog_file"
|
text: "test_changelog_file"
|
||||||
@@ -20,4 +20,16 @@ test("read localized whatsnew files", async () => {
|
|||||||
language: "ja-JP",
|
language: "ja-JP",
|
||||||
text: "test_changelog_file_japanese"
|
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"
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -6,10 +6,11 @@ import {androidpublisher_v3} from "googleapis";
|
|||||||
import LocalizedText = androidpublisher_v3.Schema$LocalizedText;
|
import LocalizedText = androidpublisher_v3.Schema$LocalizedText;
|
||||||
|
|
||||||
export async function readLocalizedReleaseNotes(whatsNewDir: string | undefined): Promise<LocalizedText[] | undefined> {
|
export async function readLocalizedReleaseNotes(whatsNewDir: string | undefined): Promise<LocalizedText[] | undefined> {
|
||||||
|
core.debug(`Executing readLocalizedReleaseNotes`);
|
||||||
if (whatsNewDir != undefined && whatsNewDir.length > 0) {
|
if (whatsNewDir != undefined && whatsNewDir.length > 0) {
|
||||||
const releaseNotes = fs.readdirSync(whatsNewDir)
|
const releaseNotes = fs.readdirSync(whatsNewDir)
|
||||||
.filter(value => /whatsnew-.*-.{2,3}\b/.test(value));
|
.filter(value => /whatsnew-((.*-.*)|(.*))\b/.test(value));
|
||||||
const pattern = /whatsnew-(?<local>.*-.*)/;
|
const pattern = /whatsnew-(?<local>(.*-.*)|(.*))/;
|
||||||
|
|
||||||
let localizedReleaseNotes: LocalizedText[] = [];
|
let localizedReleaseNotes: LocalizedText[] = [];
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ export async function readLocalizedReleaseNotes(whatsNewDir: string | undefined)
|
|||||||
releaseNotes.forEach(value => {
|
releaseNotes.forEach(value => {
|
||||||
const matches = value.match(pattern);
|
const matches = value.match(pattern);
|
||||||
core.debug(`Matches for ${value} = ${matches}`);
|
core.debug(`Matches for ${value} = ${matches}`);
|
||||||
if (matches != undefined && matches.length == 2) {
|
if (matches != undefined && matches.length == 4) {
|
||||||
const lang = matches[1];
|
const lang = matches[1];
|
||||||
const filePath = path.join(whatsNewDir, value);
|
const filePath = path.join(whatsNewDir, value);
|
||||||
const content = readFileSync(filePath, 'utf-8');
|
const content = readFileSync(filePath, 'utf-8');
|
||||||
|
|||||||
Reference in New Issue
Block a user