fix(tools) Improve efficiency of the Hide Non-translated Strings GitHub action (#40721)

* fix: changed update strings logic

* fix: pull all strings instead of strings by file

* fix: changed console.log message
This commit is contained in:
Randell Dawson
2021-01-18 11:20:29 -07:00
committed by GitHub
parent 8d12a0dae9
commit f37dd6ff84
2 changed files with 58 additions and 21 deletions

View File

@@ -13,7 +13,10 @@ const shouldHide = (text, context, challengeTitle) => {
const getStrings = async ({ projectId, fileId }) => {
let headers = { ...authHeader };
const endPoint = `projects/${projectId}/strings?fileId=${fileId}&limit=500`;
let endPoint = `projects/${projectId}/strings?limit=500`;
if (fileId) {
endPoint += `&fileId=${fileId}`;
}
const strings = await makeRequest({ method: 'get', endPoint, headers });
if (strings.data) {
return strings.data;
@@ -66,9 +69,27 @@ const updateFileStrings = async ({ projectId, fileId, challengeTitle }) => {
}
};
const updateFileString = async ({ projectId, string, challengeTitle }) => {
const {
data: { id: stringId, text, isHidden, context }
} = string;
const hideString = shouldHide(text, context, challengeTitle);
if (!isHidden && hideString) {
await changeHiddenStatus(projectId, stringId, true);
console.log(
`${challengeTitle} - stringId: ${stringId} - changed isHidden to true`
);
} else if (isHidden && !hideString) {
await changeHiddenStatus(projectId, stringId, false);
console.log(
`${challengeTitle} - stringId: ${stringId} - changed isHidden to false`
);
}
};
module.exports = {
getStrings,
changeHiddenStatus,
updateString,
updateFileStrings
updateFileStrings,
updateFileString
};