Estoy trabajando en un bot de Slack que obtiene solicitudes de combinación para una lista dada de repositorios (tan múltiples).
const fetchRepositories = (repositories) => { return repositories.reduce(async (accumulator, currentRepository) => { const eligibleMRs = await fetchEligibleMergeRequests(currentRepository.api); // the PROBLEM is here const refinedMRs = eligibleMRs.length && eligibleMRs.map(mr => { // some logic to clean the shorten info received } return Promise.resolve(accumulator) .then(...) //return personalized object for each repository }, []); }; El problema es que eligibleMRs es una matriz de Promise { <pending> } (cada solicitud de combinación).
Y este problema apareció cuando, en lugar de solo obtener todas las solicitudes de combinación del repositorio, agregué otro .then que obtiene la lista de revisores para cada mr.
const fetchEligibleMergeRequests = (url) => { return fetch(url, fetchOptions) .then(response => { return response.json(); }) .then(data => { return data.filter(mr => filterMergeRequest(mr)); // when I only had this .then everything was perfect }) .then(async filteredMRs => { return filteredMRs.map(async mr => { const fetchedReviewers = await fetchReviewers(mr["project_id"], mr.iid); //this fetch is another call to GitlabAPI in order to retrieve reviewers return Object.assign({}, mr, { reviewers: fetchedReviewers }); }); }) };Para lo que me gustaría pedir ayuda es el hecho de que la búsqueda recién agregada (la que obtiene los revisores para cada señor) parece retrasar todo. Y me gustaría hacer que el código principal ESPERE para que los revisores lo busquen.
Gracias a todos los que intentan ayudar.