feat(tools): hide string action (#42547)
Create an action that allows us to hide a specific string during the crowdin upload process.
This commit is contained in:
committed by
GitHub
parent
7857c3932b
commit
643f34fe3a
@ -61,3 +61,13 @@ jobs:
|
|||||||
CROWDIN_API_URL: 'https://freecodecamp.crowdin.com/api/v2/'
|
CROWDIN_API_URL: 'https://freecodecamp.crowdin.com/api/v2/'
|
||||||
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_CAMPERBOT_SERVICE_TOKEN }}
|
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_CAMPERBOT_SERVICE_TOKEN }}
|
||||||
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID_CURRICULUM }}
|
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID_CURRICULUM }}
|
||||||
|
|
||||||
|
- name: Hide Example Link in Nest an Anchor Element challenge
|
||||||
|
uses: ./tools/crowdin/actions/hide-specific-string
|
||||||
|
with:
|
||||||
|
filename: 'basic-html-and-html5/nest-an-anchor-element-within-a-paragraph.md'
|
||||||
|
string-content: Here's a <a href="https://www.freecodecamp.org" target="_blank" mark="crwd-mark">link to www.freecodecamp.org</a> for you to follow.
|
||||||
|
env:
|
||||||
|
CROWDIN_API_URL: 'https://freecodecamp.crowdin.com/api/v2/'
|
||||||
|
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID_CURRICULUM }}
|
||||||
|
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_CAMPERBOT_SERVICE_TOKEN }}
|
||||||
|
12
tools/crowdin/actions/hide-specific-string/action.yml
Normal file
12
tools/crowdin/actions/hide-specific-string/action.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
name: 'Hide Specific String'
|
||||||
|
description: "Updates a specific string to be hidden"
|
||||||
|
runs:
|
||||||
|
using: 'node12'
|
||||||
|
main: './index.js'
|
||||||
|
inputs:
|
||||||
|
filename:
|
||||||
|
description: 'name of file with specific string to hide'
|
||||||
|
required: true
|
||||||
|
string-content:
|
||||||
|
description: 'text content of string to hide'
|
||||||
|
required: true
|
34
tools/crowdin/actions/hide-specific-string/index.js
Normal file
34
tools/crowdin/actions/hide-specific-string/index.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
require('dotenv').config({ path: `${__dirname}/../../.env` });
|
||||||
|
const { getFiles } = require('../../utils/files');
|
||||||
|
const { getStrings, changeHiddenStatus } = require('../../utils/strings');
|
||||||
|
// eslint-disable-next-line import/no-unresolved
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
const filename = core.getInput('filename');
|
||||||
|
const stringContent = core.getInput('string-content');
|
||||||
|
|
||||||
|
const hideString = async (projectId, fileName, string) => {
|
||||||
|
const fileResponse = await getFiles(projectId);
|
||||||
|
const targetFile = fileResponse.find(el => el.path.endsWith(filename));
|
||||||
|
if (!targetFile) {
|
||||||
|
core.setFailed(`${fileName} was not found.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const stringResponse = await getStrings({
|
||||||
|
projectId,
|
||||||
|
fileId: targetFile.fileId
|
||||||
|
});
|
||||||
|
|
||||||
|
const targetString = stringResponse.find(el => el.data.text === string);
|
||||||
|
if (!targetString) {
|
||||||
|
core.setFailed(`${string} was not found.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await changeHiddenStatus(projectId, targetString.data.id, true);
|
||||||
|
console.log('string hidden!');
|
||||||
|
};
|
||||||
|
|
||||||
|
const projectId = process.env.CROWDIN_PROJECT_ID;
|
||||||
|
hideString(projectId, filename, stringContent);
|
@ -233,5 +233,6 @@ module.exports = {
|
|||||||
addTranslation,
|
addTranslation,
|
||||||
deleteTranslation,
|
deleteTranslation,
|
||||||
getLanguageTranslations,
|
getLanguageTranslations,
|
||||||
deleteLanguageTranslations
|
deleteLanguageTranslations,
|
||||||
|
changeHiddenStatus
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user