feat: Crowdin integration scripts/actions (#40657)

This commit is contained in:
Randell Dawson
2021-01-12 11:20:54 -07:00
committed by GitHub
parent ab222e31e7
commit 0095583028
16 changed files with 670 additions and 69 deletions

View File

@@ -0,0 +1,34 @@
require('dotenv').config();
const fetch = require('node-fetch');
const makeRequest = async ({
method,
endPoint,
contentType = 'application/json',
accept = 'application/json',
headers,
body
}) => {
headers = { ...headers, 'Content-Type': contentType, Accept: accept };
const apiUrl = process.env.CROWDIN_API_URL + endPoint;
if (contentType === 'application/x-www-form-urlencoded') {
body = Object.entries(body)
.reduce((formDataArr, [key, value]) => {
return formDataArr.concat(`${key}=${value}`);
}, [])
.join('&');
} else if (contentType === 'application/json') {
body = JSON.stringify(body);
}
const response = await fetch(apiUrl, { headers, method, body });
if (method !== 'delete') {
const data = await response.json();
return data;
} else {
return null;
}
};
module.exports = makeRequest;