From 643f34fe3a3ca86c649b740bde92e738864e90d0 Mon Sep 17 00:00:00 2001 From: "Nicholas Carrigan (he/him)" Date: Thu, 17 Jun 2021 11:24:56 -0700 Subject: [PATCH] feat(tools): hide string action (#42547) Create an action that allows us to hide a specific string during the crowdin upload process. --- .../crowdin-i18n-curriculum-upload.yml | 10 ++++++ .../actions/hide-specific-string/action.yml | 12 +++++++ .../actions/hide-specific-string/index.js | 34 +++++++++++++++++++ tools/crowdin/utils/strings.js | 3 +- 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tools/crowdin/actions/hide-specific-string/action.yml create mode 100644 tools/crowdin/actions/hide-specific-string/index.js diff --git a/.github/workflows/crowdin-i18n-curriculum-upload.yml b/.github/workflows/crowdin-i18n-curriculum-upload.yml index 5c4a38c1ec..f6aeb0cf72 100644 --- a/.github/workflows/crowdin-i18n-curriculum-upload.yml +++ b/.github/workflows/crowdin-i18n-curriculum-upload.yml @@ -61,3 +61,13 @@ jobs: CROWDIN_API_URL: 'https://freecodecamp.crowdin.com/api/v2/' CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_CAMPERBOT_SERVICE_TOKEN }} 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 link to www.freecodecamp.org 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 }} diff --git a/tools/crowdin/actions/hide-specific-string/action.yml b/tools/crowdin/actions/hide-specific-string/action.yml new file mode 100644 index 0000000000..fab7733439 --- /dev/null +++ b/tools/crowdin/actions/hide-specific-string/action.yml @@ -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 diff --git a/tools/crowdin/actions/hide-specific-string/index.js b/tools/crowdin/actions/hide-specific-string/index.js new file mode 100644 index 0000000000..1eccdfd103 --- /dev/null +++ b/tools/crowdin/actions/hide-specific-string/index.js @@ -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); diff --git a/tools/crowdin/utils/strings.js b/tools/crowdin/utils/strings.js index 090efa0c63..aa0ed067ef 100644 --- a/tools/crowdin/utils/strings.js +++ b/tools/crowdin/utils/strings.js @@ -233,5 +233,6 @@ module.exports = { addTranslation, deleteTranslation, getLanguageTranslations, - deleteLanguageTranslations + deleteLanguageTranslations, + changeHiddenStatus };